private void UpdateWordAdornments()
        {
            var point = _requestedPoint;

            // Find all words in the buffer like the one the caret is on
            TextExtent extent = _textStructureNavigator.GetExtentOfWord(point);

            // If we've selected something not worth highlighting, we might have missed a "word" by a little bit
            if (!IsExtentValid(extent, point))
            {
                //Before we retry, make sure it is worthwhile
                if (extent.Span.Start != point || point == point.GetContainingLine().Start || char.IsWhiteSpace((point - 1).GetChar()))
                {
                    // If we couldn't find a word, clear out the existing markers
                    SynchronousUpdate(point, new NormalizedSnapshotSpanCollection(), null);
                    return;
                }
                else
                {
                    // Try again, one character previous. If the caret is at the end of a word, pick up the word.
                    extent = _textStructureNavigator.GetExtentOfWord(point - 1);

                    // If the word still isn't valid, we're done
                    if (!IsExtentValid(extent, point))
                    {
                        // If we couldn't find a word, clear out the existing markers
                        SynchronousUpdate(point, new NormalizedSnapshotSpanCollection(), null);
                        return;
                    }
                }
            }

            FindAndUpdateSpans(extent, point);
        }
Exemplo n.º 2
0
        private static CompletionContext GetCompletionContext(PaketDocument paketDocument, ITextStructureNavigator navigator, SnapshotPoint position)
        {
            var startPos = position.Position;
            var length   = 0;

            if (position.Position > 0)
            {
                TextExtent endPosition   = navigator.GetExtentOfWord(position);
                TextExtent startPosition = endPosition;

                // try to extend the span over .
                while (!String.IsNullOrWhiteSpace(paketDocument.GetCharAt(startPosition.Span.Start.Position - 1)))
                {
                    startPosition = navigator.GetExtentOfWord(startPosition.Span.Start - 2);
                }


                startPos = startPosition.Span.Start.Position;
                length   = endPosition.Span.End.Position - startPos;
            }

            var span         = new Span(startPos, length);
            var snapShotSpan = new SnapshotSpan(position.Snapshot, span);

            var context = new CompletionContext(span);

            context.ContextType = CompletionContextType.InstalledNuGet;
            context.Snapshot    = snapShotSpan.Snapshot;
            return(context);
        }
