예제 #1
0
        public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken)
        {
            var parser   = GetParser();
            var snapshot = textBuffer.CurrentSnapshot;

            var result = await parser.GetOrParseAsync((ITextSnapshot2)snapshot, cancellationToken);

            var doc = result.MSBuildDocument;

            //.LastParseResult?.MSBuildDocument ?? MSBuildRootDocument.CreateTestDocument ();

            if (doc == null)
            {
                return(null);
            }

            var trigger = session.GetTriggerPoint(textBuffer);
            var offset  = trigger.GetPosition(snapshot);

            var spine = parser.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);

            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 DisplayElementFactory.GetInfoTooltipElement(doc, info, rr, cancellationToken);

                    return(new QuickInfoItem(
                               snapshot.CreateTrackingSpan(rr.ReferenceOffset, rr.ReferenceLength, SpanTrackingMode.EdgeInclusive),
                               element));
                }
            }
            return(null);
        }
예제 #2
0
        Task <object> ICompletionDocumentationProvider.GetDocumentationAsync(IAsyncCompletionSession session, CompletionItem item, CancellationToken token)
        {
            if (!item.Properties.TryGetProperty <BaseInfo> (typeof(BaseInfo), out var info) || info == null)
            {
                return(Task.FromResult <object> (null));
            }

            if (!session.Properties.TryGetProperty <MSBuildCompletionSessionContext> (typeof(MSBuildCompletionSessionContext), out var context))
            {
                return(Task.FromResult <object> (null));
            }

            return(DisplayElementFactory.GetInfoTooltipElement(context.doc, info, context.rr, token));
        }