diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2023-11-11 14:02:32 +0100 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2023-11-11 14:02:32 +0100 |
| commit | 6bcf5f9cf49622e8f1bd488a1d2c3a357f834a32 (patch) | |
| tree | 30911d51c0269b5a647fe2e01f6303cddea97342 /src | |
| parent | b19c24eb17e7c16bcfb3144665fd405fd5e580f3 (diff) | |
Procedure types do no longer insert `()`
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/analysis.odin | 20 | ||||
| -rw-r--r-- | src/server/completion.odin | 40 | ||||
| -rw-r--r-- | src/server/methods.odin | 20 | ||||
| -rw-r--r-- | src/server/symbol.odin | 59 |
4 files changed, 90 insertions, 49 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 08512ba..d375911 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -997,7 +997,7 @@ resolve_function_overload :: proc( } if len(candidates) > 1 { - return Symbol{ + return Symbol { type = candidates[0].type, name = candidates[0].name, pkg = candidates[0].pkg, @@ -1210,6 +1210,7 @@ internal_resolve_type_expression :: proc( v^, ast_context.field_name, {}, + true, ), true case ^Basic_Directive: @@ -1488,7 +1489,7 @@ store_local :: proc( append( local_stack, - DocumentLocal{ + DocumentLocal { lhs = lhs, rhs = rhs, offset = offset, @@ -1695,6 +1696,7 @@ internal_resolve_type_identifier :: proc( v.type^, node, {}, + false, ), true } else { @@ -1709,6 +1711,7 @@ internal_resolve_type_identifier :: proc( v.type^, node, {}, + false, ), true } @@ -1801,6 +1804,7 @@ internal_resolve_type_identifier :: proc( v.type^, node, global.attributes, + false, ), true } else { @@ -1815,6 +1819,7 @@ internal_resolve_type_identifier :: proc( v.type^, node, global.attributes, + false, ), true } @@ -2771,10 +2776,11 @@ make_symbol_procedure_from_ast :: proc( v: ast.Proc_Type, name: ast.Ident, attributes: []^ast.Attribute, + type: bool, ) -> Symbol { symbol := Symbol { range = common.get_token_range(name, ast_context.file.src), - type = .Function, + type = .Function if !type else .Type_Function, pkg = get_package_from_node(n^), name = name.name, } @@ -4520,7 +4526,7 @@ get_signature :: proc( ) case SymbolBitSetValue: return strings.concatenate( - a = { + a = { pointer_prefix, "bit_set[", common.node_to_string(v.expr), @@ -4536,7 +4542,7 @@ get_signature :: proc( } case SymbolMapValue: return strings.concatenate( - a = { + a = { pointer_prefix, "map[", common.node_to_string(v.key), @@ -4582,7 +4588,7 @@ get_signature :: proc( ) case SymbolFixedArrayValue: return strings.concatenate( - a = { + a = { pointer_prefix, "[", common.node_to_string(v.len), @@ -4593,7 +4599,7 @@ get_signature :: proc( ) case SymbolMatrixValue: return strings.concatenate( - a = { + a = { pointer_prefix, "matrix", "[", diff --git a/src/server/completion.odin b/src/server/completion.odin index 26c014f..94789e2 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -179,7 +179,7 @@ get_directive_completion :: proc( Right now just return all the possible completions, but later on I should give the context specific ones */ - directive_list := []string{ + directive_list := []string { "file", "line", "packed", @@ -602,7 +602,9 @@ get_selector_completion :: proc( item := CompletionItem { label = symbol.name, - kind = cast(CompletionItemKind)symbol.type, + kind = symbol_type_to_completion_kind( + symbol.type, + ), detail = concatenate_symbol_information( ast_context, symbol, @@ -1135,7 +1137,7 @@ get_identifier_completion :: proc( if uri.path != ast_context.fullpath { append( &combined, - CombinedResult{ + CombinedResult { score = r.score, type = r.symbol.type, name = r.symbol.name, @@ -1182,7 +1184,7 @@ get_identifier_completion :: proc( if score, ok := common.fuzzy_match(matcher, ident.name); ok == 1 { append( &combined, - CombinedResult{ + CombinedResult { score = score * 1.1, type = symbol.type, name = ident.name, @@ -1229,7 +1231,7 @@ get_identifier_completion :: proc( ok == 1 { append( &combined, - CombinedResult{ + CombinedResult { score = score * 1.7, type = symbol.type, name = ident.name, @@ -1257,7 +1259,7 @@ get_identifier_completion :: proc( if score, ok := common.fuzzy_match(matcher, symbol.name); ok == 1 { append( &combined, - CombinedResult{ + CombinedResult { score = score * 1.1, type = symbol.type, name = symbol.name, @@ -1279,7 +1281,7 @@ get_identifier_completion :: proc( if score, ok := common.fuzzy_match(matcher, keyword); ok == 1 { append( &combined, - CombinedResult{ + CombinedResult { score = score, type = symbol.type, name = symbol.name, @@ -1301,7 +1303,7 @@ get_identifier_completion :: proc( if score, ok := common.fuzzy_match(matcher, keyword); ok == 1 { append( &combined, - CombinedResult{ + CombinedResult { score = score * 1.1, type = symbol.type, name = symbol.name, @@ -1372,7 +1374,7 @@ get_identifier_completion :: proc( documentation = result.doc, } - item.kind = cast(CompletionItemKind)result.type + item.kind = symbol_type_to_completion_kind(result.type) if result.type == .Function && common.config.enable_snippets { item.insertText = fmt.tprintf("%v($0)", item.label) @@ -1424,7 +1426,7 @@ get_package_completion :: proc( if colon_index + 1 < len(without_quotes) { absolute_path = filepath.join( - elems = { + elems = { common.config.collections[c], filepath.dir( without_quotes[colon_index + 1:], @@ -1590,14 +1592,14 @@ get_core_insert_package_if_non_existent :: proc( strings.write_string(&builder, fmt.tprintf("import \"core:%v\"", pkg)) - return { + return { newText = strings.to_string(builder), - range = { - start = { + range = { + start = { line = ast_context.file.pkg_decl.end.line + 1, character = 0, }, - end = { + end = { line = ast_context.file.pkg_decl.end.line + 1, character = 0, }, @@ -1655,7 +1657,7 @@ append_magic_map_completion :: proc( kind = .Snippet, detail = "for", additionalTextEdits = additionalTextEdits, - textEdit = TextEdit{ + textEdit = TextEdit { newText = fmt.tprintf( "for ${{1:k}}, ${{2:v}} in %v {{\n\t$0 \n}}", symbol.name, @@ -1702,7 +1704,7 @@ append_magic_dynamic_array_completion :: proc( label = "len", kind = .Function, detail = "len", - textEdit = TextEdit{ + textEdit = TextEdit { newText = text, range = {start = range.end, end = range.end}, }, @@ -1719,7 +1721,7 @@ append_magic_dynamic_array_completion :: proc( kind = .Snippet, detail = "for", additionalTextEdits = additionalTextEdits, - textEdit = TextEdit{ + textEdit = TextEdit { newText = fmt.tprintf( "for i in %v {{\n\t$0 \n}}", symbol.name, @@ -1766,7 +1768,7 @@ append_magic_union_completion :: proc( kind = .Snippet, detail = "switch", additionalTextEdits = additionalTextEdits, - textEdit = TextEdit{ + textEdit = TextEdit { newText = fmt.tprintf( "switch v in %v {{\n\t$0 \n}}", symbol.name, @@ -1882,7 +1884,7 @@ is_bitset_assignment_operator :: proc(op: string) -> bool { return op in bitset_assignment_operators } -language_keywords: []string = { +language_keywords: []string = { "align_of", "case", "defer", diff --git a/src/server/methods.odin b/src/server/methods.odin index 60e7cd8..4d1d3f2 100644 --- a/src/server/methods.odin +++ b/src/server/methods.odin @@ -1,18 +1,18 @@ package server -import "core:odin/parser" -import "core:odin/ast" -import "core:odin/tokenizer" import "core:fmt" import "core:log" -import "core:strings" -import path "core:path/slashpath" import "core:mem" -import "core:strconv" +import "core:odin/ast" +import "core:odin/parser" +import "core:odin/tokenizer" +import "core:os" import "core:path/filepath" -import "core:sort" +import path "core:path/slashpath" import "core:slice" -import "core:os" +import "core:sort" +import "core:strconv" +import "core:strings" import "shared:common" @@ -118,14 +118,14 @@ append_method_completion :: proc( item := CompletionItem { label = symbol.name, - kind = cast(CompletionItemKind)symbol.type, + kind = symbol_type_to_completion_kind(symbol.type), detail = concatenate_symbol_information( ast_context, symbol, true, ), additionalTextEdits = remove_edit, - textEdit = TextEdit{ + textEdit = TextEdit { newText = new_text, range = {start = range.end, end = range.end}, }, diff --git a/src/server/symbol.odin b/src/server/symbol.odin index 3a1a3ad..d6a6aa5 100644 --- a/src/server/symbol.odin +++ b/src/server/symbol.odin @@ -1,12 +1,12 @@ package server -import "core:odin/ast" import "core:hash" -import "core:strings" import "core:mem" +import "core:odin/ast" import "core:path/filepath" import path "core:path/slashpath" import "core:slice" +import "core:strings" import "shared:common" @@ -151,17 +151,18 @@ Symbol :: struct { } SymbolType :: enum { - Function = 3, - Field = 5, - Variable = 6, - Package = 9, - Enum = 13, - Keyword = 14, - EnumMember = 20, - Constant = 21, - Struct = 22, - Union = 7, - Unresolved = 1, //Use text if not being able to resolve it. + Function = 3, + Field = 5, + Variable = 6, + Package = 9, + Enum = 13, + Keyword = 14, + EnumMember = 20, + Constant = 21, + Struct = 22, + Type_Function = 23, + Union = 7, + Unresolved = 1, //Use text if not being able to resolve it. } new_clone_symbol :: proc( @@ -230,6 +231,38 @@ free_symbol :: proc(symbol: Symbol, allocator: mem.Allocator) { } } +symbol_type_to_completion_kind :: proc( + type: SymbolType, +) -> CompletionItemKind { + switch type { + case .Function: + return .Function + case .Field: + return .Field + case .Variable: + return .Variable + case .Package: + return .Module + case .Enum: + return .Enum + case .Keyword: + return .Keyword + case .EnumMember: + return .EnumMember + case .Constant: + return .Constant + case .Struct: + return .Struct + case .Type_Function: + return .Function + case .Union: + return .Enum + case .Unresolved: + return .Text + case: + return .Text + } +} symbol_kind_to_type :: proc(type: SymbolType) -> SymbolKind { #partial switch type { |