Exemplo n.º 3
0
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            char typedChar = char.MinValue;

            if (pguidCmdGroup == VSConstants.VSStd2K && nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR)
            {
                typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
                if (typedChar.Equals('(') && (m_session == null || m_session.IsDismissed))
                {
                    //move the point back so it's in the preceding word
                    SnapshotPoint point  = m_textView.Caret.Position.BufferPosition - 1;
                    TextExtent    extent = m_navigator.GetExtentOfWord(point);
                    string        word   = extent.Span.GetText();

                    m_session = m_broker.CreateSignatureHelpSession(m_textView, m_textView.TextSnapshot.CreateTrackingPoint(point.Position, PointTrackingMode.Positive), true);
                    m_session.Properties.AddProperty("word", word);
                    m_session.Start();
                }
                else if (typedChar.Equals(',') && (m_session == null || m_session.IsDismissed))
                {
                    int paramPos;
                    int pos = m_textView.Caret.Position.BufferPosition - 1;
                    while (pos > 0 && m_textView.TextSnapshot[pos] != '(')
                    {
                        pos--;
                    }
                    if (pos > 0)
                    {
                        paramPos = pos;
                        pos--;
                        while (pos > 0 && char.IsWhiteSpace(m_textView.TextSnapshot[pos]))
                        {
                            pos--;
                        }
                        if (pos > 0)
                        {
                            SnapshotPoint point  = new SnapshotPoint(m_textView.TextSnapshot, pos);
                            TextExtent    extent = m_navigator.GetExtentOfWord(point);
                            string        word   = extent.Span.GetText();


                            m_session = m_broker.CreateSignatureHelpSession(m_textView, m_textView.TextSnapshot.CreateTrackingPoint(m_textView.Caret.Position.BufferPosition - 1, PointTrackingMode.Positive), true);
                            m_session.Properties.AddProperty("word", word);
                            m_session.Properties.AddProperty("span", new Span(paramPos, m_textView.Caret.Position.BufferPosition - paramPos));
                            m_session.Start();
                        }
                    }
                }
                else if (typedChar.Equals(')') && m_session != null)
                {
                    m_session.Dismiss();
                    m_session = null;
                }
                else if (m_session != null && m_session.IsDismissed)
                {
                    m_session = null;
                }
            }
            return(m_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
            private TextExtent GetExtentOfWordWorker(SnapshotPoint position, CancellationToken cancellationToken)
            {
                var textLength = position.Snapshot.Length;

                if (textLength == 0)
                {
                    return(_naturalLanguageNavigator.GetExtentOfWord(position));
                }

                // If at the end of the file, go back one character so stuff works
                if (position == textLength && position > 0)
                {
                    position -= 1;
                }

                // If we're at the EOL position, return the line break's extent
                var line = position.Snapshot.GetLineFromPosition(position);

                if (position >= line.End && position < line.EndIncludingLineBreak)
                {
                    return(new TextExtent(new SnapshotSpan(line.End, line.EndIncludingLineBreak - line.End), isSignificant: false));
                }

                var document = GetDocument(position, cancellationToken);

                if (document != null)
                {
                    var root   = document.GetSyntaxRootSynchronously(cancellationToken);
                    var trivia = root.FindTrivia(position, findInsideTrivia: true);

                    if (trivia != default)
                    {
                        if (trivia.Span.Start == position && _provider.ShouldSelectEntireTriviaFromStart(trivia))
                        {
                            // We want to select the entire comment
                            return(new TextExtent(trivia.Span.ToSnapshotSpan(position.Snapshot), isSignificant: true));
                        }
                    }

                    var token = root.FindToken(position, findInsideTrivia: true);

                    // If end of file, go back a token
                    if (token.Span.Length == 0 && token.Span.Start == textLength)
                    {
                        token = token.GetPreviousToken();
                    }

                    if (token.Span.Length > 0 && token.Span.Contains(position) && !_provider.IsWithinNaturalLanguage(token, position))
                    {
                        // Cursor position is in our domain - handle it.
                        return(_provider.GetExtentOfWordFromToken(token, position));
                    }
                }

                // Fall back to natural language navigator do its thing.
                return(_naturalLanguageNavigator.GetExtentOfWord(position));
            }
        internal static SnapshotSpan?GetNextWord(this ITextStructureNavigator navigator, SnapshotPoint position)
        {
            var word = navigator.GetExtentOfWord(position);

            while (!word.IsSignificant && !word.Span.IsEmpty)
            {
                word = navigator.GetExtentOfWord(word.Span.End);
            }

            return(word.IsSignificant ? new SnapshotSpan?(word.Span) : null);
        }
Exemplo n.º 6
0
        private static CompletionContext GetCompletionContext(PaketDocument paketDocument, ITextStructureNavigator navigator, SnapshotPoint position)
        {
            TextExtent endPosition   = navigator.GetExtentOfWord(position - 1);
            TextExtent startPosition = endPosition;

            // try to extend the span over .
            while (!String.IsNullOrWhiteSpace(paketDocument.GetCharAt(startPosition.Span.Start.Position - 1)))
            {
                startPosition = navigator.GetExtentOfWord(startPosition.Span.Start - 2);
            }

            var startPos     = startPosition.Span.Start.Position;
            var length       = endPosition.Span.End.Position - startPos;
            var span         = new Span(startPos, length);
            var snapShotSpan = new SnapshotSpan(position.Snapshot, span);

            var context = new CompletionContext(span);

            var pos = startPosition.Span.Start;

            if (startPosition.Span.Start.Position > 0)
            {
                pos = startPosition.Span.Start - 1;
            }

            TextExtent previous = navigator.GetExtentOfWord(pos);

            // try to extend the span over blanks
            while (paketDocument.GetCharAt(previous.Span.Start.Position) == " ")
            {
                var pos2 = previous.Span.Start;
                if (previous.Span.Start.Position > 0)
                {
                    pos2 = previous.Span.Start - 1;
                }

                previous = navigator.GetExtentOfWord(pos2);
            }
            var lastWord = previous.Span.GetText();

            switch (lastWord)
            {
            case "nuget": context.ContextType = CompletionContextType.NuGet; break;

            case "source": context.ContextType = CompletionContextType.Source; break;

            case "strategy": context.ContextType = CompletionContextType.Strategy; break;

            default: context.ContextType = CompletionContextType.Keyword; break;
            }

            context.Snapshot = snapShotSpan.Snapshot;
            return(context);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Determine if this IAsyncCompletionSource wants to participate in the current auto-completion session.
        /// </summary>
        /// <param name="trigger">The action that triggered the auto-completion session.</param>
        /// <param name="triggerLocation">The location in the text where auto-completion was triggered.</param>
        /// <param name="cancellationToken">A cancellation token.</param>
        /// <returns>CompletionStartData.DoesNotParticipateInCompletion, if the current instance does not want to provide items for auto-completion; otherwise, an instance of CompletionStartData.</returns>
        public CompletionStartData InitializeCompletion(CompletionTrigger trigger, SnapshotPoint triggerLocation, CancellationToken cancellationToken)
        {
            // Get the syntactical parts of the current line, and check if the trigger location is after the XML doc delimiter '///'
            IList <ClassificationSpan> spans            = _classifier.GetClassificationSpans(triggerLocation.GetContainingLine().Extent);
            ClassificationSpan         commentDelimiter = spans.FirstOrDefault(s => s.ClassificationType.IsOfType(ClassificationTypeNames.XmlDocCommentDelimiter));

            if (commentDelimiter == null || commentDelimiter.Span.End > triggerLocation || cancellationToken.IsCancellationRequested)
            {
                // No XML comment in that line, or trigger location is before the '///' comment start.
                return(CompletionStartData.DoesNotParticipateInCompletion);
            }

            // See if trigger location is within a text span
            int triggerSpanIndex = -1;

            for (int i = 0; i < spans.Count; i++)
            {
                if (spans[i].Span.Contains(triggerLocation))
                {
                    triggerSpanIndex = i;
                    break;
                }
                else if (cancellationToken.IsCancellationRequested)
                {
                    return(CompletionStartData.DoesNotParticipateInCompletion);
                }
            }

            if (triggerSpanIndex == -1)             // Not within a word (EOL etc.)
            {
                if (trigger.Character == '<' || (trigger.Character == '\0' && (trigger.Reason == CompletionTriggerReason.Invoke || trigger.Reason == CompletionTriggerReason.InvokeAndCommitIfUnique)))
                {
                    SnapshotSpan applicableToSpan = _navigator.GetExtentOfWord(triggerLocation).Span;
                    return(new CompletionStartData(CompletionParticipation.ProvidesItems, applicableToSpan));
                }
                else
                {
                    return(CompletionStartData.DoesNotParticipateInCompletion);
                }
            }
            else             // Within a word
            {
                ClassificationSpan triggerSpan = spans[triggerSpanIndex];
                if (triggerSpan.ClassificationType.IsOfType(ClassificationTypeNames.XmlDocCommentText))                 // Just text, so an xml element could be inserted here
                {
                    if (trigger.Character == '<')
                    {
                        SnapshotSpan applicableToSpan = _navigator.GetExtentOfWord(triggerLocation).Span;
                        return(new CompletionStartData(CompletionParticipation.ProvidesItems, applicableToSpan));
                    }
                }
            }
            return(CompletionStartData.DoesNotParticipateInCompletion);
        }
        internal static SnapshotSpan?GetNextWord(this ITextStructureNavigator navigator, SnapshotPoint position)
        {
            TextExtent extentOfWord = navigator.GetExtentOfWord(position);

            while (!extentOfWord.IsSignificant && !extentOfWord.Span.IsEmpty)
            {
                extentOfWord = navigator.GetExtentOfWord(extentOfWord.Span.End);
            }
            if (!extentOfWord.IsSignificant)
            {
                return(new SnapshotSpan?());
            }
            return(extentOfWord.Span);
        }
Exemplo n.º 9
0
        private bool IsXmlAttributeValue(SnapshotPoint triggerLocation)
        {
            TextExtent extent = _navigator.GetExtentOfWord(triggerLocation - 1);
            IList <ClassificationSpan> spans = _classifier.GetClassificationSpans(extent.Span);

            return(spans.Any(s => s.ClassificationType.IsOfType("XML Attribute Value")));
        }
Exemplo n.º 10
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            // Map the trigger point down to our buffer
            ITextSnapshot snapshot            = _subjectBuffer.CurrentSnapshot;
            SnapshotPoint?subjectTriggerPoint = session.GetTriggerPoint(snapshot);

            if (!subjectTriggerPoint.HasValue)
            {
                applicableToSpan = null;
                return;
            }

            ITextStructureNavigator navigator = _navigatorService.GetTextStructureNavigator(_subjectBuffer);
            TextExtent extent     = navigator.GetExtentOfWord(subjectTriggerPoint.Value);
            string     extentText = extent.Span.GetText();

            // What we are effectively doing here is placing this QuickInfo source at the end so that it
            // can hijack the other previous QuickInfo sources. We replace them with colourised versions.

            applicableToSpan = null;
            if (quickInfoContent.Count > 0)
            {
                ITextBuffer cppQuickInfoContentBuffer = quickInfoContent[0] as ITextBuffer;
                string      cppQuickInfoText          = cppQuickInfoContentBuffer.CurrentSnapshot.GetText();
                TextBlock   newContent = CreateColourisedContent(cppQuickInfoText);

                quickInfoContent.RemoveAt(0);
                quickInfoContent.Add(newContent);

                applicableToSpan = snapshot.CreateTrackingSpan(extent.Span.Start, extent.Span.Length, SpanTrackingMode.EdgeInclusive);
            }
        }
Exemplo n.º 11
0
        public bool TryGetUE4Macro(SnapshotPoint triggerPoint, out UE4MacroStatement ue4MacroStatement)
        {
            ue4MacroStatement = null;

            var currentPoint = triggerPoint - 1;
            var extent       = _navigator.GetExtentOfWord(currentPoint);

            var statement     = _navigator.GetSpanOfEnclosing(extent.Span);
            var statementText = statement.GetText();

            var match = Regex.Match(statementText, $@"({UE4Statics.MacroNamesRegExPatern})\((.*)\)",
                                    RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(100));

            if (!match.Success)
            {
                return(false);
            }
            if (!match.Groups[1].Success || !match.Groups[2].Success)
            {
                return(false);
            }

            var contentPosition = statement.Start + match.Groups[2].Index;
            var contentEnd      = contentPosition + match.Groups[2].Length;

            var specifiersSpan = new SnapshotSpan(contentPosition, contentEnd);


            var macro = (UE4Macros)Enum.Parse(typeof(UE4Macros), match.Groups[1].Value.ToUpper());

            ue4MacroStatement = new UE4MacroStatement(specifiersSpan, macro);
            return(true);
        }
        /// <summary>
        /// Returns a caret location of itself or the location after the token the caret is inside of.
        /// </summary>
        private static int GetCaretLocationAfterToken(ITextStructureNavigator navigator, BlockCommentSelectionHelper blockCommentSelection)
        {
            var snapshotSpan = blockCommentSelection.SnapshotSpan;

            if (navigator == null)
            {
                return(snapshotSpan.Start);
            }

            var extent             = navigator.GetExtentOfWord(snapshotSpan.Start);
            int locationAfterToken = extent.Span.End;

            // Don't move to the end if it's already before the token.
            if (snapshotSpan.Start == extent.Span.Start)
            {
                locationAfterToken = extent.Span.Start;
            }
            // If the 'word' is just whitespace, use the selected location.
            if (blockCommentSelection.IsSpanWhitespace(TextSpan.FromBounds(extent.Span.Start, extent.Span.End)))
            {
                locationAfterToken = snapshotSpan.Start;
            }

            return(locationAfterToken);
        }
        private ITrackingSpan FindTokenSpanAtPosition(ICompletionSession session)
        {
            SnapshotPoint currentPoint = session.TextView.Caret.Position.BufferPosition - 1;
            TextExtent    extent       = _textStructureNavigator.GetExtentOfWord(currentPoint);

            var prev = _textStructureNavigator.GetSpanOfPreviousSibling(extent.Span);

            if (prev != null && !prev.Contains(extent.Span))
            {
                string text = prev.GetText();
                if (!string.IsNullOrEmpty(text) && text.Last() != '%' && !char.IsLetter(text[0]))
                {
                    return(null);
                }

                if (text.First() != '%' && CmdLanguage.Keywords.ContainsKey(text.ToLowerInvariant()))
                {
                    text = text.ToLowerInvariant();
                    if (text != "if" && text != "not")
                    {
                        return(null);
                    }
                }
            }

            return(currentPoint.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive));
        }
