From ee32288b28a939bd500143589800217f844031cb Mon Sep 17 00:00:00 2001 From: Brad Lewis <22850972+BradLewis@users.noreply.github.com> Date: Thu, 12 Feb 2026 15:11:10 +1100 Subject: Resolve decls in when statements to fix incorrectly flagging imports as unused --- src/server/file_resolve.odin | 8 -------- tests/actions_test.odin | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 tests/actions_test.odin diff --git a/src/server/file_resolve.odin b/src/server/file_resolve.odin index f381aac..c4b2467 100644 --- a/src/server/file_resolve.odin +++ b/src/server/file_resolve.odin @@ -51,10 +51,6 @@ resolve_ranged_file :: proc( margin := 20 for decl in document.ast.decls { - if _, is_value := decl.derived.(^ast.Value_Decl); !is_value { - continue - } - //Look for declarations that overlap with range if range.start.line - margin <= decl.end.line && decl.pos.line <= range.end.line + margin { resolve_decl(&position_context, &ast_context, document, decl, &symbols, .None, allocator) @@ -88,10 +84,6 @@ resolve_entire_file :: proc( symbols := make(map[uintptr]SymbolAndNode, 10000, allocator) for decl in document.ast.decls { - if _, is_value := decl.derived.(^ast.Value_Decl); !is_value { - continue - } - resolve_decl(&position_context, &ast_context, document, decl, &symbols, flag, allocator) clear(&ast_context.locals) } diff --git a/tests/actions_test.odin b/tests/actions_test.odin new file mode 100644 index 0000000..935e168 --- /dev/null +++ b/tests/actions_test.odin @@ -0,0 +1,23 @@ +package tests + +import "core:testing" + +import test "src:testing" + +@(test) +action_remove_unsed_import_when_stmt :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + import "core:fm{*}t" + + when true { + main :: proc() { + _ = fmt.printf + } + } + `, + packages = {}, + } + + test.expect_action(t, &source, {}) +} -- cgit v1.2.3