aboutsummaryrefslogtreecommitdiff
path: root/src/server/references.odin
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2024-06-13 19:58:44 +0200
committerDanielGavin <danielgavin5@hotmail.com>2024-06-13 19:58:44 +0200
commit582a1b1c1b42065d3bd22bd0f23bfd3ec38cdae4 (patch)
treeedc281df609d163d11d933d2f824035b144ef088 /src/server/references.odin
parent3c05ab67cd6b811a0993e49f2ca1ed75e0aca8e3 (diff)
add prepare rename
Diffstat (limited to 'src/server/references.odin')
-rw-r--r--src/server/references.odin80
1 files changed, 50 insertions, 30 deletions
diff --git a/src/server/references.odin b/src/server/references.odin
index d56ae62..17add83 100644
--- a/src/server/references.odin
+++ b/src/server/references.odin
@@ -51,35 +51,21 @@ walk_directories :: proc(
return 0, false
}
-resolve_references :: proc(
+prepare_references :: proc(
document: ^Document,
ast_context: ^AstContext,
position_context: ^DocumentPositionContext,
) -> (
- []common.Location,
- bool,
+ symbol: Symbol,
+ resolve_flag: ResolveReferenceFlag,
+ ok: bool,
) {
- locations := make([dynamic]common.Location, 0, ast_context.allocator)
- fullpaths = make([dynamic]string, 0, ast_context.allocator)
-
- resolve_flag: ResolveReferenceFlag
+ ok = false
reference := ""
- symbol: Symbol
- ok: bool
pkg := ""
- when !ODIN_TEST {
- for workspace in common.config.workspace_folders {
- uri, _ := common.parse_uri(workspace.uri, context.temp_allocator)
- filepath.walk(uri.path, walk_directories, document)
- }
- }
-
- reset_ast_context(ast_context)
-
-
if position_context.label != nil {
- return {}, true
+ return
} else if position_context.struct_type != nil {
found := false
done_struct: for field in position_context.struct_type.fields.list {
@@ -98,7 +84,7 @@ resolve_references :: proc(
}
}
if !found {
- return {}, false
+ return
}
} else if position_context.enum_type != nil {
/*
@@ -123,7 +109,7 @@ resolve_references :: proc(
}
*/
} else if position_context.bitset_type != nil {
- return {}, true
+ return
} else if position_context.union_type != nil {
found := false
for variant in position_context.union_type.variants {
@@ -137,19 +123,19 @@ resolve_references :: proc(
resolve_flag = .Identifier
if !ok {
- return {}, false
+ return
}
found = true
break
} else {
- return {}, false
+ return
}
}
}
if !found {
- return {}, false
+ return
}
} else if position_context.field_value != nil &&
@@ -165,12 +151,12 @@ resolve_references :: proc(
)
if !ok {
- return {}, false
+ return
}
//Only support structs for now
if _, ok := symbol.value.(SymbolStructValue); !ok {
- return {}, false
+ return
}
resolve_flag = .Field
@@ -189,7 +175,7 @@ resolve_references :: proc(
symbol, ok = resolve_location_identifier(ast_context, ident^)
if !ok {
- return {}, true
+ return
}
resolve_flag = .Base
@@ -211,7 +197,7 @@ resolve_references :: proc(
)
if !ok {
- return {}, true
+ return
}
} else if position_context.identifier != nil {
ident := position_context.identifier.derived.(^ast.Ident)
@@ -222,12 +208,46 @@ resolve_references :: proc(
resolve_flag = .Identifier
if !ok {
- return {}, true
+ return
}
} else {
+ return
+ }
+
+ return symbol, resolve_flag, true
+}
+
+resolve_references :: proc(
+ document: ^Document,
+ ast_context: ^AstContext,
+ position_context: ^DocumentPositionContext,
+) -> (
+ []common.Location,
+ bool,
+) {
+ locations := make([dynamic]common.Location, 0, ast_context.allocator)
+ fullpaths = make([dynamic]string, 0, ast_context.allocator)
+
+ symbol, resolve_flag, ok := prepare_references(
+ document,
+ ast_context,
+ position_context,
+ )
+
+ if !ok {
return {}, true
}
+ when !ODIN_TEST {
+ for workspace in common.config.workspace_folders {
+ uri, _ := common.parse_uri(workspace.uri, context.temp_allocator)
+ filepath.walk(uri.path, walk_directories, document)
+ }
+ }
+
+ reset_ast_context(ast_context)
+
+
arena: runtime.Arena
_ = runtime.arena_init(