Exemplo n.º 14
0
        public SnapshotPoint?ConvertPointToBufferIndex(Point position)
        {
            try
            {
                var line = _view.TextViewLines.GetTextViewLineContainingYCoordinate(position.Y);
                if (line == null)
                {
                    return(default(SnapshotPoint?));
                }

                SnapshotPoint?bufferPosition = line.GetBufferPositionFromXCoordinate(position.X);

                if (!bufferPosition.HasValue)
                {
                    // Assume beginning of line.
                    return(new SnapshotPoint(line.Snapshot, line.Start));
                }

                var extent = _navigator.GetExtentOfWord(bufferPosition.Value);
                if (!extent.IsSignificant)
                {
                    return(default(SnapshotPoint?));
                }
                return(bufferPosition);
            }
            catch (Exception) { }
            return(default(SnapshotPoint?));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Gets the quick information item asynchronous.
        /// </summary>
        /// <owner>Anton Patron</owner>
        /// <param name="session">The session.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The <see cref="QuickInfoItem"/></returns>
        public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken)
        {
            SnapshotPoint?subjectTriggerPoint = session.GetTriggerPoint(this.m_subjectBuffer.CurrentSnapshot);

            if (!subjectTriggerPoint.HasValue)
            {
                return(null);
            }

            ITextSnapshot           currentSnapshot = subjectTriggerPoint.Value.Snapshot;
            ITextStructureNavigator navigator       = this.m_provider.NavigatorService.GetTextStructureNavigator(this.m_subjectBuffer);
            TextExtent extent     = navigator.GetExtentOfWord(subjectTriggerPoint.Value);
            string     searchText = extent.Span.GetText();
            var        elements   = await this.m_provider.TranslatorService.GetTooltipElementsAsync(searchText).ConfigureAwait(false);

            if (!elements.Any())
            {
                return(null);
            }

            var applicableToSpan = currentSnapshot.CreateTrackingSpan(extent.Span.Start, searchText.Length, SpanTrackingMode.EdgeInclusive);
            var element          = QuickInfoSource.ComposeContainerElement(elements);

            return(new QuickInfoItem(applicableToSpan, element));
        }
