示例#1
0
        /// <summary>
        /// Determine which pieces of Quickinfo content should be displayed
        /// </summary>
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (_disposed)
            {
                throw new ObjectDisposedException("QuickInfoSource");
            }

            var triggerPoint = (SnapshotPoint)session.GetTriggerPoint(_buffer.CurrentSnapshot);

            if (triggerPoint == null)
            {
                return;
            }

            foreach (IMappingTagSpan <NM_TokenTag> curTag in _aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint)))
            {
                if (curTag.Tag.type == NM_TokenTypes.NM_data_registers)
                {
                    var    tagSpan     = curTag.Span.GetSpans(_buffer).First();
                    string key         = tagSpan.GetText().ToLower();
                    var    explanation = Dictionary_QuickInfo.GetDescription(key);
                    if (explanation.Length > 0)
                    {
                        applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);
                        quickInfoContent.Add(explanation);
                    }
                }
            }
        }
        /// <summary>
        /// Determine if the mouse is hovering over a token. If so, highlight the token and display QuickInfo
        /// </summary>
        private void OnTextViewMouseHover(object sender, MouseHoverEventArgs e)
        {
            //AsmDudeToolsStatic.Output("INFO: AsmQuickInfoController:OnTextViewMouseHover: file=" + AsmDudeToolsStatic.GetFileName(this._textView.TextBuffer));
            SnapshotPoint?point = GetMousePosition(new SnapshotPoint(this._textView.TextSnapshot, e.Position));

            if (point != null)
            {
                ITrackingPoint triggerPoint = point.Value.Snapshot.CreateTrackingPoint(point.Value.Position, PointTrackingMode.Positive);
                // Find the broker for this buffer
                if (!this._quickInfoBroker.IsQuickInfoActive(this._textView))
                {
                    //AsmDudeToolsStatic.Output("INFO: AsmQuickInfoController:OnTextViewMouseHover: CreateQuickInfoSession for triggerPoint "+triggerPoint.TextBuffer+"; file=" + AsmDudeToolsStatic.GetFileName(this._textView.TextBuffer));
                    this._session = this._quickInfoBroker.CreateQuickInfoSession(this._textView, triggerPoint, false);
                    this._session.Start();
                }
                else
                {
                    //AsmDudeToolsStatic.Output("INFO: AsmQuickInfoController:OnTextViewMouseHover: quickInfoBroker is already active; file=" + AsmDudeToolsStatic.GetFileName(this._textView.TextBuffer));
                }
            }
            else
            {
                //AsmDudeToolsStatic.Output("INFO: AsmQuickInfoController:OnTextViewMouseHover: point is null; file=" + AsmDudeToolsStatic.GetFileName(this._textView.TextBuffer));
            }
        }
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (!EnsureTreeInitialized() || session == null || qiContent == null)
                return;

            SnapshotPoint? point = session.GetTriggerPoint(_buffer.CurrentSnapshot);
            if (!point.HasValue)
                return;

            ParseItem item = _tree.StyleSheet.ItemBeforePosition(point.Value.Position);
            if (item == null || !item.IsValid)
                return;

            UrlItem urlItem = item.FindType<UrlItem>();

            if (urlItem != null && urlItem.UrlString != null && urlItem.UrlString.IsValid)
            {
                string url = GetFileName(urlItem.UrlString.Text.Trim('\'', '"'));
                if (!string.IsNullOrEmpty(url))
                {
                    applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(point.Value.Position, 1, SpanTrackingMode.EdgeNegative);
                    var image = CreateImage(url);
                    if (image != null && image.Source != null)
                    {
                        qiContent.Add(image);
                        qiContent.Add(Math.Round(image.Source.Width) + "x" + Math.Round(image.Source.Height));
                    }
                }
            }
        }
示例#4
0
        private void HandlePreprocessor(IQuickInfoSession session, SnapshotPoint point, Selector item, IList <object> qiContent)
        {
            if (item == null || !session.TextView.Properties.ContainsProperty("CssSourceMap"))
            {
                return;
            }

            CssSourceMap sourceMap;

            if (!session.TextView.Properties.TryGetProperty <CssSourceMap>("CssSourceMap", out sourceMap))
            {
                return;
            }

            var line   = point.GetContainingLine().LineNumber;
            var column = item.Start - point.Snapshot.GetLineFromPosition(item.Start).Start;

            var node = sourceMap.MapNodes.FirstOrDefault(s =>
                                                         s.SourceFilePath == _buffer.GetFileName() &&
                                                         s.OriginalLine == line &&
                                                         s.OriginalColumn == column);

            if (node == null)
            {
                return;
            }

            qiContent.Add(GenerateContent(node.GeneratedSelector));
        }
		public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> quickInfoContent, out ITrackingSpan applicableToSpan)
		{
			applicableToSpan = null;

			var triggerPoint = session.GetTriggerPoint(buffer.CurrentSnapshot);
			if (triggerPoint == null)
				return;

			ITextDocument doc;
			if (!provider.TextDocumentFactoryService.TryGetTextDocument(buffer, out doc))
				return;

			IOutputWindowPane diagnostics = provider.OutputWindowService.TryGetPane(OutputWindowPanes.DartVSDiagnostics);
			if (diagnostics != null)
				diagnostics.WriteLine("Quick info requested for: " + doc.FilePath);

			// Figure out if this is a recalculate for an existing span (not sure if this is the best way of supporting async...?)
			if (inProgressPosition != null && inProgressPosition.Value == triggerPoint.Value.Position)
			{
				UpdateTooltip(session, quickInfoContent, out applicableToSpan);
			}
			else
			{
				applicableToSpan = GetApplicableToSpan(triggerPoint);
				var ignoredTask = StartTooltipRequestAsync(session, quickInfoContent, applicableToSpan, triggerPoint, doc.FilePath);
			}
		}
示例#6
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 void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            SnapshotPoint? point = session.GetTriggerPoint(session.TextView.TextBuffer.CurrentSnapshot);

            if (!point.HasValue)
                return;

            HtmlEditorTree tree = HtmlEditorDocument.FromTextView(session.TextView).HtmlEditorTree;

            ElementNode node = null;
            AttributeNode attr = null;

            tree.GetPositionElement(point.Value.Position, out node, out attr);

            if (node == null || !node.Name.Equals("img", StringComparison.OrdinalIgnoreCase))
                return;
            if (attr == null || !attr.Name.Equals("src", StringComparison.OrdinalIgnoreCase))
                return;

            string url = ImageQuickInfo.GetFullUrl(attr.Value, session.TextView.TextBuffer);
            if (string.IsNullOrEmpty(url))
                return;

            applicableToSpan = session.TextView.TextBuffer.CurrentSnapshot.CreateTrackingSpan(point.Value.Position, 1, SpanTrackingMode.EdgeNegative);

            ImageQuickInfo.AddImageContent(qiContent, url);
        }
