Example #1
0
        public async Task <CompletionList> Handle(CompletionParams request, CancellationToken token)
        {
            var(document, position) = _workspace.GetLogicalDocument(request);

            var completionService = document.GetLanguageService <CompletionService>();

            Microsoft.CodeAnalysis.Completion.CompletionTrigger trigger;
            if (request.Context.TriggerKind == OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionTriggerKind.TriggerCharacter)
            {
                trigger = Microsoft.CodeAnalysis.Completion.CompletionTrigger.CreateInsertionTrigger(request.Context.TriggerCharacter[0]);
            }
            else
            {
                trigger = Microsoft.CodeAnalysis.Completion.CompletionTrigger.Invoke;
            }

            var completionList = await completionService.GetCompletionsAsync(document, position, trigger, cancellationToken : token);

            if (completionList == null)
            {
                return(new CompletionList());
            }

            var completionItems = completionList.Items
                                  .Select(x => ConvertCompletionItem(document, completionList.Rules, x))
                                  .ToArray();

            return(completionItems);
        }
Example #2
0
        public async Task <LocationOrLocationLinks> Handle(DefinitionParams request, CancellationToken token)
        {
            var(document, position) = _workspace.GetLogicalDocument(request);

            var goToDefinitionService = document.GetLanguageService <IGoToDefinitionService>();
            var definitions           = await goToDefinitionService.FindDefinitionsAsync(document, position, token);

            // TODO: Handle spans within embedded HLSL blocks; the TextSpan is currently relative to the start of the embedded block.

            var locations = new List <LocationOrLocationLink>();

            foreach (var definition in definitions)
            {
                var documentSpan = definition.SourceSpans[0];
                var sourceSpan   = documentSpan.SourceSpan;
                locations.Add(new Location
                {
                    Uri   = Helpers.ToUri(sourceSpan.File.FilePath),
                    Range = sourceSpan.IsInRootFile
                        ? Helpers.ToRange(document.SourceText, sourceSpan.Span)
                        : Helpers.ToRange(sourceSpan.File.Text, sourceSpan.Span)
                });
            }

            return(locations);
        }
        public async Task <DocumentHighlightContainer> Handle(DocumentHighlightParams request, CancellationToken token)
        {
            var(document, position) = _workspace.GetLogicalDocument(request);

            var documentHighlightsService = _workspace.Services.GetService <IDocumentHighlightsService>();

            var documentHighlightsList = await documentHighlightsService.GetDocumentHighlightsAsync(
                document, position,
                ImmutableHashSet <Document> .Empty, // TODO
                token);

            var result = new List <DocumentHighlight>();

            foreach (var documentHighlights in documentHighlightsList)
            {
                if (documentHighlights.Document != document)
                {
                    continue;
                }

                foreach (var highlightSpan in documentHighlights.HighlightSpans)
                {
                    result.Add(new DocumentHighlight
                    {
                        Kind = highlightSpan.Kind == HighlightSpanKind.Definition
                            ? DocumentHighlightKind.Write
                            : DocumentHighlightKind.Read,
                        Range = Helpers.ToRange(document.SourceText, highlightSpan.TextSpan)
                    });
                }
            }

            return(result);
        }
        public Task <SignatureHelp> Handle(SignatureHelpParams request, CancellationToken token)
        {
            var(document, position) = _workspace.GetLogicalDocument(request);

            var signatureHelpService = _workspace.Services.GetService <SignatureHelpService>();

            return(signatureHelpService.GetResultAsync(document, position, token));
        }
Example #5
0
        public async Task <Hover> Handle(HoverParams request, CancellationToken token)
        {
            var(document, position) = _workspace.GetLogicalDocument(request);

            var providerCoordinatorFactory = _workspace.GetGlobalService <IQuickInfoProviderCoordinatorFactory>();
            var providerCoordinator        = providerCoordinatorFactory.CreateCoordinator(document);

            var(item, _) = await providerCoordinator.GetItemAsync(document, position, token);

            if (item != null)
            {
                var   symbolInfo = new List <MarkupContent>();
                Range symbolRange;

                var markdownText = string.Empty;

                switch (item.Content)
                {
                case QuickInfoDisplayContent c:
                    markdownText += $"``` {document.Language}\n{c.MainDescription.GetFullText()}\n```\n";

                    if (!c.Documentation.IsEmpty)
                    {
                        markdownText += c.Documentation.GetFullText();
                    }

                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                symbolRange = Helpers.ToRange(document, item.TextSpan);

                return(new Hover
                {
                    Contents = new MarkedStringsOrMarkupContent(new MarkupContent {
                        Kind = MarkupKind.Markdown, Value = markdownText
                    }),
                    Range = symbolRange
                });
            }
            else
            {
                return(null);
            }
        }
Example #6
0
        public async Task <CompletionList> Handle(CompletionParams request, CancellationToken token)
        {
            var(document, position) = _workspace.GetLogicalDocument(request);

            var completionService = document.GetLanguageService <CompletionService>();

            var completionList = await completionService.GetCompletionsAsync(document, position);

            if (completionList == null)
            {
                return(new CompletionList());
            }

            var completionItems = completionList.Items
                                  .Select(x => ConvertCompletionItem(document, completionList.Rules, x))
                                  .ToArray();

            return(completionItems);
        }
Example #7
0
        public async Task <Hover> Handle(HoverParams request, CancellationToken token)
        {
            var(document, position) = _workspace.GetLogicalDocument(request);

            var quickInfoService = document.LanguageServices.GetRequiredService <QuickInfoService>();

            var item = await quickInfoService.GetQuickInfoAsync(document, position, token);

            if (item != null)
            {
                Range symbolRange;

                var content      = item.Content;
                var markdownText = $"``` {Helpers.ToLspLanguage(document.Language)}\n{content.MainDescription.GetFullText()}\n```\n";

                if (!content.Documentation.IsEmpty)
                {
                    markdownText += "---\n";
                    markdownText += content.Documentation.GetFullText();
                }

                symbolRange = Helpers.ToRange(document.SourceText, item.TextSpan);

                return(new Hover
                {
                    Contents = new MarkedStringsOrMarkupContent(new MarkupContent {
                        Kind = MarkupKind.Markdown, Value = markdownText
                    }),
                    Range = symbolRange
                });
            }
            else
            {
                return(null);
            }
        }