Exemplo n.º 16
0
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            char typedChar = char.MinValue;

            if (pguidCmdGroup == VSConstants.VSStd2K && nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR)
            {
                typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
                if (typedChar.Equals('('))
                {
                    //move the point back so it's in the preceding word
                    SnapshotPoint point  = m_textView.Caret.Position.BufferPosition - 1;
                    TextExtent    extent = m_navigator.GetExtentOfWord(point);
                    string        word   = extent.Span.GetText();
                    /******************************************************************/
                    //if (word.Equals("add"))
                    if (!String.IsNullOrEmpty(word))
                    {
                        m_session = m_broker.TriggerSignatureHelp(m_textView);
                    }
                }
                else if (typedChar.Equals(')') && m_session != null)
                {
                    m_session.Dismiss();
                    m_session = null;
                }
            }
            return(m_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
Exemplo n.º 17
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out Microsoft.VisualStudio.Text.ITrackingSpan applicableToSpan)
        {
            SnapshotPoint?sp = session.GetTriggerPoint(this.textBuffer.CurrentSnapshot);

            if (!sp.HasValue)
            {
                applicableToSpan = null;
                return;
            }

            ITextSnapshot currentSnapshot = sp.Value.Snapshot;
            SnapshotSpan  span            = new SnapshotSpan(sp.Value, 0);

            ITextStructureNavigator navigator = provider.NavigatorService.GetTextStructureNavigator(this.textBuffer);
            string keyText = navigator.GetExtentOfWord(sp.Value).Span.GetText().Trim();

            if (string.IsNullOrEmpty(keyText))
            {
                applicableToSpan = null;
                return;
            }

            string info;

            quickInfos.TryGetValue(keyText, out info);
            if (!string.IsNullOrEmpty(info))
            {
                applicableToSpan = currentSnapshot.CreateTrackingSpan(span.Start.Position, 9, SpanTrackingMode.EdgeInclusive);
                quickInfoContent.Add(info);
                return;
            }

            applicableToSpan = null;
        }
