diff options
| author | Bradley Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-08-12 20:19:25 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-12 20:19:25 -0400 |
| commit | d464ae4f65d41fa9abbac656cbfa804af3662162 (patch) | |
| tree | 8d8097db47c4cea316e411a1a943640218466c99 | |
| parent | 5f1f9c190eca31d78280a9d17cc0dd973d5983c9 (diff) | |
| parent | 2f08ec6e76d1825825cd6a5b9292b760782e00b4 (diff) | |
Merge pull request #870 from BradLewis/fix/type-definition-comp-lit
Fix go to type definition on a variable in a comp lit
| -rw-r--r-- | src/server/type_definition.odin | 14 | ||||
| -rw-r--r-- | tests/type_definition_test.odin | 27 |
2 files changed, 34 insertions, 7 deletions
diff --git a/src/server/type_definition.odin b/src/server/type_definition.odin index db0b587..7ad9c26 100644 --- a/src/server/type_definition.odin +++ b/src/server/type_definition.odin @@ -103,13 +103,6 @@ get_type_definition_locations :: proc(document: ^Document, position: common.Posi } } - if position_context.comp_lit != nil { - if symbol, ok := resolve_location_comp_literal(&ast_context, &position_context); ok { - append_symbol_to_locations(&locations, document, symbol) - return locations[:], true - } - } - if position_context.call != nil { if call, ok := position_context.call.derived.(^ast.Call_Expr); ok { if !position_in_exprs(call.args, position_context.position) { @@ -258,5 +251,12 @@ get_type_definition_locations :: proc(document: ^Document, position: common.Posi } } + if position_context.comp_lit != nil { + if symbol, ok := resolve_location_comp_literal(&ast_context, &position_context); ok { + append_symbol_to_locations(&locations, document, symbol) + return locations[:], true + } + } + return {}, false } diff --git a/tests/type_definition_test.odin b/tests/type_definition_test.odin index c08df88..3e818bf 100644 --- a/tests/type_definition_test.odin +++ b/tests/type_definition_test.odin @@ -983,3 +983,30 @@ ast_type_definition_comp_lit_variable :: proc (t: ^testing.T) { test.expect_type_definition_locations(t, &source, locations[:]) } + +@(test) +ast_type_definition_variable_in_comp_lit :: proc (t: ^testing.T) { + source := test.Source { + main = `package test + + Foo :: struct{} + + Bar :: struct { + foo: Foo, + } + + main :: proc() { + foo := Foo{} + bar := Bar { + foo = fo{*}o, + } + } + `, + } + + locations := []common.Location { + {range = {start = {line = 2, character = 2}, end = {line = 2, character = 5}}}, + } + + test.expect_type_definition_locations(t, &source, locations[:]) +} |