Пример #1
0
        void UpdateGotoDefinition(CommandInfo info)
        {
            var rr  = ResolveCurrentLocation();
            var doc = GetDocument();

            info.Enabled = rr != null && MSBuildNavigation.CanNavigate(doc, Editor.CaretLocation, rr);
        }
Пример #2
0
        void GotoDefinition()
        {
            var rr     = ResolveCurrentLocation();
            var doc    = GetDocument();
            var result = MSBuildNavigation.GetNavigation(doc, Editor.CaretLocation, rr);

            MSBuildNavigationExtension.Navigate(result, doc);
        }
Пример #3
0
        protected override Task <IEnumerable <NavigationSegment> > RequestLinksAsync(int offset, int length, CancellationToken token)
        {
            var doc = (DocumentContext.ParsedDocument as MSBuildParsedDocument)?.Document;

            if (doc == null)
            {
                return(Task.FromResult(Enumerable.Empty <NavigationSegment> ()));
            }
            return(Task.Run(
                       () => CreateNavigationSegments(doc, MSBuildNavigation.ResolveAll(doc, offset, length))
                       ));
        }
        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 bool CanNavigate(ITextBuffer buffer, SnapshotPoint point, out MSBuildReferenceKind referenceKind)
        {
            Resolver.GetResolvedReference(buffer, point, out var doc, out var rr);

            if (MSBuildNavigation.CanNavigate(doc, point, rr))
            {
                referenceKind = rr.ReferenceKind;
                return(true);
            }

            referenceKind = MSBuildReferenceKind.None;
            return(false);
        }
Пример #6
0
        public override Task <TooltipItem> GetItem(TextEditor editor, DocumentContext ctx, int offset, CancellationToken token = default(CancellationToken))
        {
            var ext = editor.GetContent <MSBuildTextEditorExtension> ();
            MSBuildRootDocument doc;

            if (ext == null || (doc = ext.GetDocument()) == null)
            {
                return(Task.FromResult <TooltipItem> (null));
            }

            var loc         = editor.OffsetToLocation(offset);
            var annotations = MSBuildNavigation.GetAnnotationsAtLocation <NavigationAnnotation> (doc, loc);

            if (annotations != null && annotations.Any())
            {
                var first = annotations.First();
                int start = editor.LocationToOffset(first.Region.Begin);
                int end   = editor.LocationToOffset(first.Region.End);
                return(Task.FromResult(new TooltipItem(annotations, start, end - start)));
            }

            var rr = ext.ResolveAt(offset);

            if (rr != null)
            {
                if (rr.ReferenceKind == MSBuildReferenceKind.NuGetID)
                {
                    var item = new InfoItem {
                        Doc           = doc,
                        ResolveResult = rr,
                        Packages      = PackageSearchHelpers.SearchPackageInfo(
                            ext.PackageSearchManager, (string)rr.Reference, null, doc.GetTargetFrameworkNuGetSearchParameter(), CancellationToken.None
                            )
                    };
                    return(Task.FromResult(new TooltipItem(item, rr.ReferenceOffset, rr.ReferenceLength)));
                }
                var info = rr.GetResolvedReference(doc);
                if (info != null)
                {
                    var item = new InfoItem {
                        Info = info, Doc = doc, ResolveResult = rr
                    };
                    return(Task.FromResult(new TooltipItem(item, rr.ReferenceOffset, rr.ReferenceLength)));
                }
            }
            return(Task.FromResult <TooltipItem> (null));
        }
        public MSBuildNavigationResult GetNavigationResult(ITextBuffer buffer, SnapshotPoint point)
        {
            Resolver.GetResolvedReference(buffer, point, out var doc, out var rr);

            return(MSBuildNavigation.GetNavigation(doc, point, rr));
        }