Exemplo n.º 18
0
        protected override bool Execute(VSConstants.VSStd97CmdID commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            SnapshotPoint?point = TextView.Caret.Position.Point.GetPoint(TextView.TextBuffer, PositionAffinity.Predecessor);

            if (point.HasValue)
            {
                TextExtent wordExtent = _navigator.GetExtentOfWord(point.Value - 1);
                string     wordText   = TextView.TextSnapshot.GetText(wordExtent.Span);

                Find2  find      = (Find2)EditorExtensionsPackage.DTE.Find;
                string types     = find.FilesOfType;
                bool   matchCase = find.MatchCase;
                bool   matchWord = find.MatchWholeWord;

                find.WaitForFindToComplete = false;
                find.Action            = EnvDTE.vsFindAction.vsFindActionFindAll;
                find.Backwards         = false;
                find.MatchInHiddenText = true;
                find.MatchWholeWord    = true;
                find.MatchCase         = true;
                find.PatternSyntax     = EnvDTE.vsFindPatternSyntax.vsFindPatternSyntaxLiteral;
                find.ResultsLocation   = EnvDTE.vsFindResultsLocation.vsFindResults1;
                find.SearchSubfolders  = true;
                find.FilesOfType       = "*.js";
                find.Target            = EnvDTE.vsFindTarget.vsFindTargetSolution;
                find.FindWhat          = wordText;
                find.Execute();

                find.FilesOfType    = types;
                find.MatchCase      = matchCase;
                find.MatchWholeWord = matchWord;
            }

            return(true);
        }
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> qiContent, out ITrackingSpan applicableToSpan)
        {
            // Map the trigger point down to our buffer.
            SnapshotPoint?subjectTriggerPoint = session.GetTriggerPoint(m_subjectBuffer.CurrentSnapshot);

            if (!subjectTriggerPoint.HasValue)
            {
                applicableToSpan = null;
                return;
            }

            var fileSpecificTooltips = fileSpecificTooltipProvider.GetFileSpecificTooltipDefinitions(GetFileFullPath());

            ITextSnapshot currentSnapshot = subjectTriggerPoint.Value.Snapshot;
            SnapshotSpan  querySpan       = new SnapshotSpan(subjectTriggerPoint.Value, 0);

            //look for occurrences of our QuickInfo words in the span
            ITextStructureNavigator navigator = m_provider.NavigatorService.GetTextStructureNavigator(m_subjectBuffer);
            TextExtent extent     = navigator.GetExtentOfWord(subjectTriggerPoint.Value);
            string     searchText = extent.Span.GetText();

            foreach (TooltipDefinition tooltipDefinition in fileSpecificTooltips)
            {
                int foundIndex = searchText.IndexOf(tooltipDefinition.Input, StringComparison.CurrentCultureIgnoreCase);
                if (foundIndex > -1)
                {
                    var start = extent.Span.Start + foundIndex;
                    applicableToSpan = currentSnapshot.CreateTrackingSpan(start, tooltipDefinition.Input.Length, SpanTrackingMode.EdgeInclusive);
                    qiContent.Add(tooltipDefinition.Description);
                    return;
                }
            }

            applicableToSpan = null;
        }