示例#8
0
        /// <summary>
        /// Determine which pieces of Quickinfo content should be displayed
        /// </summary>
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (_disposed)
                throw new ObjectDisposedException("TestQuickInfoSource");

            var triggerPoint = (SnapshotPoint) session.GetTriggerPoint(_buffer.CurrentSnapshot);

            if (triggerPoint == null)
                return;

            foreach (IMappingTagSpan<OokTokenTag> curTag in _aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint)))
            {
                if (curTag.Tag.type == OokTokenTypes.OokExclamation)
                {
                    var tagSpan = curTag.Span.GetSpans(_buffer).First();
                    applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);
                    quickInfoContent.Add("Exclaimed Ook!");
                }
                else if (curTag.Tag.type == OokTokenTypes.OokQuestion)
                {
                    var tagSpan = curTag.Span.GetSpans(_buffer).First();
                    applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);
                    quickInfoContent.Add("Question Ook?");
                }
                else if (curTag.Tag.type == OokTokenTypes.OokPeriod)
                {
                    var tagSpan = curTag.Span.GetSpans(_buffer).First();
                    applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);
                    quickInfoContent.Add("Regular Ook.");
                }
            }
        }
示例#9
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            var triggerPoint = session.GetTriggerPoint(textView.TextSnapshot);

            if (triggerPoint == null)
            {
                return;
            }
            var tagSpan = UriHelper.GetUri(viewTagAggregatorFactoryService, textView, triggerPoint.Value);

            if (tagSpan == null)
            {
                return;
            }
            if (!tagSpan.Tag.Url.IsAbsoluteUri)
            {
                return;
            }

            var spans = tagSpan.Span.GetSpans(textView.TextSnapshot);

            if (spans.Count != 1)
            {
                return;
            }
            var span = spans[0];

            applicableToSpan = span.Snapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeInclusive);
            quickInfoContent.Add(tagSpan.Tag.Url.AbsoluteUri + "\r\n" + dnSpy_Resources.UriFollowLinkMessage);
        }
            public void PresentItem(ITrackingSpan triggerSpan, QuickInfoItem item, bool trackMouse)
            {
                AssertIsForeground();

                _triggerSpan = triggerSpan;
                _item = item;

                // It's a new list of items.  Either create the editor session if this is the first time, or ask the
                // editor session that we already have to recalculate.
                if (_editorSessionOpt == null || _editorSessionOpt.IsDismissed)
                {
                    // We're tracking the caret.  Don't have the editor do it.
                    var triggerPoint = triggerSpan.GetStartTrackingPoint(PointTrackingMode.Negative);

                    _editorSessionOpt = _quickInfoBroker.CreateQuickInfoSession(_textView, triggerPoint, trackMouse: trackMouse);
                    _editorSessionOpt.Dismissed += (s, e) => OnEditorSessionDismissed();
                }

                // So here's the deal.  We cannot create the editor session and give it the right
                // signatures (even though we know what they are).  Instead, the session with
                // call back into the ISignatureHelpSourceProvider (which is us) to get those
                // values. It will pass itself along with the calls back into
                // ISignatureHelpSourceProvider. So, in order to make that connection work, we
                // add properties to the session so that we can call back into ourselves, get
                // the signatures and add it to the session.
                if (!_editorSessionOpt.Properties.ContainsProperty(s_augmentSessionKey))
                {
                    _editorSessionOpt.Properties.AddProperty(s_augmentSessionKey, this);
                }

                _editorSessionOpt.Recalculate();
            }
示例#11
0
            private void OnTextViewMouseHover(object sender, MouseHoverEventArgs e)
            {
                if (!XSharpProjectPackage.Instance.DebuggerIsRunning)
                {
                    try
                    {
                        //find the mouse position by mapping down to the subject buffer
                        SnapshotPoint?point = m_textView.BufferGraph.MapDownToFirstMatch
                                                  (new SnapshotPoint(m_textView.TextSnapshot, e.Position),
                                                  PointTrackingMode.Positive,
                                                  snapshot => m_subjectBuffers.Contains(snapshot.TextBuffer),
                                                  PositionAffinity.Predecessor);

                        if (point.HasValue && point.Value.Position != lastPointPosition)
                        {
                            lastPointPosition = point.Value.Position;
                            if (!m_provider.QuickInfoBroker.IsQuickInfoActive(m_textView))
                            {
                                ITrackingPoint triggerPoint = point.Value.Snapshot.CreateTrackingPoint(point.Value.Position,
                                                                                                       PointTrackingMode.Positive);
                                m_session = m_provider.QuickInfoBroker.TriggerQuickInfo(m_textView, triggerPoint, true);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        XSharpProjectPackage.Instance.DisplayOutPutMessage("XSharpQuickInfo.OnTextViewMouseHover failed");
                        XSharpProjectPackage.Instance.DisplayException(ex);
                    }
                }
            }
示例#12
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            var triggerPoint = (SnapshotPoint)session.GetTriggerPoint(_buffer.CurrentSnapshot);

            if (triggerPoint == null)
            {
                return;
            }

            // find each span that looks like a token and look it up in the dictionary
            foreach (IMappingTagSpan <PkgDefTokenTag> curTag in _aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint)))
            {
                if (curTag.Tag.type == PkgDefLanguageTokens.Token)
                {
                    SnapshotSpan tagSpan = curTag.Span.GetSpans(_buffer).First();
                    if (PkgDefTokenTagger.ValidTokens.Keys.Contains(tagSpan.GetText()))
                    {
                        applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);
                        quickInfoContent.Add(PkgDefTokenTagger.ValidTokens[tagSpan.GetText()]);
                    }
                }
            }
        }
示例#13
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;
        }
示例#14
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            if (quickInfoContent == null)
            {
                throw new ArgumentNullException(nameof(quickInfoContent));
            }

            VSSnapshot snapshot = this.source.CurrentSnapshot as VSSnapshot;

            if (snapshot == null)
            {
                return;
            }

            int triggerPosition = session.GetTriggerPoint(this.textBuffer).GetPosition(snapshot.TextSnapshot);

            SyntaxTree               tree       = this.source.Tree;
            IdentifierSyntax         identifier = tree.GetNodeFromPosition(snapshot, triggerPosition) as IdentifierSyntax;
            IClassificationFormatMap formatMap  = this.provider.FormatMap.GetClassificationFormatMap("text");

            if (identifier?.Definition == null)
            {
                return;
            }

            quickInfoContent.Add(new QuickTipPanel(identifier.Definition.GetIcon(this.provider.GlyphService), identifier.Definition.ToTextBlock(formatMap, this.provider.TypeRegistry), null));
            applicableToSpan = (identifier.Span as VSTrackingSpan).TrackingSpan;
        }
