예제 #1
0
        protected static async Task <LSP.VSCompletionItem> CreateCompletionItemAsync(
            string label,
            LSP.CompletionItemKind kind,
            string[] tags,
            LSP.CompletionParams request,
            Document document,
            bool preselect = false,
            ImmutableArray <char>?commitCharacters = null,
            LSP.TextEdit?textEdit = null,
            string?insertText     = null,
            string?sortText       = null,
            string?filterText     = null,
            long resultId         = 0
            )
        {
            var position = await document
                           .GetPositionFromLinePositionAsync(
                ProtocolConversions.PositionToLinePosition(request.Position),
                CancellationToken.None
                )
                           .ConfigureAwait(false);

            var completionTrigger = await ProtocolConversions
                                    .LSPToRoslynCompletionTriggerAsync(
                request.Context,
                document,
                position,
                CancellationToken.None
                )
                                    .ConfigureAwait(false);

            var item = new LSP.VSCompletionItem()
            {
                TextEdit         = textEdit,
                InsertText       = insertText,
                FilterText       = filterText ?? label,
                Label            = label,
                SortText         = sortText ?? label,
                InsertTextFormat = LSP.InsertTextFormat.Plaintext,
                Kind             = kind,
                Data             = JObject.FromObject(new CompletionResolveData()
                {
                    ResultId = resultId,
                }),
                Preselect = preselect
            };

            if (tags != null)
            {
                item.Icon = tags.ToImmutableArray().GetFirstGlyph().GetImageElement();
            }

            if (commitCharacters != null)
            {
                item.CommitCharacters = commitCharacters.Value.Select(c => c.ToString()).ToArray();
            }

            return(item);
        }
        protected static LSP.VSCompletionItem CreateCompletionItem(
            string insertText,
            LSP.CompletionItemKind kind,
            string[] tags,
            LSP.CompletionParams requestParameters,
            bool preselect = false,
            ImmutableArray <char>?commitCharacters = null,
            string?sortText = null,
            int resultId    = 0)
        {
            var item = new LSP.VSCompletionItem()
            {
                FilterText       = insertText,
                InsertText       = insertText,
                Label            = insertText,
                SortText         = sortText ?? insertText,
                InsertTextFormat = LSP.InsertTextFormat.Plaintext,
                Kind             = kind,
                Data             = JObject.FromObject(new CompletionResolveData()
                {
                    DisplayText       = insertText,
                    TextDocument      = requestParameters.TextDocument,
                    Position          = requestParameters.Position,
                    CompletionTrigger = ProtocolConversions.LSPToRoslynCompletionTrigger(requestParameters.Context),
                    ResultId          = resultId,
                }),
                Preselect = preselect
            };

            if (tags != null)
            {
                item.Icon = tags.ToImmutableArray().GetFirstGlyph().GetImageElement();
            }

            if (commitCharacters != null)
            {
                item.CommitCharacters = commitCharacters.Value.Select(c => c.ToString()).ToArray();
            }

            return(item);
        }
예제 #3
0
        private static LSP.VSCompletionItem CreateResolvedCompletionItem(string text, LSP.CompletionItemKind kind, string[] tags, LSP.CompletionParams requestParameters,
                                                                         ClassifiedTextElement description, string detail, string documentation, string[] commitCharacters = null)
        {
            var resolvedCompletionItem = CreateCompletionItem(text, kind, tags, requestParameters, commitCharacters: commitCharacters);

            resolvedCompletionItem.Detail = detail;
            if (documentation != null)
            {
                resolvedCompletionItem.Documentation = new LSP.MarkupContent()
                {
                    Kind  = LSP.MarkupKind.PlainText,
                    Value = documentation
                };
            }

            resolvedCompletionItem.Description = description;
            return(resolvedCompletionItem);
        }
예제 #4
0
        public static Glyph CompletionItemKindToGlyph(LSP.CompletionItemKind kind)
        {
            switch (kind)
            {
            case LSP.CompletionItemKind.Text:
                return(Glyph.None);

            case LSP.CompletionItemKind.Method:
            case LSP.CompletionItemKind.Constructor:
                return(Glyph.MethodPublic);

            case LSP.CompletionItemKind.Function:
                return(Glyph.DelegatePublic);

            case LSP.CompletionItemKind.Field:
                return(Glyph.FieldPublic);

            case LSP.CompletionItemKind.Variable:
            case LSP.CompletionItemKind.Unit:
            case LSP.CompletionItemKind.Value:
                return(Glyph.Local);

            case LSP.CompletionItemKind.Class:
                return(Glyph.ClassPublic);

            case LSP.CompletionItemKind.Interface:
                return(Glyph.InterfacePublic);

            case LSP.CompletionItemKind.Module:
                return(Glyph.ModulePublic);

            case LSP.CompletionItemKind.Property:
                return(Glyph.PropertyPublic);

            case LSP.CompletionItemKind.Enum:
                return(Glyph.EnumPublic);

            case LSP.CompletionItemKind.Keyword:
                return(Glyph.Keyword);

            case LSP.CompletionItemKind.Snippet:
                return(Glyph.Snippet);

            case LSP.CompletionItemKind.Color:
                return(Glyph.None);

            case LSP.CompletionItemKind.File:
                return(Glyph.CSharpFile);

            case LSP.CompletionItemKind.Reference:
                return(Glyph.Reference);

            case LSP.CompletionItemKind.Folder:
                return(Glyph.OpenFolder);

            case LSP.CompletionItemKind.EnumMember:
                return(Glyph.EnumMemberPublic);

            case LSP.CompletionItemKind.Constant:
                return(Glyph.ConstantPublic);

            case LSP.CompletionItemKind.Struct:
                return(Glyph.StructurePublic);

            case LSP.CompletionItemKind.Event:
                return(Glyph.EventPublic);

            case LSP.CompletionItemKind.Operator:
                return(Glyph.Operator);

            case LSP.CompletionItemKind.TypeParameter:
                return(Glyph.TypeParameter);

            default:
                return(Glyph.None);
            }
        }