From 12a1db1e284e4ce2af9a51bb60f9817e76c1a481 Mon Sep 17 00:00:00 2001 From: Daniel Gavin Date: Sun, 12 Jun 2022 01:24:58 +0200 Subject: Fix bugs with range loop in switch statement not completing. --- src/server/analysis.odin | 8 ++++---- src/server/completion.odin | 3 --- src/server/semantic_tokens.odin | 2 +- tests/completions_test.odin | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/server/analysis.odin b/src/server/analysis.odin index bd700fe..09564ba 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -2347,10 +2347,6 @@ get_locals_type_switch_stmt :: proc(file: ast.File, stmt: ast.Type_Switch_Stmt, if block, ok := stmt.body.derived.(^Block_Stmt); ok { for block_stmt in block.stmts { if cause, ok := block_stmt.derived.(^Case_Clause); ok && cause.pos.offset <= document_position.position && document_position.position <= cause.end.offset { - for b in cause.body { - get_locals_stmt(file, b, ast_context, document_position) - } - tag := stmt.tag.derived.(^Assign_Stmt) if len(tag.lhs) == 1 && len(cause.list) == 1 { @@ -2358,6 +2354,10 @@ get_locals_type_switch_stmt :: proc(file: ast.File, stmt: ast.Type_Switch_Stmt, store_local(ast_context, cause.list[0], ident.pos.offset, ident.name, ast_context.local_id) ast_context.variables[ident.name] = true } + + for b in cause.body { + get_locals_stmt(file, b, ast_context, document_position) + } } } } diff --git a/src/server/completion.odin b/src/server/completion.odin index f42fbb3..c8d9d11 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -290,7 +290,6 @@ get_selector_completion :: proc(ast_context: ^AstContext, position_context: ^Doc expr_len = save for k in swizzle_coord_components { - if expr_len <= 0 { break } @@ -308,7 +307,6 @@ get_selector_completion :: proc(ast_context: ^AstContext, position_context: ^Doc if containsColor > 1 { for k in swizzle_color_components { - if expr_len <= 0 { break } @@ -324,7 +322,6 @@ get_selector_completion :: proc(ast_context: ^AstContext, position_context: ^Doc } } else if containsCoord > 1 { for k in swizzle_coord_components { - if expr_len <= 0 { break } diff --git a/src/server/semantic_tokens.odin b/src/server/semantic_tokens.odin index 321858e..55d94d3 100644 --- a/src/server/semantic_tokens.odin +++ b/src/server/semantic_tokens.odin @@ -513,7 +513,7 @@ visit_selector :: proc(selector: ^ast.Selector_Expr, builder: ^SemanticTokenBuil if symbol_and_node, ok := builder.symbols[cast(uintptr)selector]; ok { if symbol_and_node.symbol.type == .Variable { - write_semantic_node(builder, selector.field, ast_context.file.src, .Method, .None) + write_semantic_node(builder, selector.field, ast_context.file.src, .Property, .None) } #partial switch v in symbol_and_node.symbol.value { case SymbolPackageValue: diff --git a/tests/completions_test.odin b/tests/completions_test.odin index 6763bed..f9e93da 100644 --- a/tests/completions_test.odin +++ b/tests/completions_test.odin @@ -1642,3 +1642,36 @@ ast_for_in_range_half_completion_2 :: proc(t: ^testing.T) { test.expect_completion_details(t, &source, ".", {"test.n: int"}) } + +@(test) +ast_for_in_switch_type :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + My_Foo :: struct { + bar: int, + } + + My_Struct :: struct { + my: []My_Foo, + } + + My_Union :: union { + My_Struct, + } + + main :: proc() { + my_union: My_Union + switch v in my_union { + case My_Struct: + for item in v.my { + item.* + } + } + } + `, + packages = {}, + } + + test.expect_completion_details(t, &source, ".", {"My_Foo.bar: int"}) +} + -- cgit v1.2.3