Пример #1
0
        private IEnumerable <ISignature> HandleComma(VsText.ITextSnapshot snapshot, ProbeAppSettings appSettings)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var fileStore = CodeModel.FileStore.GetOrCreateForTextBuffer(_textBuffer);

            if (fileStore != null)
            {
                var fileName = VsTextUtil.TryGetDocumentFileName(_textBuffer);
                var model    = fileStore.GetMostRecentModel(appSettings, fileName, snapshot, "Signature help after ','");
                var modelPos = (new VsText.SnapshotPoint(snapshot, _triggerPos)).TranslateTo(model.Snapshot, VsText.PointTrackingMode.Negative).Position;

                var argsToken = model.File.FindDownward <ArgsToken>().Where(t => t.Span.Start < modelPos && (t.Span.End > modelPos || !t.IsTerminated)).LastOrDefault();
                if (argsToken != null && argsToken.Signature != null)
                {
                    var modelSpan        = new VsText.SnapshotSpan(model.Snapshot, argsToken.Span.ToVsTextSpan());
                    var snapshotSpan     = modelSpan.TranslateTo(snapshot, VsText.SpanTrackingMode.EdgeInclusive);
                    var applicableToSpan = snapshot.CreateTrackingSpan(snapshotSpan.Span, VsText.SpanTrackingMode.EdgeInclusive, 0);
                    yield return(CreateSignature(_textBuffer, argsToken.Signature, applicableToSpan));

                    foreach (var sig in argsToken.SignatureAlternatives)
                    {
                        yield return(CreateSignature(_textBuffer, sig, applicableToSpan));
                    }
                }
            }
        }
Пример #2
0
        private IEnumerable <ISignature> HandleOpenBracket(VsText.ITextSnapshot snapshot, ProbeAppSettings appSettings)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var lineText = snapshot.GetLineTextUpToPosition(_triggerPos);

            var match = _rxFuncBeforeBracket.Match(lineText);

            if (match.Success)
            {
                var line          = snapshot.GetLineFromPosition(_triggerPos);
                var word1         = match.Groups[2].Value;
                var word1Start    = line.Start.Position + match.Groups[2].Index;
                var funcName      = match.Groups[3].Value;
                var funcNameStart = line.Start.Position + match.Groups[3].Index;

                var fileStore = FileStore.GetOrCreateForTextBuffer(_textBuffer);
                if (fileStore != null)
                {
                    if (!string.IsNullOrEmpty(word1))
                    {
                        VsText.ITrackingSpan applicableToSpan = null;

                        var fileName = VsTextUtil.TryGetDocumentFileName(snapshot.TextBuffer);
                        var model    = fileStore.GetMostRecentModel(appSettings, fileName, snapshot, "Signature help after '(' - dot separated words");
                        var modelPos = model.AdjustPosition(word1Start, snapshot);

                        foreach (var word1Def in model.DefinitionProvider.GetAny(modelPos, word1))
                        {
                            if (!word1Def.AllowsChild)
                            {
                                continue;
                            }
                            foreach (var word2Def in word1Def.GetChildDefinitions(funcName))
                            {
                                if (!word2Def.ArgumentsRequired)
                                {
                                    continue;
                                }
                                if (applicableToSpan == null)
                                {
                                    applicableToSpan = snapshot.CreateTrackingSpan(new VsText.Span(_triggerPos, 0), VsText.SpanTrackingMode.EdgeInclusive);
                                }
                                yield return(CreateSignature(_textBuffer, word2Def.ArgumentsSignature, applicableToSpan));
                            }
                        }
                    }
                    else
                    {
                        VsText.ITrackingSpan applicableToSpan = null;

                        var fileName = VsTextUtil.TryGetDocumentFileName(snapshot.TextBuffer);
                        var model    = fileStore.GetMostRecentModel(appSettings, fileName, snapshot, "Signature help after '('");
                        var modelPos = model.AdjustPosition(funcNameStart, snapshot);
                        foreach (var def in model.DefinitionProvider.GetAny(modelPos, funcName))
                        {
                            if (!def.ArgumentsRequired)
                            {
                                continue;
                            }

                            if (applicableToSpan == null)
                            {
                                applicableToSpan = snapshot.CreateTrackingSpan(new VsText.Span(_triggerPos, 0), VsText.SpanTrackingMode.EdgeInclusive);
                            }
                            yield return(CreateSignature(_textBuffer, def.ArgumentsSignature, applicableToSpan));
                        }
                    }
                }
            }
        }