示例#15
0
        /// <summary>
        ///   Determines which pieces of QuickInfo content should be part of the specified <see cref = "T:Microsoft.VisualStudio.Language.Intellisense.IQuickInfoSession" />.
        /// </summary>
        /// <param name = "session">The session for which completions are to be computed.</param>
        /// <param name = "quickInfoContent">The QuickInfo content to be added to the session.</param>
        /// <param name = "applicableToSpan">The <see cref = "T:Microsoft.VisualStudio.Text.ITrackingSpan" /> to which this session applies.</param>
        /// <remarks>
        ///   Each applicable <see cref = "M:Microsoft.VisualStudio.Language.Intellisense.IQuickInfoSource.AugmentQuickInfoSession(Microsoft.VisualStudio.Language.Intellisense.IQuickInfoSession,System.Collections.Generic.IList{System.Object},Microsoft.VisualStudio.Text.ITrackingSpan@)" /> instance will be called in-order to (re)calculate a
        ///   <see cref = "T:Microsoft.VisualStudio.Language.Intellisense.IQuickInfoSession" />. Objects can be added to the session by adding them to the quickInfoContent collection
        ///   passed-in as a parameter.  In addition, by removing items from the collection, a source may filter content provided by
        ///   <see cref = "T:Microsoft.VisualStudio.Language.Intellisense.IQuickInfoSource" />s earlier in the calculation chain.
        /// </remarks>
        public void AugmentQuickInfoSession(IQuickInfoSession session,
                                            IList <object> quickInfoContent,
                                            out ITrackingSpan applicableToSpan)
        {
            if (_Disposed)
            {
                throw new ObjectDisposedException("QuickInfoErrorSource");
            }

            ITextSnapshot currentSnapshot = Buffer.CurrentSnapshot;
            SnapshotPoint?triggerPoint    = session.GetTriggerPoint(currentSnapshot);

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

            var bufferSpan = new SnapshotSpan(currentSnapshot, 0, currentSnapshot.Length);

            foreach (var tagSpan in Aggregator.GetTags(bufferSpan))
            {
                foreach (SnapshotSpan span in tagSpan.Span
                         .GetSpans(Buffer)
                         .Where(span => span.Contains(triggerPoint.Value)))
                {
                    applicableToSpan = currentSnapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeExclusive);
                    quickInfoContent.Add(GetToolTip(tagSpan.Tag));
                    return;
                }
            }
            applicableToSpan = null;
        }
示例#16
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            SnapshotPoint?subjectTriggerPoint = session.GetTriggerPoint(_buffer.CurrentSnapshot);

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

            var snapshotLine = subjectTriggerPoint.Value.GetContainingLine().LineNumber;


            var triggerPoint = subjectTriggerPoint.Value;


            var lines = _buffer.CurrentSnapshot.Lines.Take(snapshotLine + 1).Select(line => line.GetText()).Reverse().GetEnumerator();

            var hocon = _hoconRetriever.GetHoconObject(lines, subjectTriggerPoint.Value.Position);


            if (!String.IsNullOrEmpty(hocon))
            {
                quickInfoContent.Add(hocon);

                applicableToSpan = subjectTriggerPoint.Value.Snapshot.CreateTrackingSpan(triggerPoint.Position, 5,
                                                                                         SpanTrackingMode.EdgeInclusive);
            }
            else
            {
                applicableToSpan = null;
            }
        }
示例#17
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            SnapshotPoint? triggerPoint = session.GetTriggerPoint(TextBuffer.CurrentSnapshot);
            if (!triggerPoint.HasValue)
            {
                applicableToSpan = null;
                return;
            }

            JavaQuickInfo qi = null;
            if (session.Properties.TryGetProperty<JavaQuickInfo>(typeof(JavaQuickInfo), out qi))
            {
                //quickInfoContent.Clear();
                foreach (var o in qi.QuickInfoContent)
                {
                    var display = o;
                    if (display.Contains("{"))
                        display = display.Substring(0, display.IndexOf("{"));
                    if (display.Contains("[in"))
                        display = display.Substring(0, display.IndexOf("[in"));
                    //quickInfoContent.Add(o);
                    quickInfoContent.Add(display); // TODO: Workaround to only show the declaration of the type and not the full location string
                }

                // Get whole word under point
                ITextStructureNavigator navigator = Provider.NavigatorService.GetTextStructureNavigator(TextBuffer);
                TextExtent extent = navigator.GetExtentOfWord(triggerPoint.Value);

                applicableToSpan = triggerPoint.Value.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive);
            }
            else
                applicableToSpan = null;
        }
 void UpdateTooltip(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
 {
     // Provide the tooltip data from the data we stashed in our callback.
     quickInfoContent.Add(inProgressTooltipData);
     // TODO: For some reason, this doesn't seem to work properly; the tooltip flickers as the mouse moves (and fires off additional requests) :(
     applicableToSpan = inProgressApplicableToSpan;
 }
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (!EnsureTreeInitialized() || session == null || qiContent == null)
                return;

            // Map the trigger point down to our buffer.
            SnapshotPoint? point = session.GetTriggerPoint(_buffer.CurrentSnapshot);
            if (!point.HasValue)
                return;

            ParseItem item = _tree.StyleSheet.ItemBeforePosition(point.Value.Position);
            if (item == null || !item.IsValid)
                return;

            RuleSet rule = item.FindType<RuleSet>();
            if (rule == null)
                return;

            applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(item.Start, item.Length, SpanTrackingMode.EdgeNegative);
            var fileName = _buffer.GetFileName().ToLowerInvariant();
            var unmatchedEntry = UsageRegistry.GetAllUnusedRules().FirstOrDefault(x => x.File == fileName && x.Is(rule));

            if(unmatchedEntry == null)
            {
                return;
            }

            qiContent.Add("No usages of this rule have been found");
        }
示例#20
0
        private void OnTextViewMouseHover(object sender, MouseHoverEventArgs e)
        {
            if (this.provider.QuickInfoBroker.IsQuickInfoActive(this.textView))
            {
                return;
            }
            var mousePoint = new SnapshotPoint(this.textView.TextSnapshot, e.Position);

            // If the mouse position maps to the csharp buffer then it should be handled by C# only.
            SnapshotPoint?csharpPoint = this.textView.BufferGraph.MapDownToBuffer(
                mousePoint, PointTrackingMode.Positive, this.csharpBuffer, PositionAffinity.Predecessor);

            if (csharpPoint != null)
            {
                return;
            }

            // Find the mouse position by mapping down to the subject (P#) buffer
            SnapshotPoint?point = this.textView.BufferGraph.MapDownToFirstMatch(
                mousePoint, PointTrackingMode.Positive, snapshot => this.subjectBuffers.Contains(snapshot.TextBuffer), PositionAffinity.Predecessor);

            if (point != null)
            {
                ITrackingPoint triggerPoint = point.Value.Snapshot.CreateTrackingPoint(point.Value.Position, PointTrackingMode.Positive);
                this.session = this.provider.QuickInfoBroker.TriggerQuickInfo(this.textView, triggerPoint, true);
            }
        }
示例#21
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> qiContent, out ITrackingSpan applicableToSpan)
        {
            try
            {
                Debug.WriteLine("AugmentQuickInfoSession Starts");
                var subjectTriggerPoint = session.GetTriggerPoint(m_subjectBuffer.CurrentSnapshot);
                if (!subjectTriggerPoint.HasValue)
                {
                    applicableToSpan = null;
                    return;
                }

                var navigator = m_provider.NavigatorService.GetTextStructureNavigator(m_subjectBuffer);
                var extent    = navigator.GetExtentOfWord(subjectTriggerPoint.Value);
                var symbol    = CodeAnalysis.GetCurrentSymbol(extent.Span);
                if (symbol != null)
                {
                    Current.Symbol = symbol;
                    var lnkBtn = new LinkButton
                    {
                        FormCaption = symbol.OriginalDefinition.ToDisplayString(Microsoft.CodeAnalysis.SymbolDisplayFormat.FullyQualifiedFormat)
                    };
                    qiContent.Insert(0, lnkBtn);
                }
            }
            catch (Exception err)
            {
                Debug.WriteLine(err.ToString() + new StackTrace(err).ToString());
            }
            finally
            {
                applicableToSpan = null;
            }
        }
