diff options
| -rw-r--r-- | src/common/ast.odin | 3 | ||||
| -rw-r--r-- | src/server/analysis.odin | 9 | ||||
| -rw-r--r-- | src/server/collector.odin | 9 | ||||
| -rw-r--r-- | tests/completions_test.odin | 18 |
4 files changed, 35 insertions, 4 deletions
diff --git a/src/common/ast.odin b/src/common/ast.odin index 44bd643..2a7a027 100644 --- a/src/common/ast.odin +++ b/src/common/ast.odin @@ -8,6 +8,7 @@ import "core:strings" import path "core:path/slashpath" keyword_map: map[string]bool = { + "typeid" = true, "int" = true, "uint" = true, "string" = true, @@ -938,7 +939,7 @@ build_string_node :: proc( } } case ^Typeid_Type: - strings.write_string(builder, "$") + strings.write_string(builder, "typeid") build_string(n.specialization, builder, remove_pointers) case ^Helper_Type: build_string(n.type, builder, remove_pointers) diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 42e02cd..7050471 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1093,6 +1093,10 @@ internal_resolve_type_expression :: proc( using ast #partial switch v in node.derived { + case ^ast.Typeid_Type: + ident := new_type(ast.Ident, v.pos, v.end, context.temp_allocator) + ident.name = "typeid" + return make_symbol_basic_type_from_ast(ast_context, ident), true case ^ast.Value_Decl: if v.type != nil { return internal_resolve_type_expression(ast_context, v.type) @@ -2364,8 +2368,7 @@ make_symbol_map_from_ast :: proc( make_symbol_basic_type_from_ast :: proc( ast_context: ^AstContext, - n: ^ast.Node, - v: ^ast.Ident, + n: ^ast.Ident, ) -> Symbol { symbol := Symbol { range = common.get_token_range(n^, ast_context.file.src), @@ -2374,7 +2377,7 @@ make_symbol_basic_type_from_ast :: proc( } symbol.value = SymbolBasicValue { - ident = v, + ident = n, } return symbol diff --git a/src/server/collector.odin b/src/server/collector.odin index 913d66f..9a7d050 100644 --- a/src/server/collector.odin +++ b/src/server/collector.odin @@ -492,6 +492,15 @@ collect_symbols :: proc( token = v^ token_type = .Variable symbol.value = collect_multi_pointer(collection, v^, package_map) + case ^ast.Typeid_Type: + if v.specialization == nil { + continue + } + + ident := new_type(ast.Ident, v.pos, v.end, context.temp_allocator) + ident.name = "typeid" + + symbol.value = collect_generic(collection, ident, package_map, uri) case ^ast.Basic_Lit: token = v^ symbol.value = collect_generic( diff --git a/tests/completions_test.odin b/tests/completions_test.odin index 77e1913..46364ff 100644 --- a/tests/completions_test.odin +++ b/tests/completions_test.odin @@ -1929,3 +1929,21 @@ ast_union_with_type_from_different_package :: proc(t: ^testing.T) { test.expect_completion_labels(t, &source, ".", {"(my_package.My_Int)"}) } + +@(test) +ast_completion_union_with_typeid :: proc(t: ^testing.T) { + source := test.Source { + main = `package main + import "my_package" + + Maybe :: union($T: typeid) {T} + + main :: proc() { + my_maybe: Maybe(typeid) + my_maybe.* + } + `, + } + + test.expect_completion_labels(t, &source, ".", {"(typeid)"}) +} |