diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2022-03-14 01:02:43 +0100 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2022-03-14 01:02:43 +0100 |
| commit | 06562b8ff7d3d4ad3bb22b66eef8c8111fe243da (patch) | |
| tree | c292c2437a7afba8defef0da57019642e376ab28 /src/server/completion.odin | |
| parent | e2780708f9a590a62882d1316997dc2248b3e9b1 (diff) | |
Fix comp_lit error and start work on magic completion
Diffstat (limited to 'src/server/completion.odin')
| -rw-r--r-- | src/server/completion.odin | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/src/server/completion.odin b/src/server/completion.odin index f7ce075..8d6d93a 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -350,7 +350,7 @@ get_selector_completion :: proc(ast_context: ^analysis.AstContext, position_cont case index.SymbolUnionValue: list.isIncomplete = false - //append_magic_union_completion(position_context, selector, &items) + append_magic_union_completion(position_context, selector, &items) for type in v.types { if symbol, ok := resolve_type_expression(ast_context, type); ok { @@ -459,7 +459,7 @@ get_selector_completion :: proc(ast_context: ^analysis.AstContext, position_cont } case index.SymbolDynamicArrayValue: list.isIncomplete = false - //append_magic_dynamic_array_completion(position_context, selector, &items) + append_magic_dynamic_array_completion(position_context, selector, &items) } list.items = items[:] @@ -1233,13 +1233,24 @@ get_range_from_selection_start_to_dot :: proc(position_context: ^analysis.Docume } append_magic_dynamic_array_completion :: proc(position_context: ^analysis.DocumentPositionContext, symbol: index.Symbol, items: ^[dynamic]CompletionItem) { - 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 //len { @@ -1252,23 +1263,13 @@ append_magic_dynamic_array_completion :: proc(position_context: ^analysis.Docume textEdit = TextEdit { newText = text, range = { - start = range.start, + start = range.end, end = range.end, }, }, + additionalTextEdits = additionalTextEdits, } - log.error(item) - append(items, item) - } - //append - { - item := CompletionItem { - label = "append", - kind = .Function, - detail = "append", - insertText = fmt.tprintf("append(%v)$0", symbol.name), - } append(items, item) } @@ -1281,15 +1282,37 @@ append_magic_union_completion :: proc(position_context: ^analysis.DocumentPositi 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 + //switch { item := CompletionItem { label = "switch", kind = .Snippet, detail = "switch", - insertText = fmt.tprintf("len(%v)$0", symbol.name), + additionalTextEdits = additionalTextEdits, + textEdit = TextEdit { + newText = fmt.tprintf("switch v in %v {{\n\t$0 \n}}", symbol.name), + range = { + start = range.end, + end = range.end, + }, + }, insertTextFormat = .Snippet, + InsertTextMode = .adjustIndentation, } + append(items, item) } |