示例#22
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;
            var document = _subjectBuffer.GetEditorDocument <IREditorDocument>();

            if (document == null)
            {
                return;
            }

            var textBuffer   = document.EditorBuffer.As <ITextBuffer>();
            var triggerPoint = session.GetTriggerPoint(textBuffer.CurrentSnapshot);

            if (!triggerPoint.HasValue)
            {
                return;
            }

            int position = triggerPoint.Value;

            if (_lastPosition != position)
            {
                _lastPosition = position;
                // Document may be null in REPL window as projections are not
                // getting set immediately or may change as user moves mouse over.
                AugmentQuickInfoSession(document.EditorTree.AstRoot, textBuffer, position,
                                        session, quickInfoContent, out applicableToSpan,
                                        RetriggerQuickInfoSession);
            }
        }
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan) {
            applicableToSpan = null;

            var modifier = ModifierKeys.Control | ModifierKeys.Shift;
            if((Keyboard.Modifiers & modifier) != modifier) {
                return;
            }

            var parseResult = ParserService.ParseResult;
            if (parseResult == null) {
                return;
            }
            // Map the trigger point down to our buffer.
            SnapshotPoint? subjectTriggerPoint = session.GetTriggerPoint(parseResult.Snapshot);
            if(!subjectTriggerPoint.HasValue) {
                return;
            }

            var triggerToken = parseResult.SyntaxTree.Tokens.FindAtPosition(subjectTriggerPoint.Value.Position);

            if(triggerToken.IsMissing || triggerToken.Parent == null) {
                return;
            }

            var location = triggerToken.GetLocation();
            qiContent.Add($"{triggerToken.Type} ({triggerToken.Classification}) Ln {location?.StartLine + 1} Ch {location?.StartCharacter + 1}\r\n{triggerToken.Parent?.GetType().Name}");

            applicableToSpan = parseResult.Snapshot.CreateTrackingSpan(
                triggerToken.Start,
                triggerToken.Length,
                SpanTrackingMode.EdgeExclusive);
        }
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }

            if (quickInfoContent == null)
            {
                throw new ArgumentNullException("quickInfoContent");
            }

            TemplateAnalysis analysis     = this.analyzer.CurrentAnalysis;
            SnapshotPoint?   triggerPoint = session.GetTriggerPoint(analysis.TextSnapshot);

            if (triggerPoint != null && analysis.Template != null)
            {
                string description;
                Span   applicableTo;
                if (analysis.Template.TryGetDescription(triggerPoint.Value.Position, out description, out applicableTo))
                {
                    quickInfoContent.Add(description);
                    applicableToSpan = analysis.TextSnapshot.CreateTrackingSpan(applicableTo, SpanTrackingMode.EdgeExclusive);
                    return;
                }
            }

            applicableToSpan = null;
        }
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }

            if (quickInfoContent == null)
            {
                throw new ArgumentNullException("quickInfoContent");
            }

            TemplateAnalysis analysis = this.analyzer.CurrentAnalysis;
            SnapshotPoint? triggerPoint = session.GetTriggerPoint(analysis.TextSnapshot);
            if (triggerPoint != null && analysis.Template != null)
            {
                string description;
                Span applicableTo;
                if (analysis.Template.TryGetDescription(triggerPoint.Value.Position, out description, out applicableTo))
                {
                    quickInfoContent.Add(description);
                    applicableToSpan = analysis.TextSnapshot.CreateTrackingSpan(applicableTo, SpanTrackingMode.EdgeExclusive); 
                    return;                    
                }
            }

            applicableToSpan = null;
        }
示例#26
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);
            }
        }
示例#27
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> qiContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (session == null || qiContent == null)
            {
                return;
            }

            // Map the trigger point down to our buffer.
            SnapshotPoint?point = session.GetTriggerPoint(_buffer.CurrentSnapshot);

            if (!point.HasValue)
            {
                return;
            }

            var snapshot   = _buffer.CurrentSnapshot;
            var classifier = _classifierService.GetClassifier(_buffer);

            var doc    = new SnapshotSpan(snapshot, 0, snapshot.Length);
            var line   = point.Value.GetContainingLine();
            var idents = classifier.GetClassificationSpans(line.Extent);

            bool handled = HandleVariables(qiContent, ref applicableToSpan, idents, point);

            if (handled)
            {
                return;
            }

            HandleKeywords(qiContent, ref applicableToSpan, idents, point);
        }
 public QuickInfoPresenterSession(IQuickInfoBroker quickInfoBroker, ITextView textView, ITextBuffer subjectBuffer, IQuickInfoSession sessionOpt)
 {
     _quickInfoBroker = quickInfoBroker;
     _textView = textView;
     _subjectBuffer = subjectBuffer;
     _editorSessionOpt = sessionOpt;
 }
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (session == null || qiContent == null)
                return;

            // Map the trigger point down to our buffer.
            SnapshotPoint? point = session.GetTriggerPoint(_buffer.CurrentSnapshot);
            if (!point.HasValue)
                return;

            JSONEditorDocument doc = JSONEditorDocument.FromTextBuffer(_buffer);
            JSONParseItem item = doc.JSONDocument.ItemBeforePosition(point.Value.Position);

            if (item == null || !item.IsValid)
                return;

            JSONMember dependency = item.FindType<JSONMember>();
            if (dependency == null || dependency.Name != item)
                return;

            var parent = dependency.Parent.FindType<JSONMember>();
            if (parent == null || !parent.UnquotedNameText.EndsWith("dependencies", StringComparison.OrdinalIgnoreCase))
                return;

            applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(item.Start, item.Length, SpanTrackingMode.EdgeNegative);

            UIElement element = CreateTooltip(dependency.UnquotedNameText, item);

            if (element != null)
                qiContent.Add(element);
        }
        public static object[] RetrieveVsSquiggleContents([CanBeNull] this IQuickInfoSession session)
        {
            var properties = session?.Properties;

            if (properties != null)
            {
                if (properties.TryGetProperty(_squiggleContentsPropertyKey, out object[] squiggleContents))
示例#31
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, System.Collections.Generic.IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            if (_curSession != null && !_curSession.IsDismissed)
            {
                _curSession.Dismiss();
                _curSession = null;
            }

            _curSession            = session;
            _curSession.Dismissed += CurSessionDismissed;
            if (_provider._PublicFunctionProvider != null)
            {
                _provider._PublicFunctionProvider.SetFilename(_textBuffer.GetFilePath());
            }
            if (_provider._DatabaseInfoProvider != null)
            {
                _provider._DatabaseInfoProvider.SetFilename(_textBuffer.GetFilePath());
            }
            var vars = _textBuffer.CurrentSnapshot.AnalyzeExpression(
                session.CreateTrackingSpan(_textBuffer),
                false,
                _provider._PublicFunctionProvider,
                _provider._DatabaseInfoProvider,
                _provider._ProgramFileProvider
                );

            AugmentQuickInfoWorker(_provider, session, _textBuffer, _viewAdapter, vars, quickInfoContent, out applicableToSpan);
        }
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (_disposed)
            {
                throw new ObjectDisposedException("TestQuickInfoSource");
            }

            var triggerPoint = (SnapshotPoint)session.GetTriggerPoint(_buffer.CurrentSnapshot);

            if (triggerPoint == null)
            {
                return;
            }

            foreach (IMappingTagSpan <Merlin32TokenTag> curTag in _aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint)))
            {
                if ((curTag.Tag.Tokentype == Merlin32TokenTypes.Merlin32Opcode) || (curTag.Tag.Tokentype == Merlin32TokenTypes.Merlin32Directive) || (curTag.Tag.Tokentype == Merlin32TokenTypes.Merlin32DataDefine))
                {
                    var tagSpan = curTag.Span.GetSpans(_buffer).First();
                    // Before
                    //if (tagSpan.GetText() == Merlin32Opcodes.ORG.ToString())
                    //{
                    //    applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);
                    //    quickInfoContent.Add("Must be followed by the program's origin, e.g. org $800");
                    //}
                    // OG After
                    applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);
                    if (tagSpan.GetText() == Resources.directives.ELUPValue)
                    {
                        quickInfoContent.Add(_Merlin32OpcodesHelper._Merlin32KeywordsQuickInfo[Merlin32Directives.ELUP.ToString()]);
                    }
                    else
                    {
                        // TODO: why do I get an exception here if I don't test for string.Empty!?

                        /*
                         * System.Collections.Generic.KeyNotFoundException was unhandled by user code
                         * HResult=-2146232969
                         * Message=The given key was not present in the dictionary.
                         * Source=mscorlib
                         * StackTrace:
                         *     at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
                         *     at VSMerlin32.Merlin32QuickInfoSource.AugmentQuickInfoSession(IQuickInfoSession session, IList`1 quickInfoContent, ITrackingSpan& applicableToSpan) in c:\Users\Olivier\Documents\Visual Studio 2013\Projects\Merlin32 Language Service\Merlin32Language\Intellisense\Merlin32QuickInfoSource.cs:line 77
                         *     at Microsoft.VisualStudio.Language.Intellisense.Implementation.QuickInfoSession.Recalculate()
                         *     at Microsoft.VisualStudio.Language.Intellisense.Implementation.QuickInfoSession.Start()
                         *     at Microsoft.VisualStudio.Language.Intellisense.Implementation.DefaultQuickInfoController.OnTextView_MouseHover(Object sender, MouseHoverEventArgs e)
                         *     at Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView.RaiseHoverEvents()
                         * InnerException:
                         */
                        // Compare with changeset 151, you'll see why I ask...
                        if (string.Empty != tagSpan.GetText())
                        {
                            quickInfoContent.Add(_Merlin32OpcodesHelper._Merlin32KeywordsQuickInfo[tagSpan.GetText().ToUpper()]);
                        }
                    }
                }
            }
        }