Exemplo n.º 20
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            SnapshotPoint?subjectTriggerPoint = session.GetTriggerPoint(_subjectBuffer.CurrentSnapshot);

            if (!subjectTriggerPoint.HasValue)
            {
                applicableToSpan = null;
                return;
            }

            //ITextSnapshot currentSnapshot = subjectTriggerPoint.Value.Snapshot;
            //SnapshotSpan querySpan = new SnapshotSpan(subjectTriggerPoint.Value, 0);

            ITextStructureNavigator navigator = _provider.NavigatorService.GetTextStructureNavigator(_subjectBuffer);
            TextExtent extent = navigator.GetExtentOfWord(subjectTriggerPoint.Value);
            //string searchText = extent.Span.GetText();

            string description = _analysisEntry.GetDescription(_subjectBuffer, subjectTriggerPoint.Value);

            if (description != String.Empty && description != null)
            {
                applicableToSpan = subjectTriggerPoint.Value.Snapshot.CreateTrackingSpan(extent.Span.Start, extent.Span.Length, SpanTrackingMode.EdgeInclusive);
                quickInfoContent.Add(description);
                return;
            }

            applicableToSpan = null;
        }
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (pguidCmdGroup == VSConstants.VSStd2K && nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR)
            {
                var typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
                if (typedChar.Equals('('))
                {
                    // Move the point back so it's in the preceding word
                    var point  = _textView.Caret.Position.BufferPosition - 1;
                    var extent = _navigator.GetExtentOfWord(point);
                    var word   = extent.Span.GetText();

                    if (word.Equals("emplace") || word.Equals("emplace_back"))
                    {
                        _session = _broker.TriggerSignatureHelp(_textView);
                    }
                }
                else if (typedChar.Equals(')') && _session != null)
                {
                    _session.Dismiss();
                    _session = null;
                }
            }

            return(_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
Exemplo n.º 22
0
        private void OnLayoutChanged(object sender, TextViewLayoutChangedEventArgs e)
        {
            var caretPosition = _view.Caret.Position;

            SnapshotPoint?point = caretPosition.Point.GetPoint(_buffer, caretPosition.Affinity);

            if (!point.HasValue)
            {
                return;
            }

            /*/ If the new caret position is still within the current word (and on the same snapshot), we don't need to check it
             * if (CurrentWord.HasValue
             *  && CurrentWord.Value.Snapshot == m_view.TextSnapshot
             *  && point.Value >= CurrentWord.Value.Start
             *  && point.Value <= CurrentWord.Value.End)
             * {
             *  return;
             * }*/

            List <SnapshotSpan> wordSpans = new List <SnapshotSpan>();
            //Find all words in the buffer like the one the caret is on
            TextExtent word = _textStructureNavigator.GetExtentOfWord(point.Value);

            if (_codeModel == null)
            {
                //If we couldn't find a word, clear out the existing markers
                SynchronousUpdate(new NormalizedSnapshotSpanCollection());
                return;
            }

            FindBadActions(wordSpans, word.Span);

            SynchronousUpdate(new NormalizedSnapshotSpanCollection(wordSpans));
        }
Exemplo n.º 23
0
        public async Task <INavigableSymbol> GetNavigableSymbolAsync(SnapshotSpan triggerSpan, CancellationToken cancellationToken)
        {
            Debug.Assert(triggerSpan.Length == 1);

            cancellationToken.ThrowIfCancellationRequested();

            var extent = _textNavigator.GetExtentOfWord(triggerSpan.Start);

            if (!extent.IsSignificant)
            {
                return(null);
            }

            // Check with pylance, which will give us a precise
            // result, including the source location.
            var result = await GetDefinitionLocationsAsync(extent.Span, cancellationToken).ConfigureAwait(false);

            cancellationToken.ThrowIfCancellationRequested();

            if (result != null && result.Any())
            {
                return(result.First());
            }

            return(null);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Determines whether the given match qualifies as a whole word using <see cref="ITextStructureNavigator"/>.
        /// </summary>
        /// <remarks>
        /// In the new implementation, we don't use any external parties to determine word boundaries, rather we pick a small
        /// predictable range of characters and use them as word splitters. The primary reason for this is performance as calls
        /// to external components could be slow. Further, we want the search service to be a dumb but very predictable and simple
        /// text based search service so we enforce our own rules in the new implementation.
        /// </remarks>
        private bool LegacyMatchesAWholeWord(SnapshotSpan result, FindData findData)
        {
            ITextStructureNavigator textStructureNavigator = findData.TextStructureNavigator;

            if (textStructureNavigator == null)
            {
                // the navigator was never set; create one without benefit of context
                textStructureNavigator = _navigatorSelectorService.GetTextStructureNavigator(findData.TextSnapshotToSearch.TextBuffer);
            }

            // We'll need to get the left extent and right extent in case the match spans across multiple words
            Microsoft.VisualStudio.Text.Operations.TextExtent leftExtent  = textStructureNavigator.GetExtentOfWord(result.Start);
            Microsoft.VisualStudio.Text.Operations.TextExtent rightExtent = textStructureNavigator.GetExtentOfWord(result.Length > 0 ? result.End - 1 : result.End);

            return((result.Start == leftExtent.Span.Start) && (result.End == rightExtent.Span.End));
        }
Exemplo n.º 25
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;
            // Map the trigger point down to our buffer.
            SnapshotPoint?subjectTriggerPoint = session.GetTriggerPoint(_subjectBuffer.CurrentSnapshot);

            if (!subjectTriggerPoint.HasValue)
            {
                return;
            }

            ITextSnapshot           currentSnapshot = subjectTriggerPoint.Value.Snapshot;
            ITextStructureNavigator navigator       = _provider.NavigatorService.GetTextStructureNavigator(_subjectBuffer);
            TextExtent extent = navigator.GetExtentOfWord(subjectTriggerPoint.Value);

            string key = extent.Span.GetText();
            //look for occurrences of our QuickInfo words in the span
            SQDeclaration dec = _languageService.Find(key);

            if (dec != null)
            {
                quickInfoContent.Add(dec.GetDescription());
                //quickInfoContent.Add(searchText);

                applicableToSpan = currentSnapshot.CreateTrackingSpan(extent.Span.Start, key.Length, SpanTrackingMode.EdgeInclusive);
            }
        }
Exemplo n.º 26
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            // Map the trigger point down to our buffer.
            SnapshotPoint?subjectTriggerPoint = session.GetTriggerPoint(m_subjectBuffer.CurrentSnapshot);

            if (!subjectTriggerPoint.HasValue)
            {
                applicableToSpan = null;
                return;
            }

            ITextSnapshot currentSnapshot = subjectTriggerPoint.Value.Snapshot;
            SnapshotSpan  querySpan       = new SnapshotSpan(subjectTriggerPoint.Value, 0);

            //look for occurrences of our QuickInfo words in the span
            ITextStructureNavigator navigator = m_provider.NavigatorService.GetTextStructureNavigator(m_subjectBuffer);
            TextExtent extent     = navigator.GetExtentOfWord(subjectTriggerPoint.Value);
            string     searchText = extent.Span.GetText();

            searchText = searchText?.Trim();
            String text = null;

            if (!String.IsNullOrEmpty(searchText))
            {
                text             = TranslateApi.TranslateEn_Zh(searchText);
                applicableToSpan = currentSnapshot.CreateTrackingSpan
                                   (
                    //querySpan.Start.Add(foundIndex).Position, 9, SpanTrackingMode.EdgeInclusive
                    extent.Span.Start, text.Length, SpanTrackingMode.EdgeInclusive
                                   );
                quickInfoContent.Add(text);
                return;
            }


            //foreach (string key in m_dictionary.Keys)
            //{
            //    int foundIndex = searchText.IndexOf(key, StringComparison.CurrentCultureIgnoreCase);
            //    if (foundIndex > -1)
            //    {
            //        applicableToSpan = currentSnapshot.CreateTrackingSpan
            //            (
            //                                    //querySpan.Start.Add(foundIndex).Position, 9, SpanTrackingMode.EdgeInclusive
            //                                    extent.Span.Start + foundIndex, key.Length, SpanTrackingMode.EdgeInclusive
            //            );

            //        string value;
            //        m_dictionary.TryGetValue(key, out value);
            //        if (value != null)
            //            quickInfoContent.Add(value);
            //        else
            //            quickInfoContent.Add("");

            //        return;
            //    }
            //}

            applicableToSpan = null;
        }
