public Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { QuickInfoItem quickInfoItem = null; if (session == null) { throw new ArgumentNullException("session"); } 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)) { ITrackingSpan applicableToSpan = analysis.TextSnapshot.CreateTrackingSpan(applicableTo, SpanTrackingMode.EdgeExclusive); quickInfoItem = new QuickInfoItem(applicableToSpan, description); } } return(Task.FromResult(quickInfoItem)); }
public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { var snapshot = _textBuffer.CurrentSnapshot; var triggerPoint = session.GetTriggerPoint(snapshot); if (!triggerPoint.HasValue) { return(null); } var navigationsResult = await _navigationTokenService .GetNavigationsAsync(triggerPoint.Value) .ConfigureAwait(false); if (navigationsResult == null) { return(null); } var dataElement = await _descriptionBuilder .GetColorizedDescriptionAsync(navigationsResult.Values, cancellationToken) .ConfigureAwait(false); if (dataElement == null) { return(null); } var tokenSpan = navigationsResult.ApplicableToken.Span; var applicableSpan = snapshot.CreateTrackingSpan(tokenSpan, SpanTrackingMode.EdgeInclusive); return(new QuickInfoItem(applicableSpan, dataElement)); }
// This is called on a background thread. public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { SnapshotPoint?triggerPoint = session.GetTriggerPoint(_buffer.CurrentSnapshot); if (triggerPoint != null) { ITextSnapshotLine line = triggerPoint.Value.GetContainingLine(); IList <ClassificationSpan> spans = _classifier.GetClassificationSpans(line.Extent); ClassificationSpan attrValue = spans.FirstOrDefault(s => s.ClassificationType.IsOfType("XML Attribute Value") && s.Span.Contains(triggerPoint.Value.Position)); if (attrValue != null) { ITrackingSpan id = _buffer.CurrentSnapshot.CreateTrackingSpan(attrValue.Span, SpanTrackingMode.EdgeInclusive); var fileName = VsctCompletionSource.GetFileName(attrValue.Span.GetText()); // Image exist if (!string.IsNullOrEmpty(fileName)) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var img = new Image { Source = new BitmapImage(new Uri(fileName)), MaxHeight = 500 }; return(new QuickInfoItem(id, img)); } } } return(null); }
// This is called on a background thread. public Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { var triggerPoint = session.GetTriggerPoint(_textBuffer.CurrentSnapshot); if (triggerPoint != null) { var line = triggerPoint.Value.GetContainingLine(); var lineNumber = triggerPoint.Value.GetContainingLine().LineNumber; var lineSpan = _textBuffer.CurrentSnapshot.CreateTrackingSpan(line.Extent, SpanTrackingMode.EdgeInclusive); var lineNumberElm = new ContainerElement( ContainerElementStyle.Wrapped, new ImageElement(_icon), new ClassifiedTextElement( new ClassifiedTextRun(PredefinedClassificationTypeNames.Keyword, "Line number: "), new ClassifiedTextRun(PredefinedClassificationTypeNames.Identifier, $"{lineNumber + 1}") )); var dateElm = new ContainerElement( ContainerElementStyle.Stacked, lineNumberElm, new ClassifiedTextElement( new ClassifiedTextRun(PredefinedClassificationTypeNames.SymbolDefinition, "The current date: "), new ClassifiedTextRun(PredefinedClassificationTypeNames.Comment, DateTime.Now.ToShortDateString()) )); return(Task.FromResult(new QuickInfoItem(lineSpan, dateElm))); } return(Task.FromResult <QuickInfoItem>(null)); }
public void AugmentQuickInfoSession(IAsyncQuickInfoSession 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 async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { if (!_textBuffer.ContentType.DisplayName.Contains("CSharp")) { return(await System.Threading.Tasks.Task.FromResult <QuickInfoItem>(null)); } _quickInfoUtils = new OverloadGenerator(_textBuffer, session); var overloads = _quickInfoUtils.GetAllOverLoadsForMousePosition(); ContainerElementBuilder uIHelper = new ContainerElementBuilder(); GeneralOptions options = await GeneralOptions.GetLiveInstanceAsync(); var showButton = options.ShowButtonToBrowser; if (overloads.Count > 0 || showButton) { if (overloads.Count > 0) { foreach (var item in overloads) { uIHelper.AddContainer(item); } } var symbol = _quickInfoUtils.GetSymbol(); if (showButton && symbol != null) { uIHelper.AddContainer("Search in browser", Buttonelement_Click); } var containers = uIHelper.Build(); return(await System.Threading.Tasks.Task.FromResult(new QuickInfoItem(session.ApplicableToSpan, containers))); } return(await System.Threading.Tasks.Task.FromResult <QuickInfoItem>(null)); }
public Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { if (!_state.HasAnyEvaluatedWatches) { return(Task.FromResult <QuickInfoItem>(null)); } var maybeExtentSpan = session.GetTriggerPoint(_textBuffer.CurrentSnapshot)?.GetWordExtentSpan(); if (!maybeExtentSpan.HasValue) { return(Task.FromResult <QuickInfoItem>(null)); } var wordExtent = maybeExtentSpan.Value; var watchName = wordExtent.GetText(); if (_state.TryGetEvaluated(watchName, out var evaluated)) { var applicableToSpan = _textBuffer.CurrentSnapshot.CreateTrackingSpan( wordExtent.Span.Start, watchName.Length, SpanTrackingMode.EdgeInclusive ); var displayElement = new ContainerElement( ContainerElementStyle.Stacked, new ClassifiedTextElement( new ClassifiedTextRun(PredefinedClassificationTypeNames.Identifier, watchName)), new ClassifiedTextElement( new ClassifiedTextRun(PredefinedClassificationTypeNames.Literal, evaluated.AppendByDelimiter('|'))) ); return(Task.FromResult(new QuickInfoItem(applicableToSpan, displayElement))); } return(Task.FromResult <QuickInfoItem>(null)); }
public async Task <QuickInfoItem?> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { SnapshotPoint?triggerPoint = session.GetTriggerPoint(_buffer?.CurrentSnapshot); if (triggerPoint.HasValue) { SnapshotSpan span = new(triggerPoint.Value.Snapshot, triggerPoint.Value.Position, 0); IMappingTagSpan <TokenTag> tag = _tags.GetTags(span).FirstOrDefault(t => t.Tag.GetTooltipAsync != null); if (tag != null && tag.Tag.GetTooltipAsync != null) { object?tooltip = await tag.Tag.GetTooltipAsync(triggerPoint.Value); if (tooltip == null) { return(null); } ContainerElement container = new(ContainerElementStyle.Stacked, tooltip); ITrackingSpan applicapleTo = _buffer !.CurrentSnapshot.CreateTrackingSpan(tag.Span.GetSpans(_buffer)[0], SpanTrackingMode.EdgeExclusive); return(new QuickInfoItem(applicapleTo, container)); } } return(null); }
public async Task <QuickInfoItem> GetQuickInfoItemAsync( IAsyncQuickInfoSession session, CancellationToken cancellationToken) { var snapshot = textBuffer.CurrentSnapshot; var triggerPoint = session.GetTriggerPoint(snapshot); if (triggerPoint is null) { return(null); } var position = triggerPoint.Value.Position; var document = snapshot.GetOpenDocumentInCurrentContextWithChanges(); var result = await CalculateQuickInfo(document, position, cancellationToken); if (!result.HasValue) { return(null); } var(message, span) = result.Value; return(new QuickInfoItem( snapshot.CreateTrackingSpan(new Span(span.Start, span.Length), SpanTrackingMode.EdgeExclusive), message)); }
public Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { return(Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.Selection) == false || session.Mark(nameof(SelectionQuickInfo)) == false ? System.Threading.Tasks.Task.FromResult <QuickInfoItem>(null) : InternalGetQuickInfoItemAsync(session, cancellationToken)); }
public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { var snapshot = _subjectBuffer.CurrentSnapshot; var position = session.GetTriggerPoint(snapshot); if (position.HasValue) { var document = await _documentProvider.GetDocumentAsync(snapshot, cancellationToken).ConfigureAwait(false); if (document == null) { return(null); } var quickInfoService = QuickInfoService.GetService(document); var item = await quickInfoService.GetQuickInfoAsync(document, position.Value.Position, cancellationToken).ConfigureAwait(false); if (item == null) { return(null); } var quickInfoElement = CreateElement(document, item.Content); return(new QuickInfoItem( snapshot.CreateTrackingSpan(item.TextSpan.ToSpan(), SpanTrackingMode.EdgeInclusive), quickInfoElement)); } return(null); }
/// <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)); }
private async Task EvaluateAndShowTooltipAsync(IAsyncQuickInfoSession session, ITextView view, SnapshotPoint point, DataTipInfo debugInfo, CancellationToken cancellationToken) { var options = DebuggingService.DebuggerSession.EvaluationOptions.Clone(); options.AllowMethodEvaluation = true; options.AllowTargetInvoke = true; var val = DebuggingService.CurrentFrame.GetExpressionValue(debugInfo.Text, options); if (val.IsEvaluating) { await WaitOneAsync(val.WaitHandle, cancellationToken); } if (cancellationToken.IsCancellationRequested) { return; } if (val == null || val.IsUnknown || val.IsNotSupported) { return; } if (!view.Properties.TryGetProperty(typeof(Gtk.Widget), out Gtk.Widget gtkParent)) { return; } provider.textDocumentFactoryService.TryGetTextDocument(view.TextDataModel.DocumentBuffer, out var textDocument); // This is a bit hacky, since AsyncQuickInfo is designed to display multiple elements if multiple sources // return value, we don't want that for debugger value hovering, hence we dismiss AsyncQuickInfo // and do our own thing, notice VS does same thing await session.DismissAsync(); await provider.joinableTaskContext.Factory.SwitchToMainThreadAsync(); this.lastView = view; val.Name = debugInfo.Text; window = new DebugValueWindow((Gtk.Window)gtkParent.Toplevel, textDocument?.FilePath, textBuffer.CurrentSnapshot.GetLineNumberFromPosition(debugInfo.Span.GetStartPoint(textBuffer.CurrentSnapshot)), DebuggingService.CurrentFrame, val, null); Ide.IdeApp.CommandService.RegisterTopWindow(window); var bounds = view.TextViewLines.GetCharacterBounds(point); view.LayoutChanged += LayoutChanged; #if CLOSE_ON_FOCUS_LOST view.LostAggregateFocus += View_LostAggregateFocus; #endif RegisterForHiddenAsync(view).Ignore(); window.LeaveNotifyEvent += LeaveNotifyEvent; #if MAC var cocoaView = ((ICocoaTextView)view); var cgPoint = cocoaView.VisualElement.ConvertPointToView(new CoreGraphics.CGPoint(bounds.Left - view.ViewportLeft, bounds.Top - view.ViewportTop), cocoaView.VisualElement.Superview); cgPoint.Y = cocoaView.VisualElement.Superview.Frame.Height - cgPoint.Y; window.ShowPopup(gtkParent, new Gdk.Rectangle((int)cgPoint.X, (int)cgPoint.Y, (int)bounds.Width, (int)bounds.Height), Components.PopupPosition.TopLeft); #else throw new NotImplementedException(); #endif }
public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { await Task.Yield().ConfigureAwait(false); if (cancellationToken.IsCancellationRequested) { return(null); } var syntaxTreeAndSnapshot = ParserService.SyntaxTreeAndSnapshot; if (syntaxTreeAndSnapshot == null) { return(null); } // Map the trigger point down to our buffer. SnapshotPoint?triggerPoint = session.GetTriggerPoint(syntaxTreeAndSnapshot.Snapshot); if (triggerPoint == null) { return(null); } var triggerToken = syntaxTreeAndSnapshot.SyntaxTree.Root.FindToken(triggerPoint.Value.Position); if (triggerToken.IsMissing || triggerToken.Parent == null) { return(null); } var applicableToSpan = syntaxTreeAndSnapshot.Snapshot.CreateTrackingSpan( triggerToken.Extent.Start, triggerToken.Extent.Length, SpanTrackingMode.EdgeExclusive); var location = triggerToken.GetLocation(); var qiContent = $"{triggerToken.GetText()}\r\n{triggerToken.Kind} Ln {location?.StartLine + 1} Ch {location?.StartCharacter + 1}\r\n{triggerToken.Parent?.GetType().Name}"; await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var modifier = ModifierKeys.Control | ModifierKeys.Shift; if ((Keyboard.Modifiers & modifier) != modifier) { return(null); } var controlControl = new SymbolQuickInfoControl { CrispImage = { Moniker = ImageMonikers.StatusInformation }, TextContent = { Content = qiContent } }; var qiItem = new QuickInfoItem(applicableToSpan: applicableToSpan, item: controlControl ); return(qiItem); }
public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); if (Keyboard.Modifiers != ModifierKeys.Control) { return(new QuickInfoItem(null, QuickInfoOverrider.CreateOverrider(session).Control)); } return(null); }
public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { if (DebuggingService.CurrentFrame == null) { return(null); } if (window != null) { await Runtime.RunInMainThread(DestroyWindow); } var view = session.TextView; var textViewLines = view.TextViewLines; var snapshot = textViewLines.FormattedSpan.Snapshot; var triggerPoint = session.GetTriggerPoint(textBuffer); if (snapshot.TextBuffer != triggerPoint.TextBuffer) { return(null); } var point = triggerPoint.GetPoint(snapshot); foreach (var debugInfoProvider in provider.debugInfoProviders) { DataTipInfo debugInfo = default; if (!view.Selection.IsEmpty) { foreach (var span in view.Selection.SelectedSpans) { if (span.Contains(point)) { //debugInfo = new DataTipInfo (snapshot.CreateTrackingSpan (span, SpanTrackingMode.EdgeInclusive), snapshot.GetText (span)); debugInfo = await debugInfoProvider.Value.GetDebugInfoAsync(span, cancellationToken); break; } } } else { debugInfo = await debugInfoProvider.Value.GetDebugInfoAsync(point, cancellationToken); } if (!debugInfo.IsDefault) { await EvaluateAndShowTooltipAsync(session, view, point, debugInfo, cancellationToken); return(null); } } return(null); }
// This is called on a background thread. public Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { var triggerPoint = session.GetTriggerPoint(_textBuffer.CurrentSnapshot); if (triggerPoint != null) { SnapshotPoint tp = (SnapshotPoint)triggerPoint; var line = triggerPoint.Value.GetContainingLine(); var lineNumber = triggerPoint.Value.GetContainingLine().LineNumber; var lineOffset = triggerPoint.Value.Position - line.Start.Position; string type = extractType(tp); if (type == null) { return(Task.FromResult <QuickInfoItem>(null)); } var lineSpan = _textBuffer.CurrentSnapshot.CreateTrackingSpan(line.Extent, SpanTrackingMode.EdgeInclusive); var lineNumberElm = new ContainerElement( ContainerElementStyle.Wrapped, new ImageElement(_icon1), new ClassifiedTextElement( new ClassifiedTextRun(PredefinedClassificationTypeNames.Keyword, "Line number: "), new ClassifiedTextRun(PredefinedClassificationTypeNames.Identifier, $"{lineNumber + 1}") )); var linePosElm = new ContainerElement( ContainerElementStyle.Wrapped, new ImageElement(_icon2), new ClassifiedTextElement( new ClassifiedTextRun(PredefinedClassificationTypeNames.Keyword, "Offset: "), new ClassifiedTextRun(PredefinedClassificationTypeNames.Identifier, $"{lineOffset + 1}") )); var typeElm = new ContainerElement( ContainerElementStyle.Wrapped, new ClassifiedTextElement( new ClassifiedTextRun(PredefinedClassificationTypeNames.Keyword, "Type: "), new ClassifiedTextRun(PredefinedClassificationTypeNames.Identifier, type) )); var resultElm = new ContainerElement( ContainerElementStyle.Stacked, lineNumberElm, linePosElm, typeElm ); return(Task.FromResult(new QuickInfoItem(lineSpan, resultElm))); } return(Task.FromResult <QuickInfoItem>(null)); }
public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { var options = await GeneralOptions.GetLiveInstanceAsync(); if (!options.ShowTooltips) { await session.DismissAsync(); } return(null); }
// This is called on a background thread. public Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { SnapshotPoint?triggerPoint = session.GetTriggerPoint(_textBuffer.CurrentSnapshot); if (triggerPoint != null) { ITextSnapshotLine line = triggerPoint.Value.GetContainingLine(); ITrackingSpan lineSpan = _textBuffer.CurrentSnapshot.CreateTrackingSpan(line.Extent, SpanTrackingMode.EdgeInclusive); string text = triggerPoint.Value.GetContainingLine().GetText(); //get whole line of current cursor pos string[] textArray = text.Split('"'); int partCount = textArray.Length / 2; if (partCount <= 0) { return(Task.FromResult <QuickInfoItem>(null)); //do not add anything to Quick Info } if (!JSONExtensionPackage.settings.isLoaded) //if langFile not loaded show ERROR msg in Quick Info { return(Task.FromResult(new QuickInfoItem(lineSpan, new ContainerElement(ContainerElementStyle.Stacked, new ClassifiedTextElement(new ClassifiedTextRun(PredefinedClassificationTypeNames.Keyword, "JSONEx: Not Loaded! If the problem persist add JSON Path in Tools/JSONEx Settings")))))); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < partCount; i++) { string key = textArray[2 * i + 1]; if (key.Contains(" ")) { continue; } string value = ""; if (JSONExtensionPackage.settings.langFile.ContainsKey(key)) { value = JSONExtensionPackage.settings.langFile[key]; } if (partCount == 1) { sb.Append(value); } else if (i == partCount - 1) { sb.Append($"{key}: {value}"); } else { sb.Append($"{key}: {value}\n"); } } return(Task.FromResult(new QuickInfoItem(lineSpan, new ContainerElement(ContainerElementStyle.Stacked, new ClassifiedTextElement(new ClassifiedTextRun(PredefinedClassificationTypeNames.Comment, sb.ToString())))))); } return(Task.FromResult <QuickInfoItem>(null)); //do not add anything to Quick Info }
public async Task <IntellisenseQuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { var triggerPoint = session.GetTriggerPoint(_subjectBuffer.CurrentSnapshot); if (!triggerPoint.HasValue) { return(null); } var snapshot = triggerPoint.Value.Snapshot; var document = snapshot.GetOpenDocumentInCurrentContextWithChanges(); if (document == null) { return(null); } var service = QuickInfoService.GetService(document); if (service == null) { return(null); } try { using (Logger.LogBlock(FunctionId.Get_QuickInfo_Async, cancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); var options = _globalOptions.GetSymbolDescriptionOptions(document.Project.Language); var item = await service.GetQuickInfoAsync(document, triggerPoint.Value, options, cancellationToken).ConfigureAwait(false); if (item != null) { var textVersion = snapshot.Version; var trackingSpan = textVersion.CreateTrackingSpan(item.Span.ToSpan(), SpanTrackingMode.EdgeInclusive); var classificationOptions = _globalOptions.GetClassificationOptions(document.Project.Language); return(await IntellisenseQuickInfoBuilder.BuildItemAsync( trackingSpan, item, document, classificationOptions, _threadingContext, _operationExecutor, _asyncListener, _streamingPresenter, cancellationToken).ConfigureAwait(false)); } return(null); } } catch (Exception e) when(FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken, ErrorSeverity.Critical)) { throw ExceptionUtilities.Unreachable; } }
public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { var snapshot = textBuffer.CurrentSnapshot; var result = await parser.GetOrProcessAsync(snapshot, cancellationToken); var doc = result?.MSBuildDocument; if (doc == null) { return(null); } var trigger = session.GetTriggerPoint(textBuffer); var offset = trigger.GetPosition(snapshot); var spine = parser.XmlParser.GetSpineParser(new SnapshotPoint(snapshot, offset)); var annotations = MSBuildNavigation.GetAnnotationsAtOffset <NavigationAnnotation> (doc, offset)?.ToList(); if (annotations != null && annotations.Count > 0) { return(CreateQuickInfo(snapshot, annotations)); } //FIXME: can we avoid awaiting this unless we actually need to resolve a function? need to propagate async downwards await provider.FunctionTypeProvider.EnsureInitialized(cancellationToken); var rr = MSBuildResolver.Resolve( spine, snapshot.GetTextSource(), doc, provider.FunctionTypeProvider, cancellationToken ); if (rr != null) { if (rr.ReferenceKind == MSBuildReferenceKind.NuGetID) { return(await CreateNuGetQuickInfo(snapshot, doc, rr, cancellationToken)); } var info = rr.GetResolvedReference(doc, provider.FunctionTypeProvider); if (info != null) { var element = await provider.DisplayElementFactory.GetInfoTooltipElement( session.TextView.TextBuffer, doc, info, rr, cancellationToken ); return(new QuickInfoItem( snapshot.CreateTrackingSpan(rr.ReferenceOffset, rr.ReferenceLength, SpanTrackingMode.EdgeInclusive), element)); } } return(null); }
public Task <QuickInfoItem> GetQuickInfoItemAsync( IAsyncQuickInfoSession session, CancellationToken cancellationToken) { var triggerPoint = session.GetTriggerPoint(this.textBuffer.CurrentSnapshot); if (triggerPoint != null) { var line = triggerPoint.Value.GetContainingLine(); var lineNumber = triggerPoint.Value.GetContainingLine().LineNumber; var lineSpan = this.textBuffer.CurrentSnapshot.CreateTrackingSpan( line.Extent, SpanTrackingMode.EdgeInclusive); object content = null; // Check if this is an even line. if ((lineNumber % 2) == 1) { content = new ContainerElement( ContainerElementStyle.Wrapped, new ImageElement(AssemblyWarningImageId), new ClassifiedTextElement( new ClassifiedTextRun(PredefinedClassificationTypeNames.Keyword, "Even Or Odd: "), new ClassifiedTextRun(PredefinedClassificationTypeNames.Identifier, "Even"))); } else { content = new ContainerElement( ContainerElementStyle.Wrapped, new ImageElement(AssemblyWarningImageId), new ClassifiedTextElement( new ClassifiedTextRun(PredefinedClassificationTypeNames.Keyword, "Even Or Odd: "), new ClassifiedTextRun(PredefinedClassificationTypeNames.Identifier, "Odd"))); } var contentContainer = new ContainerElement( ContainerElementStyle.Stacked, content, new ClassifiedTextElement( new ClassifiedTextRun( PredefinedClassificationTypeNames.Identifier, "The current date and time is: " + DateTime.Now.ToString()))); return(Task.FromResult( new QuickInfoItem( lineSpan, contentContainer))); } return(Task.FromResult <QuickInfoItem>(null)); }
public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { await Task.Yield().ConfigureAwait(false); if (cancellationToken.IsCancellationRequested) { return(null); } var syntaxTreeAndSnapshot = ParserService.SyntaxTreeAndSnapshot; if (syntaxTreeAndSnapshot == null) { return(null); } // Map the trigger point down to our buffer. SnapshotPoint?triggerPoint = session.GetTriggerPoint(syntaxTreeAndSnapshot.Snapshot); if (triggerPoint == null) { return(null); } var qiInfo = QuickInfoProvider.GetQuickInfoDefinition(syntaxTreeAndSnapshot.SyntaxTree, triggerPoint.Value.Position); if (qiInfo == null) { return(null); } var applicableToSpan = syntaxTreeAndSnapshot.Snapshot.CreateTrackingSpan( qiInfo.ApplicableToExtent.Start, qiInfo.ApplicableToExtent.Length, SpanTrackingMode.EdgeExclusive); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var qiContent = _textBlockBuilderService.ToTextBlock(qiInfo.Content); var controlControl = new SymbolQuickInfoControl { CrispImage = { Moniker = GdImageMonikers.GetMoniker(qiInfo.Glyph) }, TextContent = { Content = qiContent } }; var qiItem = new QuickInfoItem(applicableToSpan: applicableToSpan, item: controlControl ); return(qiItem); }
static async Task <QuickInfoItem> InternalGetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var textSnapshot = session.TextView.TextSnapshot; var triggerPoint = session.GetTriggerPoint(textSnapshot).GetValueOrDefault(); try { return(ShowSelectionInfo(session, triggerPoint)); } catch (ArgumentException /*triggerPoint has a differ TextBuffer from textSnapshot*/) { return(null); } }
public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { if (!session.TextView.TextBuffer.Properties.TryGetProperty(typeof(ITextDocument), out ITextDocument textDoc)) { return(null); } SnapshotPoint?triggerPoint = session.GetTriggerPoint(session.TextView.TextSnapshot); if (triggerPoint == null) { return(null); } int pos = triggerPoint.Value.Position; if (!PackageCompletionSource.IsInRangeForPackageCompletion(session.TextView.TextSnapshot, pos, out Span s, out string packageId, out string packageVersion, out string type)) { XmlInfo info = XmlTools.GetXmlInfo(session.TextView.TextSnapshot, pos); if (info != null) { IWorkspace workspace = workspace = _workspaceManager.GetWorkspace(textDoc.FilePath); string evaluatedValue = workspace.GetEvaluatedPropertyValue(info.AttributeValue); ITrackingSpan target = session.TextView.TextSnapshot.CreateTrackingSpan(new Span(info.AttributeValueStart, info.AttributeValueLength), SpanTrackingMode.EdgeNegative); if (info.AttributeName == "Condition") { try { bool isTrue = workspace.EvaluateCondition(info.AttributeValue); evaluatedValue = $"Expanded value: {evaluatedValue}\nEvaluation result: {isTrue}"; await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); return(new QuickInfoItem(target, evaluatedValue)); } catch (Exception ex) { Debug.Fail(ex.ToString()); } } else { evaluatedValue = $"Value(s):\n {string.Join("\n ", evaluatedValue.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))}"; await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); return(new QuickInfoItem(target, evaluatedValue)); } } }
public Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { try { var trigger_point = (SnapshotPoint)session.GetTriggerPoint(_buffer.CurrentSnapshot); if (trigger_point == null) { return(Task.FromResult <QuickInfoItem>(null)); } string file_path = _buffer.GetFFN().Result; if (file_path == null) { return(Task.FromResult <QuickInfoItem>(null)); } if (_grammar_description == null) { return(Task.FromResult <QuickInfoItem>(null)); } if (!_grammar_description.IsFileType(file_path)) { Task.FromResult <QuickInfoItem>(null); } var document = Workspaces.Workspace.Instance.FindDocument(file_path); if (document == null) { return(Task.FromResult <QuickInfoItem>(null)); } int index = trigger_point.Position; var info = LanguageServer.Module.GetQuickInfo(index, document); if (info == null || info.Display == null || info.Display == "") { return(Task.FromResult <QuickInfoItem>(null)); } ITextView view = session.TextView; var len = 1 + info.Range.End.Value - info.Range.Start.Value; var start = info.Range.Start.Value; if (len + start > view.TextSnapshot.Length) { len = len - (len + start - view.TextSnapshot.Length); } SnapshotSpan span = new SnapshotSpan(view.TextSnapshot, new Span(start, len)); var tracking_span = _buffer.CurrentSnapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeInclusive); return(Task.FromResult(new QuickInfoItem(tracking_span, info.Display))); } catch (Exception exception) { Logger.Log.Notify(exception.StackTrace); } return(Task.FromResult <QuickInfoItem>(null)); }
/// <summary> /// Determine if the mouse is hovering over a token. If so, highlight the token and display QuickInfo /// </summary> private async void OnTextViewMouseHover(object sender, MouseHoverEventArgs e) { SnapshotPoint?point = GetMousePosition(new SnapshotPoint(_textView.TextSnapshot, e.Position)); if (point.HasValue) { ITrackingPoint triggerPoint = point.Value.Snapshot.CreateTrackingPoint(point.Value.Position, PointTrackingMode.Positive); // Find the broker for this buffer if (!_componentContext.QuickInfoBroker.IsQuickInfoActive(_textView)) { _session = await _componentContext.QuickInfoBroker.TriggerQuickInfoAsync(_textView, triggerPoint); } } }
// This is called on a background thread. public Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken _) //XYZZY NEW { MyTools.Output_INFO(string.Format("{0}:GetQuickInfoItemAsync", this.ToString())); var triggerPoint = session.GetTriggerPoint(this._textBuffer.CurrentSnapshot); if (triggerPoint != null) { var line = triggerPoint.Value.GetContainingLine(); var applicableToSpan = this._textBuffer.CurrentSnapshot.CreateTrackingSpan(line.Extent, SpanTrackingMode.EdgeInclusive); return(Task <QuickInfoItem> .Factory.StartNew(() => this.RunOnUI(applicableToSpan), CancellationToken.None, TaskCreationOptions.None, this._uiScheduler)); } return(Task.FromResult <QuickInfoItem>(null)); }
public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { if (_curSession != null && _curSession.State != QuickInfoSessionState.Dismissed) { await _curSession.DismissAsync(); _curSession = null; } _curSession = session; _curSession.StateChanged += CurSessionStateChanged; var quickInfo = GetQuickInfo(session.TextView); return(quickInfo != null ? new QuickInfoItem(quickInfo.Span, quickInfo.Text) : null); }
public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); // don't show Quick Info when CtrlQuickInfo option is on and shift is not pressed if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.CtrlQuickInfo) && Keyboard.Modifiers.MatchFlags(ModifierKeys.Shift) == false // do not show Quick Info when user is hovering on the SmartBar or the SymbolList || session.TextView.Properties.ContainsProperty(SmartBars.SmartBar.QuickInfoSuppressionId) || session.TextView.Properties.ContainsProperty(Controls.ExternalAdornment.QuickInfoSuppressionId) ) { await session.DismissAsync(); } return(null); }