diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2023-03-10 19:51:49 +0100 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2023-03-10 19:51:49 +0100 |
| commit | 998ac324d217b6b7ca32fb7c6bd31af830148f5a (patch) | |
| tree | c95d37111d5ae853adca01dc30646396149adb9a /src/server | |
| parent | d0a4169a4eb2a2a703af41ae1c221d449030516b (diff) | |
Start working on labeldetails
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/completion.odin | 27 | ||||
| -rw-r--r-- | src/server/inlay_hints.odin | 16 | ||||
| -rw-r--r-- | src/server/requests.odin | 9 | ||||
| -rw-r--r-- | src/server/types.odin | 28 |
4 files changed, 63 insertions, 17 deletions
diff --git a/src/server/completion.odin b/src/server/completion.odin index 2ca11d0..ebd88db 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -150,6 +150,10 @@ get_completion_list :: proc( get_package_completion(&ast_context, &position_context, &list) } + if common.config.enable_label_details { + format_to_label_details(&list) + } + return list, true } @@ -597,8 +601,9 @@ get_selector_completion :: proc( if symbol.type == .Function && common.config.enable_snippets { item.insertText = fmt.tprintf("%v($0)", item.label) item.insertTextFormat = .Snippet - item.command.command = - "editor.action.triggerParameterHints" + item.command = Command { + command = "editor.action.triggerParameterHints", + } item.deprecated = .Deprecated in symbol.flags } @@ -1354,7 +1359,9 @@ get_identifier_completion :: proc( item.insertText = fmt.tprintf("%v($0)", item.label) item.insertTextFormat = .Snippet item.deprecated = .Deprecated in result.flags - item.command.command = "editor.action.triggerParameterHints" + item.command = Command { + command = "editor.action.triggerParameterHints", + } } item.detail = concatenate_symbol_information( @@ -1760,6 +1767,20 @@ append_magic_union_completion :: proc( } +//Temporary hack to support labeldetails +format_to_label_details :: proc(list: ^CompletionList) { + for item in &list.items { + if item.kind == .Function && true { + proc_index := strings.index(item.detail, "proc") + + item.labelDetails = CompletionItemLabelDetails { + detail = item.detail[proc_index + 4:len(item.detail)], + } + } + } +} + + bitset_operators: map[string]bool = { "|" = true, "&" = true, diff --git a/src/server/inlay_hints.odin b/src/server/inlay_hints.odin index 59f3c86..b258b44 100644 --- a/src/server/inlay_hints.odin +++ b/src/server/inlay_hints.odin @@ -38,6 +38,8 @@ get_inlay_hints :: proc( data := cast(^Visit_Data)visitor.data if call, ok := node.derived.(^ast.Call_Expr); ok { + + append(&data.calls, node) } @@ -53,6 +55,7 @@ get_inlay_hints :: proc( ast.walk(&visitor, decl) } + loop: for node_call in &data.calls { symbol_arg_count := 0 @@ -74,13 +77,14 @@ get_inlay_hints :: proc( } if ident, ok := name.derived.(^ast.Ident); ok { + range := common.get_token_range( + call.args[symbol_arg_count], + string(document.text), + ) hint := InlayHint { - kind = "parameter", - label = fmt.tprintf("%v = ", ident.name), - range = common.get_token_range( - call.args[symbol_arg_count], - string(document.text), - ), + kind = .Parameter, + label = fmt.tprintf("%v = ", ident.name), + position = range.start, } append(&hints, hint) } diff --git a/src/server/requests.odin b/src/server/requests.odin index b9ac631..96f24f5 100644 --- a/src/server/requests.odin +++ b/src/server/requests.odin @@ -271,7 +271,7 @@ call_map: map[string]proc( "textDocument/semanticTokens/range" = request_semantic_token_range, "textDocument/hover" = request_hover, "textDocument/formatting" = request_format_document, - "odin/inlayHints" = request_inlay_hint, + "textDocument/inlayHint" = request_inlay_hint, "textDocument/documentLink" = request_document_links, "textDocument/rename" = request_rename, "textDocument/references" = request_references, @@ -573,8 +573,12 @@ request_initialize :: proc( } } + config.enable_label_details = + initialize_params.capabilities.textDocument.completion.completionItem.labelDetailsSupport + config.enable_snippets &= initialize_params.capabilities.textDocument.completion.completionItem.snippetSupport + config.signature_offset_support = initialize_params.capabilities.textDocument.signatureHelp.signatureInformation.parameterInformation.labelOffsetSupport @@ -626,6 +630,7 @@ request_initialize :: proc( completionProvider = CompletionOptions{ resolveProvider = false, triggerCharacters = completionTriggerCharacters, + completionItem = {labelDetailsSupport = true}, }, signatureHelpProvider = SignatureHelpOptions{ triggerCharacters = signatureTriggerCharacters, @@ -639,7 +644,7 @@ request_initialize :: proc( tokenModifiers = token_modifiers, }, }, - inlayHintsProvider = config.enable_inlay_hints, + inlayHintProvider = config.enable_inlay_hints, documentSymbolProvider = config.enable_document_symbols, hoverProvider = config.enable_hover, documentFormattingProvider = config.enable_format, diff --git a/src/server/types.odin b/src/server/types.odin index cbb168f..73f3938 100644 --- a/src/server/types.odin +++ b/src/server/types.odin @@ -94,7 +94,7 @@ ServerCapabilities :: struct { documentSymbolProvider: bool, hoverProvider: bool, documentFormattingProvider: bool, - inlayHintsProvider: bool, + inlayHintProvider: bool, renameProvider: bool, referencesProvider: bool, documentLinkProvider: DocumentLinkOptions, @@ -103,6 +103,9 @@ ServerCapabilities :: struct { CompletionOptions :: struct { resolveProvider: bool, triggerCharacters: []string, + completionItem: struct { + labelDetailsSupport: bool, + }, } CompletionContext :: struct { @@ -141,7 +144,8 @@ GeneralClientCapabilities :: struct { } CompletionItemCapabilities :: struct { - snippetSupport: bool, + snippetSupport: bool, + labelDetailsSupport: bool, } CompletionClientCapabilities :: struct { @@ -299,7 +303,13 @@ CompletionItem :: struct { additionalTextEdits: []TextEdit, tags: []CompletionItemTag, deprecated: bool, - command: Command, + command: Maybe(Command), + labelDetails: Maybe(CompletionItemLabelDetails), +} + +CompletionItemLabelDetails :: struct { + detail: string, + description: string, } CompletionItemTag :: enum { @@ -384,6 +394,7 @@ HoverParams :: struct { InlayParams :: struct { textDocument: TextDocumentIdentifier, + range: common.Range, } Hover :: struct { @@ -397,10 +408,15 @@ Command :: struct { arguments: []string, } +InlayHintKind :: enum { + Type = 1, + Parameter = 2, +} + InlayHint :: struct { - range: common.Range, - kind: string, - label: string, + position: common.Position, + kind: InlayHintKind, + label: string, } DocumentLinkClientCapabilities :: struct { |