示例#33
0
        /// <summary>
        /// Activates a new QuickInfo session in response to the MouseHover event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void textView_MouseHover(object sender, MouseHoverEventArgs e)
        {
            if (activeSession != null)
            {
                activeSession.Dismiss();
            }

            SnapshotPoint?point = e.TextPosition.GetPoint(
                textBuffer =>
                (
                    buffer == textBuffer
                    // only text buffers require expilicit session activation
                    // XML and HTML already have quickInfo session activation code
                    // adding our own would cause 'double vision' - our source would be hit
                    // by our session as well as by the standard one
                    && textBuffer.ContentType.TypeName == "plaintext"
                )
                , PositionAffinity.Predecessor);

            if (point.HasValue)
            {
                ITrackingPoint triggerPoint = point.Value.Snapshot.CreateTrackingPoint(point.Value.Position, PointTrackingMode.Positive);

                activeSession = provider.quickInfoBroker.CreateQuickInfoSession(textView, triggerPoint, true);
                activeSession.Start();
            }
        }
示例#34
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (!EnsureTreeInitialized() || session == null || qiContent == null)
                return;

            // Map the trigger point down to our buffer.
            SnapshotPoint? point = session.GetTriggerPoint(_buffer.CurrentSnapshot);
            if (!point.HasValue)
                return;

            ParseItem item = _tree.StyleSheet.ItemBeforePosition(point.Value.Position);
            if (item == null || !item.IsValid)
                return;

            Declaration dec = item.FindType<Declaration>();
            if (dec == null || !dec.IsValid || !_allowed.Contains(dec.PropertyName.Text.ToUpperInvariant()))
                return;

            string fontName = item.Text.Trim('\'', '"');

            if (fonts.Families.SingleOrDefault(f => f.Name.Equals(fontName, StringComparison.OrdinalIgnoreCase)) != null)
            {
                FontFamily font = new FontFamily(fontName);

                applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(item.Start, item.Length, SpanTrackingMode.EdgeNegative);
                qiContent.Add(CreateFontPreview(font, 10));
                qiContent.Add(CreateFontPreview(font, 11));
                qiContent.Add(CreateFontPreview(font, 12));
                qiContent.Add(CreateFontPreview(font, 14));
                qiContent.Add(CreateFontPreview(font, 25));
                qiContent.Add(CreateFontPreview(font, 40));
            }
        }
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            var triggerPoint = (SnapshotPoint)session.GetTriggerPoint(_buffer.CurrentSnapshot);

            if (triggerPoint == null)
                return;

            // find each span that looks like a token and look it up in the dictionary
            foreach (IMappingTagSpan<PkgDefTokenTag> curTag in _aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint)))
            {
                if (curTag.Tag.type == PkgDefLanguageTokens.Token)
                {
                    SnapshotSpan tagSpan = curTag.Span.GetSpans(_buffer).First();
                    if (PkgDefTokenTagger.ValidTokens.Keys.Contains(tagSpan.GetText()))
                    {
                        applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);
                        string quickInfo = PkgDefTokenTagger.ValidTokens[tagSpan.GetText()];
                        System.Diagnostics.Debug.WriteLine(quickInfo);
                        quickInfoContent.Add(quickInfo);
                    }
                }
            }
        }
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan) {
            applicableToSpan = null;

            var semanticModelResult = SemanticModelService.SemanticModelResult;
            if (semanticModelResult == null) {
               return;
            }

            // Map the trigger point down to our buffer.
            SnapshotPoint? subjectTriggerPoint = session.GetTriggerPoint(semanticModelResult.Snapshot);
            if (!subjectTriggerPoint.HasValue) {
                return;
            }
           
            var triggerSymbol = semanticModelResult.CompilationUnit.Symbols.FindAtPosition(subjectTriggerPoint.Value.Position);

            if (triggerSymbol == null) {
                return;
            }

            foreach(var content in SymbolQuickInfoBuilder.Build(triggerSymbol, SyntaxQuickinfoBuilderService)) {                 
                qiContent.Add(content);
            }
            
            var location = triggerSymbol.Location;
            applicableToSpan = semanticModelResult.Snapshot.CreateTrackingSpan(
                    location.Start,
                    location.Length,
                    SpanTrackingMode.EdgeExclusive);
        }
示例#37
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            QuickInfoManager quickInfoManager;

            if (!session.Properties.TryGetProperty(typeof(QuickInfoManager), out quickInfoManager))
            {
                return;
            }

            var model           = quickInfoManager.Model;
            var textSpan        = model.Span;
            var span            = new Span(textSpan.Start, textSpan.Length);
            var currentSnapshot = session.TextView.TextBuffer.CurrentSnapshot;
            var content         = GetContent(model);

            if (content == null)
            {
                return;
            }

            applicableToSpan = currentSnapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeNegative);
            quickInfoContent.Add(content);
        }
