aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-08-31 13:43:00 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-08-31 13:43:00 -0400
commit37c4ec0b95cdfac3000ddd3fb95b0466b3dbc0b7 (patch)
tree85be48bc2313b9f9df4a7c2fb132e5b9ee10ac07
parent50a3fd1799c23074452802dcd51fef5c4e03d525 (diff)
Construct current package from the current file when searching index
-rw-r--r--src/server/analysis.odin36
-rw-r--r--src/server/completion.odin9
-rw-r--r--src/server/indexer.odin15
-rw-r--r--src/server/memory_index.odin2
-rw-r--r--src/server/workspace_symbols.odin2
5 files changed, 28 insertions, 36 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin
index 06e593a..9672824 100644
--- a/src/server/analysis.odin
+++ b/src/server/analysis.odin
@@ -1404,10 +1404,7 @@ resolve_selector_expression :: proc(ast_context: ^AstContext, node: ^ast.Selecto
try_build_package(ast_context.current_package)
if node.field != nil {
- return resolve_symbol_return(
- ast_context,
- lookup(node.field.name, selector.pkg, ast_context.current_package, node.pos.file),
- )
+ return resolve_symbol_return(ast_context, lookup(node.field.name, selector.pkg, node.pos.file))
} else {
return Symbol{}, false
}
@@ -1544,7 +1541,7 @@ internal_resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ide
switch node.name {
case "context":
for built in indexer.builtin_packages {
- if symbol, ok := lookup("Context", built, "", ""); ok {
+ if symbol, ok := lookup("Context", built, ""); ok {
symbol.type = .Variable
return symbol, ok
}
@@ -1568,24 +1565,24 @@ internal_resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ide
is_runtime := strings.contains(ast_context.current_package, "base/runtime")
if is_runtime {
- if symbol, ok := lookup(node.name, "$builtin", ast_context.current_package, node.pos.file); ok {
+ if symbol, ok := lookup(node.name, "$builtin", node.pos.file); ok {
return resolve_symbol_return(ast_context, symbol)
}
}
//last option is to check the index
- if symbol, ok := lookup(node.name, ast_context.current_package, ast_context.current_package, node.pos.file); ok {
+ if symbol, ok := lookup(node.name, ast_context.current_package, node.pos.file); ok {
return resolve_symbol_return(ast_context, symbol)
}
if !is_runtime {
- if symbol, ok := lookup(node.name, "$builtin", ast_context.current_package, node.pos.file); ok {
+ if symbol, ok := lookup(node.name, "$builtin", node.pos.file); ok {
return resolve_symbol_return(ast_context, symbol)
}
}
for built in indexer.builtin_packages {
- if symbol, ok := lookup(node.name, built, ast_context.current_package, node.pos.file); ok {
+ if symbol, ok := lookup(node.name, built, node.pos.file); ok {
return resolve_symbol_return(ast_context, symbol)
}
}
@@ -1593,7 +1590,7 @@ internal_resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ide
for u in ast_context.usings {
for imp in ast_context.imports {
if strings.compare(imp.name, u.pkg_name) == 0 {
- if symbol, ok := lookup(node.name, imp.name, ast_context.current_package, node.pos.file); ok {
+ if symbol, ok := lookup(node.name, imp.name, node.pos.file); ok {
return resolve_symbol_return(ast_context, symbol)
}
}
@@ -2427,19 +2424,19 @@ resolve_location_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -
return symbol, true
}
- if symbol, ok := lookup(node.name, ast_context.document_package, ast_context.current_package, node.pos.file); ok {
+ if symbol, ok := lookup(node.name, ast_context.document_package, node.pos.file); ok {
return symbol, ok
}
usings := get_using_packages(ast_context)
for pkg in usings {
- if symbol, ok := lookup(node.name, pkg, ast_context.current_package, node.pos.file); ok {
+ if symbol, ok := lookup(node.name, pkg, node.pos.file); ok {
return symbol, ok
}
}
- if symbol, ok := lookup(node.name, "$builtin", ast_context.current_package, node.pos.file); ok {
+ if symbol, ok := lookup(node.name, "$builtin", node.pos.file); ok {
return resolve_symbol_return(ast_context, symbol)
}
@@ -2608,7 +2605,7 @@ resolve_location_implicit_selector :: proc(
resolve_container_allocator :: proc(ast_context: ^AstContext, container_name: string) -> (Symbol, bool) {
for built in indexer.builtin_packages {
- if symbol, ok := lookup(container_name, built, ast_context.current_package, ast_context.fullpath); ok {
+ if symbol, ok := lookup(container_name, built, ast_context.fullpath); ok {
if v, ok := symbol.value.(SymbolStructValue); ok {
for name, i in v.names {
if name == "allocator" {
@@ -2628,7 +2625,7 @@ resolve_container_allocator :: proc(ast_context: ^AstContext, container_name: st
resolve_container_allocator_location :: proc(ast_context: ^AstContext, container_name: string) -> (Symbol, bool) {
for built in indexer.builtin_packages {
- if symbol, ok := lookup(container_name, built, ast_context.current_package, ast_context.fullpath); ok {
+ if symbol, ok := lookup(container_name, built, ast_context.fullpath); ok {
if v, ok := symbol.value.(SymbolStructValue); ok {
for name, i in v.names {
if name == "allocator" {
@@ -2694,8 +2691,7 @@ resolve_symbol_selector :: proc(
}
}
case SymbolPackageValue:
- if pkg, ok := lookup(field, symbol.pkg, ast_context.current_package, symbol.uri);
- ok {
+ if pkg, ok := lookup(field, symbol.pkg, symbol.uri); ok {
symbol.range = pkg.range
symbol.uri = pkg.uri
} else {
@@ -2933,7 +2929,11 @@ make_int_basic_value :: proc(
}
get_package_from_node :: proc(node: ast.Node) -> string {
- slashed, _ := filepath.to_slash(node.pos.file, context.temp_allocator)
+ return get_package_from_filepath(node.pos.file)
+}
+
+get_package_from_filepath :: proc(file_path: string) -> string {
+ slashed, _ := filepath.to_slash(file_path, context.temp_allocator)
ret := path.dir(slashed, context.temp_allocator)
return ret
}
diff --git a/src/server/completion.odin b/src/server/completion.odin
index 33b30d6..29ae7bb 100644
--- a/src/server/completion.odin
+++ b/src/server/completion.odin
@@ -1035,9 +1035,8 @@ get_selector_completion :: proc(
is_incomplete = true
pkg := selector.pkg
- current_pkg := ast_context.current_package
- if searched, ok := fuzzy_search(field, {pkg}, current_pkg, ast_context.fullpath); ok {
+ if searched, ok := fuzzy_search(field, {pkg}, ast_context.fullpath); ok {
for search in searched {
symbol := search.symbol
@@ -1568,7 +1567,7 @@ get_identifier_completion :: proc(
append(&pkgs, ast_context.document_package)
append(&pkgs, "$builtin")
- if fuzzy_results, ok := fuzzy_search(lookup_name, pkgs[:], ast_context.current_package, ast_context.fullpath); ok {
+ if fuzzy_results, ok := fuzzy_search(lookup_name, pkgs[:], ast_context.fullpath); ok {
for r in fuzzy_results {
r := r
resolve_unresolved_symbol(ast_context, &r.symbol)
@@ -1683,8 +1682,8 @@ get_identifier_completion :: proc(
for keyword, docs in keywords_docs {
item := CompletionItem {
- label = keyword,
- kind = .Keyword,
+ label = keyword,
+ kind = .Keyword,
documentation = docs,
}
diff --git a/src/server/indexer.odin b/src/server/indexer.odin
index d4ec5a4..1afa1e8 100644
--- a/src/server/indexer.odin
+++ b/src/server/indexer.odin
@@ -47,20 +47,13 @@ should_skip_private_symbol :: proc(symbol: Symbol, current_pkg, current_file: st
return false
}
-lookup :: proc(
- name: string,
- pkg: string,
- current_pkg, current_file: string,
- loc := #caller_location,
-) -> (
- Symbol,
- bool,
-) {
+lookup :: proc(name: string, pkg: string, current_file: string, loc := #caller_location) -> (Symbol, bool) {
if name == "" {
return {}, false
}
if symbol, ok := memory_index_lookup(&indexer.index, name, pkg); ok {
+ current_pkg := get_package_from_filepath(current_file)
if should_skip_private_symbol(symbol, current_pkg, current_file) {
return {}, false
}
@@ -73,13 +66,13 @@ lookup :: proc(
fuzzy_search :: proc(
name: string,
pkgs: []string,
- current_pkg, current_file: string,
+ current_file: string,
resolve_fields := false,
) -> (
[]FuzzyResult,
bool,
) {
- results, ok := memory_index_fuzzy_search(&indexer.index, name, pkgs, current_pkg, current_file, resolve_fields)
+ results, ok := memory_index_fuzzy_search(&indexer.index, name, pkgs, current_file, resolve_fields)
result := make([dynamic]FuzzyResult, context.temp_allocator)
if !ok {
diff --git a/src/server/memory_index.odin b/src/server/memory_index.odin
index bb4d13c..ad5fedc 100644
--- a/src/server/memory_index.odin
+++ b/src/server/memory_index.odin
@@ -44,7 +44,6 @@ memory_index_fuzzy_search :: proc(
index: ^MemoryIndex,
name: string,
pkgs: []string,
- current_pkg: string,
current_file: string,
resolve_fields := false,
) -> (
@@ -56,6 +55,7 @@ memory_index_fuzzy_search :: proc(
fuzzy_matcher := common.make_fuzzy_matcher(name)
top := 100
+ current_pkg := get_package_from_filepath(current_file)
for pkg in pkgs {
if pkg, ok := index.collection.packages[pkg]; ok {
diff --git a/src/server/workspace_symbols.odin b/src/server/workspace_symbols.odin
index 8ddbd64..a45fba5 100644
--- a/src/server/workspace_symbols.odin
+++ b/src/server/workspace_symbols.odin
@@ -65,7 +65,7 @@ get_workspace_symbols :: proc(query: string) -> (workspace_symbols: []WorkspaceS
try_build_package(pkg)
- if results, ok := fuzzy_search(query, {pkg}, "", "", resolve_fields = true); ok {
+ if results, ok := fuzzy_search(query, {pkg}, "", resolve_fields = true); ok {
for result in results {
symbol := WorkspaceSymbol {
name = result.symbol.name,