Exemplo n.º 27
0
        private ITrackingSpan FindTokenSpanAtPosition(ICompletionSession session)
        {
            SnapshotPoint           currentPoint = (session.TextView.Caret.Position.BufferPosition) - 1;
            ITextStructureNavigator navigator    = _navigator.GetTextStructureNavigator(_buffer);
            TextExtent extent = navigator.GetExtentOfWord(currentPoint);

            return(currentPoint.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive));
        }
        private ITrackingSpan FindTokenSpanAtPosition(ITrackingPoint point, ICompletionSession completionSession)
        {
            SnapshotPoint           ssPoint   = (completionSession.TextView.Caret.Position.BufferPosition) - 1;
            ITextStructureNavigator navigator = sourceProvider.TextNavigatorService.GetTextStructureNavigator(this.textBuffer);
            TextExtent textExtent             = navigator.GetExtentOfWord(ssPoint);

            return(ssPoint.Snapshot.CreateTrackingSpan(textExtent.Span, SpanTrackingMode.EdgeInclusive));
        }
        ITrackingSpan FindTokenSpanAtPosition(ITrackingPoint point, ICompletionSession session)
        {
            SnapshotPoint           currentPoint = (session.TextView.Caret.Position.BufferPosition) - 1;
            ITextStructureNavigator navigator    = m_sourceProvider.NavigatorService.GetTextStructureNavigator(m_textBuffer);
            TextExtent extent = navigator.GetExtentOfWord(currentPoint);

            return(currentPoint.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive));
        }
Exemplo n.º 30
0
        private TextExtent FindExtentAtPoint(SnapshotPoint?subjectTriggerPoint)
        {
            ITextStructureNavigator navigator =
                this.provider.NavigatorService.GetTextStructureNavigator(this.textBuffer);
            TextExtent extent = navigator.GetExtentOfWord(subjectTriggerPoint.Value);

            return(extent);
        }
Exemplo n.º 31
0
		bool IsWholeWord(ITextStructureNavigator textStructureNavigator, ITextSnapshot snapshot, FindResult result) {
			Debug.Assert(textStructureNavigator != null);
			if (textStructureNavigator == null)
				return false;
			if (result.Length == 0)
				return false;
			var start = textStructureNavigator.GetExtentOfWord(new SnapshotPoint(snapshot, result.Position));
			if (start.Span.Start.Position != result.Position)
				return false;
			var end = textStructureNavigator.GetExtentOfWord(new SnapshotPoint(snapshot, result.Position + result.Length - 1));
			return end.Span.End.Position == result.Position + result.Length;
		}