示例#38
0
        public void AugmentQuickInfoSession(
            IQuickInfoSession session, IList <object> quickInfoContent,
            out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;
            SnapshotPoint?subjectTriggerPoint =
                session.GetTriggerPoint(textBuffer.CurrentSnapshot);

            if (!subjectTriggerPoint.HasValue)
            {
                return;
            }
            ITextSnapshot currentSnapshot = subjectTriggerPoint.Value.Snapshot;
            SnapshotSpan  querySpan       = new SnapshotSpan(subjectTriggerPoint.Value, 0);

            var        tagAggregator = GetAggregator(session);
            TextExtent extent        = FindExtentAtPoint(subjectTriggerPoint);

            if (CheckForPrefixTag(tagAggregator, extent.Span))
            {
                String prefix = extent.Span.GetText();
                String url    = FindNSUri(extent.Span, GetDocText(extent.Span));
                applicableToSpan = currentSnapshot.CreateTrackingSpan(
                    extent.Span, SpanTrackingMode.EdgeInclusive
                    );
                quickInfoContent.Add(CreateInfoText(prefix, url));
            }
        }
示例#39
0
 private ExpressionAnalysis AnalyzeExpression(IQuickInfoSession session) {
     return VsProjectAnalyzer.AnalyzeExpression(
         _textBuffer.CurrentSnapshot,
         session.CreateTrackingSpan(_textBuffer),
         false
     );
 }
示例#40
0
        public void AugmentQuickInfoSession(
        IQuickInfoSession session, IList<object> quickInfoContent,
        out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;
              SnapshotPoint? subjectTriggerPoint =
            session.GetTriggerPoint(textBuffer.CurrentSnapshot);
              if ( !subjectTriggerPoint.HasValue ) {
            return;
              }
              ITextSnapshot currentSnapshot = subjectTriggerPoint.Value.Snapshot;
              SnapshotSpan querySpan = new SnapshotSpan(subjectTriggerPoint.Value, 0);

              var tagAggregator = GetAggregator(session);
              TextExtent extent = FindExtentAtPoint(subjectTriggerPoint);

              if ( CheckForPrefixTag(tagAggregator, extent.Span) ) {
            string text = extent.Span.GetText();
            string url = FindNSUri(extent.Span, GetDocText(extent.Span));
            applicableToSpan = currentSnapshot.CreateTrackingSpan(
              extent.Span, SpanTrackingMode.EdgeInclusive
            );
            String toolTipText = String.Format("Prefix: {0}\r\nNamespace: {1}", text, url);
            quickInfoContent.Add(toolTipText);
              }
        }
示例#41
0
 public QuickInfoPresenterSession(IQuickInfoBroker quickInfoBroker, ITextView textView, ITextBuffer subjectBuffer, IQuickInfoSession sessionOpt)
 {
     _quickInfoBroker  = quickInfoBroker;
     _textView         = textView;
     _subjectBuffer    = subjectBuffer;
     _editorSessionOpt = sessionOpt;
 }
            public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> quickInfoContent, out ITrackingSpan applicableToSpan)
            {
                applicableToSpan = null;

                object eventHookupValue;
                if (quickInfoContent.Count != 0 ||
                    session.Properties.TryGetProperty(QuickInfoUtilities.EventHookupKey, out eventHookupValue))
                {
                    // No quickinfo if it's the event hookup popup.
                    return;
                }

                var position = session.GetTriggerPoint(_subjectBuffer.CurrentSnapshot);
                if (position.HasValue)
                {
                    var textView = session.TextView;
                    var args = new InvokeQuickInfoCommandArgs(textView, _subjectBuffer);

                    Controller controller;
                    if (_commandHandler.TryGetController(args, out controller))
                    {
                        controller.InvokeQuickInfo(position.Value, trackMouse: true, augmentSession: session);
                    }
                }
            }
示例#43
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            SnapshotPoint?triggerPoint = session.GetTriggerPoint(_subjectBuffer.CurrentSnapshot);

            if (!triggerPoint.HasValue)
            {
                return;
            }

            int position = triggerPoint.Value;

            if (_lastPosition == position)
            {
                return;
            }

            _lastPosition = position;
            ITextSnapshot snapshot = triggerPoint.Value.Snapshot;

            IREditorDocument document = REditorDocument.TryFromTextBuffer(_subjectBuffer);

            if (document != null)
            {
                // Document may be null in REPL window as projections are not
                // getting set immediately or may change as user moves mouse over.
                AugmentQuickInfoSession(document.EditorTree.AstRoot, position,
                                        session, quickInfoContent, out applicableToSpan,
                                        (object o) => RetriggerQuickInfoSession(o as IQuickInfoSession));
            }
        }
示例#44
0
文件: HoverText.cs 项目: ggrov/dafny
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            var triggerPoint = (SnapshotPoint)session.GetTriggerPoint(_buffer.CurrentSnapshot);

            if (triggerPoint == null)
            {
                return;
            }

            foreach (IMappingTagSpan <DafnyTokenTag> curTag in _aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint)))
            {
                var s = curTag.Tag.HoverText;
                if (s != null)
                {
                    var tagSpan = curTag.Span.GetSpans(_buffer).First();
                    applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);
                    quickInfoContent.Add(s);
                }
            }

            if (applicableToSpan == null)
            {
                TacticsHoverText.TestForAndAddHoverText(ref applicableToSpan, triggerPoint, _buffer, quickInfoContent);
            }
        }
示例#45
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <Object> qiContent, out ITrackingSpan applicableToSpan)
        {
            if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.Color) == false)
            {
                goto EXIT;
            }
            var buffer    = session.TextView.TextBuffer;
            var snapshot  = session.TextView.TextSnapshot;
            var navigator = _NavigatorService.GetTextStructureNavigator(buffer);
            var extent    = navigator.GetExtentOfWord(session.GetTriggerPoint(snapshot).GetValueOrDefault()).Span;
            var word      = snapshot.GetText(extent);
            var brush     = ColorQuickInfo.GetBrush(word);

            if (brush == null)
            {
                if ((extent.Length == 6 || extent.Length == 8) && extent.Span.Start > 0 && Char.IsPunctuation(snapshot.GetText(extent.Span.Start - 1, 1)[0]))
                {
                    word = "#" + word;
                }
                brush = ColorQuickInfo.GetBrush(word);
            }
            if (brush != null)
            {
                qiContent.Add(ColorQuickInfo.PreviewColor(brush));
                applicableToSpan = snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeExclusive);
                return;
            }
EXIT:
            applicableToSpan = null;
        }
