aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-06-09 08:10:48 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-06-09 10:14:13 -0400
commitc4dfd07a0537041556d7c074ebea60987ffc3d2b (patch)
tree9ecee74df9a13751fc7ba382ac8d79da017030b0
parenta42400e0c9f1471ec27454476f6fe6c19dc95242 (diff)
Fix goto definition taking you to the field definition instead of the variable declaration when used with a selector expr
-rw-r--r--src/server/definition.odin27
-rw-r--r--tests/definition_test.odin54
2 files changed, 66 insertions, 15 deletions
diff --git a/src/server/definition.odin b/src/server/definition.odin
index 0a216cc..00a62fc 100644
--- a/src/server/definition.odin
+++ b/src/server/definition.odin
@@ -76,25 +76,22 @@ get_definition_location :: proc(document: ^Document, position: common.Position)
}
} else if position_context.selector_expr != nil {
//if the base selector is the client wants to go to.
- if base, ok := position_context.selector.derived.(^ast.Ident); ok && position_context.identifier != nil {
+ if position_in_node(position_context.selector, position_context.position) && position_context.identifier != nil {
ident := position_context.identifier.derived.(^ast.Ident)
+ if resolved, ok := resolve_location_identifier(&ast_context, ident^); ok {
+ location.range = resolved.range
- if position_in_node(base, position_context.position) {
- if resolved, ok := resolve_location_identifier(&ast_context, ident^); ok {
- location.range = resolved.range
-
- if resolved.uri == "" {
- location.uri = document.uri.uri
- } else {
- location.uri = resolved.uri
- }
-
- append(&locations, location)
-
- return locations[:], true
+ if resolved.uri == "" {
+ location.uri = document.uri.uri
} else {
- return {}, false
+ location.uri = resolved.uri
}
+
+ append(&locations, location)
+
+ return locations[:], true
+ } else {
+ return {}, false
}
}
diff --git a/tests/definition_test.odin b/tests/definition_test.odin
index ced4256..8718f3a 100644
--- a/tests/definition_test.odin
+++ b/tests/definition_test.odin
@@ -392,3 +392,57 @@ ast_goto_implicit_enum_infer_from_assignment_within_switch :: proc(t: ^testing.T
test.expect_definition_locations(t, &source, {location})
}
+
+@(test)
+ast_goto_variable_declaration_with_selector_expr :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+
+ Bar :: struct {
+ foo: int,
+ }
+
+ main :: proc() {
+ bar: [1]Bar
+ b{*}ar[0].foo = 5
+ }
+ `,
+ packages = {},
+ }
+
+ location := common.Location {
+ range = {
+ start = {line = 7, character = 3},
+ end = {line = 7, character = 6},
+ },
+ }
+
+ test.expect_definition_locations(t, &source, {location})
+}
+
+@(test)
+ast_goto_variable_field_definition_with_selector_expr :: proc(t: ^testing.T) {
+ source := test.Source {
+ main = `package test
+
+ Bar :: struct {
+ foo: int,
+ }
+
+ main :: proc() {
+ bar: [1]Bar
+ bar[0].fo{*}o = 5
+ }
+ `,
+ packages = {},
+ }
+
+ location := common.Location {
+ range = {
+ start = {line = 3, character = 3},
+ end = {line = 3, character = 6},
+ },
+ }
+
+ test.expect_definition_locations(t, &source, {location})
+}