diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-08-31 13:04:55 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-08-31 13:04:55 -0400 |
| commit | 50a3fd1799c23074452802dcd51fef5c4e03d525 (patch) | |
| tree | a448af819ee0826220342f71af6d9eb8d486b75b | |
| parent | 8ee9db53bf77e676afa6ebf9c5a1b5bc6504c627 (diff) | |
Use current package rather than file path to filter private symbols
| -rw-r--r-- | src/server/analysis.odin | 33 | ||||
| -rw-r--r-- | src/server/completion.odin | 5 | ||||
| -rw-r--r-- | src/server/indexer.odin | 27 | ||||
| -rw-r--r-- | src/server/memory_index.odin | 3 | ||||
| -rw-r--r-- | src/server/methods.odin | 2 | ||||
| -rw-r--r-- | src/server/workspace_symbols.odin | 2 |
6 files changed, 47 insertions, 25 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 42d908b..06e593a 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -1404,7 +1404,10 @@ 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, node.pos.file)) + return resolve_symbol_return( + ast_context, + lookup(node.field.name, selector.pkg, ast_context.current_package, node.pos.file), + ) } else { return Symbol{}, false } @@ -1541,7 +1544,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 } @@ -1565,24 +1568,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", node.pos.file); ok { + if symbol, ok := lookup(node.name, "$builtin", ast_context.current_package, 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, node.pos.file); ok { + if symbol, ok := lookup(node.name, ast_context.current_package, 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", node.pos.file); ok { + if symbol, ok := lookup(node.name, "$builtin", ast_context.current_package, node.pos.file); ok { return resolve_symbol_return(ast_context, symbol) } } for built in indexer.builtin_packages { - if symbol, ok := lookup(node.name, built, node.pos.file); ok { + if symbol, ok := lookup(node.name, built, ast_context.current_package, node.pos.file); ok { return resolve_symbol_return(ast_context, symbol) } } @@ -1590,7 +1593,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, node.pos.file); ok { + if symbol, ok := lookup(node.name, imp.name, ast_context.current_package, node.pos.file); ok { return resolve_symbol_return(ast_context, symbol) } } @@ -2204,7 +2207,8 @@ resolve_implicit_selector :: proc( if cc, ok := stmt.derived.(^ast.Case_Clause); ok { for item in cc.list { if position_in_node(item, position_context.position) { - if symbol, ok := resolve_type_expression(ast_context, position_context.switch_stmt.cond); ok { + if symbol, ok := resolve_type_expression(ast_context, position_context.switch_stmt.cond); + ok { return symbol, ok } } @@ -2423,19 +2427,19 @@ resolve_location_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) - return symbol, true } - if symbol, ok := lookup(node.name, ast_context.document_package, node.pos.file); ok { + if symbol, ok := lookup(node.name, ast_context.document_package, ast_context.current_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, node.pos.file); ok { + if symbol, ok := lookup(node.name, pkg, ast_context.current_package, node.pos.file); ok { return symbol, ok } } - if symbol, ok := lookup(node.name, "$builtin", node.pos.file); ok { + if symbol, ok := lookup(node.name, "$builtin", ast_context.current_package, node.pos.file); ok { return resolve_symbol_return(ast_context, symbol) } @@ -2604,7 +2608,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.fullpath); ok { + if symbol, ok := lookup(container_name, built, ast_context.current_package, ast_context.fullpath); ok { if v, ok := symbol.value.(SymbolStructValue); ok { for name, i in v.names { if name == "allocator" { @@ -2624,7 +2628,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.fullpath); ok { + if symbol, ok := lookup(container_name, built, ast_context.current_package, ast_context.fullpath); ok { if v, ok := symbol.value.(SymbolStructValue); ok { for name, i in v.names { if name == "allocator" { @@ -2690,7 +2694,8 @@ resolve_symbol_selector :: proc( } } case SymbolPackageValue: - if pkg, ok := lookup(field, symbol.pkg, symbol.uri); ok { + if pkg, ok := lookup(field, symbol.pkg, ast_context.current_package, symbol.uri); + ok { symbol.range = pkg.range symbol.uri = pkg.uri } else { diff --git a/src/server/completion.odin b/src/server/completion.odin index b06c67f..33b30d6 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -1035,8 +1035,9 @@ get_selector_completion :: proc( is_incomplete = true pkg := selector.pkg + current_pkg := ast_context.current_package - if searched, ok := fuzzy_search(field, {pkg}, ast_context.fullpath); ok { + if searched, ok := fuzzy_search(field, {pkg}, current_pkg, ast_context.fullpath); ok { for search in searched { symbol := search.symbol @@ -1567,7 +1568,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.fullpath); ok { + if fuzzy_results, ok := fuzzy_search(lookup_name, pkgs[:], ast_context.current_package, ast_context.fullpath); ok { for r in fuzzy_results { r := r resolve_unresolved_symbol(ast_context, &r.symbol) diff --git a/src/server/indexer.odin b/src/server/indexer.odin index 793f621..d4ec5a4 100644 --- a/src/server/indexer.odin +++ b/src/server/indexer.odin @@ -26,7 +26,7 @@ clear_index_cache :: proc() { memory_index_clear_cache(&indexer.index) } -should_skip_private_symbol :: proc(symbol: Symbol, current_file: string) -> bool { +should_skip_private_symbol :: proc(symbol: Symbol, current_pkg, current_file: string) -> bool { if .PrivateFile not_in symbol.flags && .PrivatePackage not_in symbol.flags { return false } @@ -41,20 +41,27 @@ should_skip_private_symbol :: proc(symbol: Symbol, current_file: string) -> bool return true } - current_pkg := filepath.dir(current_file, context.temp_allocator) if .PrivatePackage in symbol.flags && current_pkg != symbol.pkg { return true } return false } -lookup :: proc(name: string, pkg: string, current_file: string, loc := #caller_location) -> (Symbol, bool) { +lookup :: proc( + name: string, + pkg: string, + current_pkg, current_file: string, + loc := #caller_location, +) -> ( + Symbol, + bool, +) { if name == "" { return {}, false } if symbol, ok := memory_index_lookup(&indexer.index, name, pkg); ok { - if should_skip_private_symbol(symbol, current_file) { + if should_skip_private_symbol(symbol, current_pkg, current_file) { return {}, false } return symbol, true @@ -63,8 +70,16 @@ lookup :: proc(name: string, pkg: string, current_file: string, loc := #caller_l return {}, false } -fuzzy_search :: proc(name: string, pkgs: []string, current_file: string, resolve_fields := false) -> ([]FuzzyResult, bool) { - results, ok := memory_index_fuzzy_search(&indexer.index, name, pkgs, current_file, resolve_fields) +fuzzy_search :: proc( + name: string, + pkgs: []string, + current_pkg, current_file: string, + resolve_fields := false, +) -> ( + []FuzzyResult, + bool, +) { + results, ok := memory_index_fuzzy_search(&indexer.index, name, pkgs, current_pkg, 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 4176757..bb4d13c 100644 --- a/src/server/memory_index.odin +++ b/src/server/memory_index.odin @@ -44,6 +44,7 @@ memory_index_fuzzy_search :: proc( index: ^MemoryIndex, name: string, pkgs: []string, + current_pkg: string, current_file: string, resolve_fields := false, ) -> ( @@ -59,7 +60,7 @@ memory_index_fuzzy_search :: proc( for pkg in pkgs { if pkg, ok := index.collection.packages[pkg]; ok { for _, symbol in pkg.symbols { - if should_skip_private_symbol(symbol, current_file) { + if should_skip_private_symbol(symbol, current_pkg, current_file) { continue } if resolve_fields { diff --git a/src/server/methods.odin b/src/server/methods.odin index e05fded..757b37d 100644 --- a/src/server/methods.odin +++ b/src/server/methods.odin @@ -116,7 +116,7 @@ collect_methods :: proc( for k, v in indexer.index.collection.packages { if symbols, ok := &v.methods[method]; ok { for &symbol in symbols { - if should_skip_private_symbol(symbol, ast_context.fullpath) { + if should_skip_private_symbol(symbol, ast_context.current_package, ast_context.fullpath) { continue } resolve_unresolved_symbol(ast_context, &symbol) diff --git a/src/server/workspace_symbols.odin b/src/server/workspace_symbols.odin index a45fba5..8ddbd64 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, |