aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-07-06 20:40:09 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-07-06 20:48:25 -0400
commitd4b195cf6dba5894f9597c935106d190860d9de8 (patch)
tree4f69af08839cb2cd4dd54f15e4432fa83188011d /src/server
parent695707577521c7246e851e0acfdfe3b9e51fc097 (diff)
Improvements for references and renaming of struct pointer fields
Diffstat (limited to 'src/server')
-rw-r--r--src/server/references.odin25
-rw-r--r--src/server/rename.odin40
2 files changed, 33 insertions, 32 deletions
diff --git a/src/server/references.odin b/src/server/references.odin
index ed3af4d..f107759 100644
--- a/src/server/references.odin
+++ b/src/server/references.odin
@@ -65,25 +65,14 @@ prepare_references :: proc(
}
}
if position_in_node(field.type, position_context.position) {
- if ident, ok := field.type.derived.(^ast.Ident); ok {
- symbol, ok = resolve_location_identifier(ast_context, ident^)
- if !ok {
- return
- }
-
- found = true
- resolve_flag = .Identifier
- break done_struct
- } else if selector, ok := field.type.derived.(^ast.Selector_Expr); ok {
- symbol, ok = resolve_location_identifier(ast_context, ident^)
- if !ok {
- return
- }
-
- found = true
- resolve_flag = .Identifier
- break done_struct
+ symbol, ok = resolve_location_type_expression(ast_context, field.type)
+ if !ok {
+ return
}
+
+ found = true
+ resolve_flag = .Identifier
+ break done_struct
}
}
if !found {
diff --git a/src/server/rename.odin b/src/server/rename.odin
index 30c8296..d97df2b 100644
--- a/src/server/rename.odin
+++ b/src/server/rename.odin
@@ -93,6 +93,26 @@ get_prepare_rename :: proc(document: ^Document, position: common.Position) -> (c
return symbol.range, ok2
}
+get_struct_field_type_position :: proc(
+ ast_context: ^AstContext, position_context: ^DocumentPositionContext, node: ^ast.Expr
+) -> (Symbol, bool) {
+ #partial switch v in node.derived {
+ case ^ast.Ident:
+ symbol := Symbol {
+ range = common.get_token_range(node, ast_context.file.src),
+ }
+ return symbol, true
+ case ^ast.Selector_Expr:
+ symbol := Symbol {
+ range = common.get_token_range(v.field, ast_context.file.src),
+ }
+ return symbol, true
+ case ^ast.Pointer_Type:
+ return get_struct_field_type_position(ast_context, position_context, v.elem)
+ }
+ return {}, false
+}
+
// For preparing the rename, we want to position of the token within the current file,
// not the position of the declaration
prepare_rename :: proc(
@@ -119,21 +139,13 @@ prepare_rename :: proc(
}
}
if position_in_node(field.type, position_context.position) {
- if ident, ok := field.type.derived.(^ast.Ident); ok {
- symbol = Symbol {
- range = common.get_token_range(field.type, ast_context.file.src),
- }
-
- found = true
- break done_struct
- } else if selector, ok := field.type.derived.(^ast.Selector_Expr); ok {
- symbol = Symbol {
- range = common.get_token_range(selector.field, ast_context.file.src),
- }
-
- found = true
- break done_struct
+ symbol, ok = get_struct_field_type_position(ast_context, position_context, field.type)
+ if !ok {
+ return
}
+
+ found = true
+ break done_struct
}
}
if !found {