public void FormattedDescriptionMalformed()
        {
            var results = DisplayElementFactory.FormatDescriptionText("foo `bar baz").ToList();

            Assert.AreEqual(1, results.Count);
            AssertTextAndClassification(results[0], "foo `bar baz");
        }
예제 #2
0
        CompletionItem CreateNuGetVersionCompletionItem(string version, FeedKind kind)
        {
            var kindImage = DisplayElementFactory.GetImageElement(GetPackageImageId(kind));
            var item      = new CompletionItem(version, this, kindImage);

            return(item);
        }
예제 #3
0
        CompletionItem CreateSpecialItem(string text, string description, KnownImages image, MSBuildSpecialCommitKind kind)
        {
            var item = new CompletionItem(text, this, DisplayElementFactory.GetImageElement(image));

            item.Properties.AddProperty(typeof(MSBuildSpecialCommitKind), kind);
            item.AddDocumentation(description);
            return(item);
        }
        public void FormattedDescriptionOneElement()
        {
            var results = DisplayElementFactory.FormatDescriptionText("foo `bar` baz").ToList();

            Assert.AreEqual(3, results.Count);
            AssertTextAndClassification(results[0], "foo ");
            AssertTextAndClassification(results[1], "bar", PredefinedClassificationTypeNames.SymbolReference);
            AssertTextAndClassification(results[2], " baz");
        }
예제 #5
0
        static QuickInfoItem CreateQuickInfo(ITextSnapshot snapshot, IEnumerable <NavigationAnnotation> annotations)
        {
            var navs = annotations.ToList();

            var first = navs.First();
            var span  = snapshot.CreateTrackingSpan(first.Span.Start, first.Span.Length, SpanTrackingMode.EdgeInclusive);

            return(new QuickInfoItem(span, DisplayElementFactory.GetResolvedPathElement(navs)));
        }
예제 #6
0
        CompletionItem CreateSdkCompletionItem(SdkInfo info)
        {
            var img  = DisplayElementFactory.GetImageElement(KnownImages.Sdk);
            var item = new CompletionItem(info.Name, this, img);

            //FIXME better tooltips for SDKs
            item.AddDocumentation(info.Path);
            return(item);
        }
예제 #7
0
        CompletionItem CreateCompletionItem(BaseInfo info, MSBuildRootDocument doc, MSBuildResolveResult rr)
        {
            var image = DisplayElementFactory.GetImageElement(info);
            var item  = new CompletionItem(info.Name, this, image);

            item.AddDocumentationProvider(this);
            item.Properties.AddProperty(typeof(BaseInfo), info);
            return(item);
        }
 void Update()
 {
     store.Clear();
     if (documentTracker.Document?.DocumentContext.ParsedDocument is MSBuildParsedDocument doc)
     {
         var shorten = DisplayElementFactory.CreateFilenameShortener(doc.Document.RuntimeInformation);
         AddNode(store.AddNode(), doc.Document, shorten);
         ExpandAll();
     }
 }
예제 #9
0
        IEnumerable <CompletionItem> GetLcidCompletions()
        {
            var imageEl = DisplayElementFactory.GetImageElement(KnownImages.Constant);

            foreach (var culture in System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.AllCultures))
            {
                string name        = culture.Name;
                string id          = culture.LCID.ToString();
                string display     = culture.DisplayName;
                string displayText = $"{id} - ({display})";
                yield return(new CompletionItem(displayText, this, imageEl, ImmutableArray <CompletionFilter> .Empty, string.Empty, id, id, displayText, ImmutableArray <ImageElement> .Empty));
            }
        }
예제 #10
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);
        }
예제 #11
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));
        }
예제 #12
0
        //FIXME: can we display some kind of "loading" message while it loads?
        async Task <QuickInfoItem> CreateNuGetQuickInfo(ITextSnapshot snapshot, MSBuildRootDocument doc, MSBuildResolveResult rr, CancellationToken token)
        {
            IPackageInfo info      = null;
            var          packageId = (string)rr.Reference;

            try {
                var frameworkId = doc.GetTargetFrameworkNuGetSearchParameter();
                var infos       = await provider.PackageSearchManager.SearchPackageInfo(packageId, null, frameworkId).ToTask(token);

                //prefer non-local results as they will have more metadata
                info = infos
                       .FirstOrDefault(p => p.SourceKind != ProjectFileTools.NuGetSearch.Feeds.FeedKind.Local)
                       ?? infos.FirstOrDefault();
            }
            catch (Exception ex) {
                LoggingService.LogError("Error loading package description", ex);
            }

            var span = snapshot.CreateTrackingSpan(rr.ReferenceOffset, rr.ReferenceLength, SpanTrackingMode.EdgeInclusive);

            return(new QuickInfoItem(span, DisplayElementFactory.GetPackageInfoTooltip(packageId, info)));
        }
예제 #13
0
 DisplayElementFactory GetDisplayElementFactory() => displayElementFactory ?? (
     displayElementFactory = CompositionManager.Instance.GetExportedValue <DisplayElementFactory> ()
     );