diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2023-07-02 21:50:05 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2023-07-02 21:50:05 +0200 |
| commit | 2dbdd7584956c9a529a1ec7f1bd7096d43808c02 (patch) | |
| tree | 05b295ed759dec48bba4565d1b0671c2c2815251 /src/server/completion.odin | |
| parent | b9642f114f221c54c30efde20fc3664c85f7b809 (diff) | |
Fix issues with fake method completion not removing the selector after completing
Diffstat (limited to 'src/server/completion.odin')
| -rw-r--r-- | src/server/completion.odin | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/src/server/completion.odin b/src/server/completion.odin index ff37211..aa1aed2 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -335,7 +335,7 @@ get_selector_completion :: proc( } if common.config.enable_fake_method { - append_method_completion(ast_context, selector, &items) + append_method_completion(ast_context, selector, position_context, &items) } #partial switch v in selector.value { @@ -1616,12 +1616,21 @@ get_range_from_selection_start_to_dot :: proc( append_method_completion :: proc( ast_context: ^AstContext, symbol: Symbol, + position_context: ^DocumentPositionContext, items: ^[dynamic]CompletionItem, ) { if symbol.type != .Variable { return } + selector: ^ast.Expr + + if position_context.selector_expr != nil { + selector = position_context.selector_expr + } else { + selector = position_context.selector + } + for k, v in indexer.index.collection.packages { method := Method { name = symbol.name, @@ -1633,6 +1642,25 @@ append_method_completion :: proc( resolve_unresolved_symbol(ast_context, &symbol) build_procedure_symbol_signature(&symbol) + range, ok := get_range_from_selection_start_to_dot(position_context) + + if !ok { + return + } + + remove_range := common.Range { + start = range.start, + end = range.end, + } + + remove_edit := TextEdit { + range = remove_range, + newText = "", + } + + additionalTextEdits := make([]TextEdit, 1, context.temp_allocator) + additionalTextEdits[0] = remove_edit + item := CompletionItem { label = symbol.name, kind = cast(CompletionItemKind)symbol.type, @@ -1641,18 +1669,19 @@ append_method_completion :: proc( symbol, true, ), + additionalTextEdits = additionalTextEdits, + textEdit = TextEdit{ + newText = fmt.tprintf( + "%v($0)", + symbol.name, + ), + range = {start = range.end, end = range.end}, + }, + insertTextFormat = .Snippet, + InsertTextMode = .adjustIndentation, documentation = symbol.doc, } - if symbol.type == .Function && common.config.enable_snippets { - item.insertText = fmt.tprintf("%v($0)", item.label) - item.insertTextFormat = .Snippet - item.command = Command { - command = "editor.action.triggerParameterHints", - } - item.deprecated = .Deprecated in symbol.flags - } - append(items, item) } } |