示例#46
0
		protected QuickInfoPresenterBase(IQuickInfoSession session) {
			if (session == null)
				throw new ArgumentNullException(nameof(session));
			this.session = session;
			control = new QuickInfoPresenterControl { DataContext = this };
			session.Dismissed += Session_Dismissed;
		}
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (_disposed)
            {
                throw new ObjectDisposedException("TestQuickInfoSource");
            }

            var triggerPoint = (SnapshotPoint)session.GetTriggerPoint(_buffer.CurrentSnapshot);

            if (triggerPoint == null)
            {
                return;
            }

            foreach (IMappingTagSpan <IRTokenTag> curTag in _aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint)))
            {
                if (curTag.Tag.type == IRTokenTypes.IRDefine)
                {
                    var tagSpan = curTag.Span.GetSpans(_buffer).First();
                    applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);
                    quickInfoContent.Add("Defining a new function!");
                }
            }
        }
 private void HACK_SetShimQuickInfoSessionWorker(ITextView textView, IQuickInfoSession quickInfoSession)
 {
     var properties = textView.Properties.PropertyList;
     var shimController = properties.Single(p => p.Value != null && p.Value.GetType().Name == "ShimQuickInfoController").Value;
     var sessionField = shimController.GetType().GetField("_session", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
     sessionField.SetValue(shimController, quickInfoSession);
 }
示例#49
0
            public void PresentItem(ITrackingSpan triggerSpan, QuickInfoItem item, bool trackMouse)
            {
                AssertIsForeground();

                _triggerSpan = triggerSpan;
                _item        = item;

                // It's a new list of items.  Either create the editor session if this is the first time, or ask the
                // editor session that we already have to recalculate.
                if (_editorSessionOpt == null || _editorSessionOpt.IsDismissed)
                {
                    // We're tracking the caret.  Don't have the editor do it.
                    var triggerPoint = triggerSpan.GetStartTrackingPoint(PointTrackingMode.Negative);

                    _editorSessionOpt            = _quickInfoBroker.CreateQuickInfoSession(_textView, triggerPoint, trackMouse: trackMouse);
                    _editorSessionOpt.Dismissed += (s, e) => OnEditorSessionDismissed();
                }

                // So here's the deal.  We cannot create the editor session and give it the right
                // signatures (even though we know what they are).  Instead, the sessino with
                // call back into the ISignatureHelpSourceProvider (which is us) to get those
                // values. It will pass itself along with the calls back into
                // ISignatureHelpSourceProvider. So, in order to make that connection work, we
                // add properties to the session so that we can call back into ourselves, get
                // the signatures and add it to the session.
                if (!_editorSessionOpt.Properties.ContainsProperty(s_augmentSessionKey))
                {
                    _editorSessionOpt.Properties.AddProperty(s_augmentSessionKey, this);
                }

                _editorSessionOpt.Recalculate();
            }
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (session == null || qiContent == null || qiContent.Count > 0)
                return;

            // Map the trigger point down to our buffer.
            SnapshotPoint? point = session.GetTriggerPoint(_buffer.CurrentSnapshot);
            if (!point.HasValue)
                return;

            var doc = JSONEditorDocument.FromTextBuffer(_buffer);
            JSONParseItem item = doc.JSONDocument.ItemBeforePosition(point.Value.Position);
            if (item == null || !item.IsValid)
                return;

            JSONMember member = item.FindType<JSONMember>();
            if (member == null || member.Name == null)
                return;

            IJSONSchema schema = _schemaResolver.DetermineSchemaForTextBuffer(_buffer);

            if (schema != null)
            {
                IJSONSchemaPropertyNameCompletionInfo info = GetInfo(schema, member);

                if (info != null && !string.IsNullOrEmpty(info.PropertyDocumentation))
                {
                    applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(item.Start, item.Length, SpanTrackingMode.EdgeNegative);
                    qiContent.Add(info.DisplayText + Environment.NewLine + info.PropertyDocumentation);
                }
            }
        }
示例#51
0
        /// <summary>
        /// Determine which pieces of Quickinfo content should be displayed
        /// </summary>
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (_disposed)
                throw new ObjectDisposedException("TestQuickInfoSource");

            var triggerPoint = (SnapshotPoint) session.GetTriggerPoint(_buffer.CurrentSnapshot);

            if (triggerPoint == null)
                return;

            foreach (IMappingTagSpan<LuaTokenTag> curTag in _aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint)))
            {
                if (curTag.Tag.type == LuaTokenTypes.ReservedWord)
                {
                    var tagSpan = curTag.Span.GetSpans(_buffer).First();
                    applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);
                    quickInfoContent.Add("A reserved word");
                }
                else if (curTag.Tag.type == LuaTokenTypes.Operators)
                {
                    var tagSpan = curTag.Span.GetSpans(_buffer).First();
                    applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);
                    quickInfoContent.Add("A language operator");
                }
            }
        }
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (!EnsureTreeInitialized() || session == null || qiContent == null)
                return;

            // Map the trigger point down to our buffer.
            SnapshotPoint? point = session.GetTriggerPoint(_buffer.CurrentSnapshot);
            if (!point.HasValue)
                return;

            ParseItem item = _tree.StyleSheet.ItemBeforePosition(point.Value.Position);
            if (item == null || !item.IsValid)
                return;

            Selector sel = item.FindType<Selector>();
            if (sel == null)
                return;
            // Mixins don't have specificity
            if (sel.SimpleSelectors.Count == 1 && sel.SimpleSelectors[0].SubSelectors.Count == 1 && sel.SimpleSelectors[0].SubSelectors[0] is LessMixinDeclaration)
                return;

            applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(item.Start, item.Length, SpanTrackingMode.EdgeNegative);

            string content = GenerateContent(sel);
            qiContent.Add(content);
        }
示例#53
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (session == null || qiContent == null)
                return;

            // Map the trigger point down to our buffer.
            SnapshotPoint? point = session.GetTriggerPoint(_buffer.CurrentSnapshot);
            if (!point.HasValue)
                return;

            var snapshot = _buffer.CurrentSnapshot;
            var classifier = _classifierService.GetClassifier(_buffer);

            var doc = new SnapshotSpan(snapshot, 0, snapshot.Length);
            var line = point.Value.GetContainingLine();
            var idents = classifier.GetClassificationSpans(line.Extent);

            bool handled = HandleVariables(qiContent, ref applicableToSpan, idents, point);

            if (handled)
                return;

            HandleKeywords(qiContent, ref applicableToSpan, idents, point);
        }
示例#54
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, System.Collections.Generic.IList<object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            var textBuffer = session.TextView.TextBuffer;

            var vars = _provider._Analyzer.AnalyzeExpression(
                textBuffer.CurrentSnapshot,
                textBuffer,
                session.CreateTrackingSpan(textBuffer)
            );

            applicableToSpan = vars.Span;
            if (String.IsNullOrEmpty(vars.Expression)) {
                return;
            }

            bool first = true;
            var result = new StringBuilder();
            int count = 0;
            List<IAnalysisValue> listVars = new List<IAnalysisValue>(vars.Values);
            HashSet<string> descriptions = new HashSet<string>();
            bool multiline = false;
            foreach (var v in listVars) {
                string description = null;
                if (listVars.Count == 1) {
                    if (v.Description != null) {
                        description = v.Description;
                    }
                } else {
                    if (v.ShortDescription != null) {
                        description = v.ShortDescription;
                    }
                }

                if (descriptions.Add(description)) {
                    if (first) {
                        first = false;
                    } else {
                        if (result.Length == 0 || result[result.Length - 1] != '\n') {
                            result.Append(", ");
                        } else {
                            multiline = true;
                        }
                    }
                    result.Append(description);
                    count++;
                }
            }

            if (multiline) {
                result.Insert(0, vars.Expression + ": " + Environment.NewLine);
            } else {
                result.Insert(0, vars.Expression + ": ");
            }

            quickInfoContent.Add(result.ToString());
        }
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (session == null || qiContent == null || qiContent.Count > 0 || !WESettings.GetBoolean(WESettings.Keys.ShowBrowserTooltip))
                return;

            SnapshotPoint? point = session.GetTriggerPoint(_buffer.CurrentSnapshot);
            if (!point.HasValue)
                return;

            var tree = CssEditorDocument.FromTextBuffer(_buffer);
            ParseItem item = tree.StyleSheet.ItemBeforePosition(point.Value.Position);
            if (item == null || !item.IsValid)
                return;

            ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaForItem(_rootSchema, item);

            Tuple<ParseItem, ICssCompletionListEntry> tuple = GetEntriesAndPoint(item, point.Value, schema);
            if (tuple == null)
                return;

            ParseItem tipItem = tuple.Item1;
            ICssCompletionListEntry entry = tuple.Item2;
            if (tipItem == null || entry == null)
                return;

            var ruleSet = item.FindType<RuleSet>();

            //If the selector's full name would require computation (it's nested), compute it and add it to the output
            if (ruleSet != null && ruleSet.Parent.FindType<RuleSet>() != null)
            {
                qiContent.Add(LessDocument.GetLessSelectorName(ruleSet));
            }

            applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tipItem.Start, tipItem.Length, SpanTrackingMode.EdgeNegative);

            string syntax = entry.GetSyntax(schema.Version);
            string b = entry.GetAttribute("browsers");

            if (string.IsNullOrEmpty(b) && tipItem.Parent != null && tipItem.Parent is Declaration)
            {
                b = schema.GetProperty(((Declaration)tipItem.Parent).PropertyName.Text).GetAttribute("browsers");
                if (string.IsNullOrEmpty(syntax))
                    syntax = tipItem.Text;
            }

            if (!string.IsNullOrEmpty(syntax))
            {
                //var example = CreateExample(syntax);
                qiContent.Add("Example: " + syntax);
            }

            Dictionary<string, string> browsers = GetBrowsers(b);
            qiContent.Add(CreateBrowserList(browsers));
        }
        void IQuickInfoSource.AugmentQuickInfoSession(IQuickInfoSession existingQuickInfoSession, IList<object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            // Augmenting quick info isn't cancellable.
            var cancellationToken = CancellationToken.None;
            EventHookupSessionManager eventHookupSessionManager;

            // Ensure this is a quick info session created by event hookup
            if (!existingQuickInfoSession.Properties.TryGetProperty(typeof(EventHookupSessionManager), out eventHookupSessionManager))
            {
                applicableToSpan = null;
                return;
            }

            if (!eventHookupSessionManager.IsTrackingSession())
            {
                existingQuickInfoSession.Dismiss();
                applicableToSpan = null;
                return;
            }

            string eventHandlerName = null;

            // Get the event handler method name. The name was calculated when the quick info
            // session was created, so we do not need to wait for the task here.
            if (eventHookupSessionManager.CurrentSession.GetEventNameTask.Status == TaskStatus.RanToCompletion)
            {
                eventHandlerName = eventHookupSessionManager.CurrentSession.GetEventNameTask.Result;
            }

            if (eventHandlerName == null)
            {
                existingQuickInfoSession.Dismiss();
                applicableToSpan = null;
                return;
            }

            // We should show the quick info session. Calculate the span and create the content.
            var currentSnapshot = _textBuffer.CurrentSnapshot;
            applicableToSpan = currentSnapshot.CreateTrackingSpan(
                start: eventHookupSessionManager.CurrentSession.TrackingPoint.GetPosition(currentSnapshot),
                length: 0,
                trackingMode: SpanTrackingMode.EdgeInclusive);

            // Clear any existing quick info content. This ensures that the event hookup text is
            // the only text in the quick info.
            quickInfoContent.Clear();

            var content = CreateContent(eventHandlerName, _classificationTypeMap);

            quickInfoContent.Add(content);

            // For test purposes only!
            eventHookupSessionManager.TEST_MostRecentQuickInfoContent = content;
        }
示例#57
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, System.Collections.Generic.IList<object> quickInfoContent, out ITrackingSpan applicableToSpan) {
            if (_curSession != null && !_curSession.IsDismissed) {
                _curSession.Dismiss();
                _curSession = null;
            }

            _curSession = session;
            _curSession.Dismissed += CurSessionDismissed;

            var quickInfo = GetQuickInfo(session.TextView);
            AugmentQuickInfoWorker(quickInfoContent, quickInfo, out applicableToSpan);
        }
            public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> quickInfoContent, out ITrackingSpan applicableToSpan)
            {
                AssertIsForeground();
                if (!session.Properties.TryGetProperty<QuickInfoPresenterSession>(s_augmentSessionKey, out var presenterSession))
                {
                    applicableToSpan = session.ApplicableToSpan;
                    return;
                }

                session.Properties.RemoveProperty(s_augmentSessionKey);
                presenterSession.AugmentQuickInfoSession(quickInfoContent, out applicableToSpan);
            }
 private void TextViewMouseHover(object sender, MouseHoverEventArgs e) {
     if (_quickInfoSession != null && !_quickInfoSession.IsDismissed) {
         _quickInfoSession.Dismiss();
     }
     var pt = e.TextPosition.GetPoint(IsNodejsContent, PositionAffinity.Successor);
     if (pt != null) {
         _quickInfoSession = _provider._QuickInfoBroker.TriggerQuickInfo(
             _textView,
             pt.Value.Snapshot.CreateTrackingPoint(pt.Value.Position, PointTrackingMode.Positive),
             true);
     }
 }
示例#60
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;

            if (_disposed)
                throw new ObjectDisposedException("TestQuickInfoSource");

            var triggerPoint = (SnapshotPoint) session.GetTriggerPoint(_buffer.CurrentSnapshot);

            if (triggerPoint == null)
                return;

            foreach (IMappingTagSpan<ClassificationTag> curTag in _aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint)))
            {
                if (curTag.Tag.ClassificationType.Classification == "table")
                {
                    //var tagSpan = curTag.Span.GetSpans(_buffer).First();
                    //applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);
                    //quickInfoContent.Add("Lua table no need comment");
                }
                else if (curTag.Tag.ClassificationType.Classification == "function")
                {
                    //find table name for it
                    var tagSpan = curTag.Span.GetSpans(_buffer).First();
                    applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);
                    var start = tagSpan.Start;

                    string function = tagSpan.GetText();
                    string table = "_G";
                    if (start.Position > 1)
                    {
                        start -= 1;
                        char ch = start.GetChar();
                        if (ch == '.' || ch == ':')
                        {
                            var pos = start;
                            while (pos.Position > 0 && Help.is_word_char((pos - 1).GetChar()))
                            {
                                pos -= 1;
                            }
                            ITextSnapshot snapshot = _buffer.CurrentSnapshot;
                            table = snapshot.GetText(pos.Position, start.Position - pos.Position);
                        }
                    }

                    var s = Help.Instance.GetTableFunctionComment(table, function);
                    if(s == "")
                        s = ("Lua function");
                    quickInfoContent.Add(s);
                }
            }
        }