diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-09-08 22:43:04 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-09-08 22:43:04 -0400 |
| commit | d5eceef610619f34996c1be2da218fcc4eb1ef5c (patch) | |
| tree | 98484c5b934ba5b9f509c3eca9f923cfbe642f32 /src/server/workspace_symbols.odin | |
| parent | 6e1b9e3fcecabf258f8f718e113f0b37f21e00ee (diff) | |
Cache workspace pkgs so we don't walk the file system each workspace symbol request
Diffstat (limited to 'src/server/workspace_symbols.odin')
| -rw-r--r-- | src/server/workspace_symbols.odin | 88 |
1 files changed, 52 insertions, 36 deletions
diff --git a/src/server/workspace_symbols.odin b/src/server/workspace_symbols.odin index a45fba5..c48ffad 100644 --- a/src/server/workspace_symbols.odin +++ b/src/server/workspace_symbols.odin @@ -1,16 +1,24 @@ package server - import "core:fmt" import "core:log" import "core:os" import "core:path/filepath" import "core:strings" +import "core:time" import "src:common" dir_blacklist :: []string{"node_modules", ".git"} +WorkspaceCache :: struct { + time: time.Time, + pkgs: [dynamic]string, +} + +@(thread_local, private = "file") +cache: WorkspaceCache + @(private) walk_dir :: proc(info: os.File_Info, in_err: os.Errno, user_data: rawptr) -> (err: os.Error, skip_dir: bool) { pkgs := cast(^[dynamic]string)user_data @@ -31,50 +39,58 @@ walk_dir :: proc(info: os.File_Info, in_err: os.Errno, user_data: rawptr) -> (er } get_workspace_symbols :: proc(query: string) -> (workspace_symbols: []WorkspaceSymbol, ok: bool) { - workspace := common.config.workspace_folders[0] - uri := common.parse_uri(workspace.uri, context.temp_allocator) or_return - pkgs := make([dynamic]string, 0, context.temp_allocator) - symbols := make([dynamic]WorkspaceSymbol, 0, 100, context.temp_allocator) - - filepath.walk(uri.path, walk_dir, &pkgs) + if time.since(cache.time) > 1 * time.Minute { + for pkg in cache.pkgs { + delete(pkg) + } + clear(&cache.pkgs) + workspace := common.config.workspace_folders[0] + uri := common.parse_uri(workspace.uri, context.temp_allocator) or_return + pkgs := make([dynamic]string, 0, context.temp_allocator) - _pkg: for pkg in pkgs { - matches, err := filepath.glob(fmt.tprintf("%v/*.odin", pkg), context.temp_allocator) + filepath.walk(uri.path, walk_dir, &pkgs) - if len(matches) == 0 { - continue - } + _pkg: for pkg in pkgs { + matches, err := filepath.glob(fmt.tprintf("%v/*.odin", pkg), context.temp_allocator) - for exclude_path in common.config.profile.exclude_path { - exclude_forward, _ := filepath.to_slash(exclude_path, context.temp_allocator) + if len(matches) == 0 { + continue + } - if exclude_forward[len(exclude_forward) - 2:] == "**" { - lower_pkg := strings.to_lower(pkg) - lower_exclude := strings.to_lower(exclude_forward[:len(exclude_forward) - 3]) - if strings.contains(lower_pkg, lower_exclude) { - continue _pkg - } - } else { - lower_pkg := strings.to_lower(pkg) - lower_exclude := strings.to_lower(exclude_forward) - if lower_pkg == lower_exclude { - continue _pkg + for exclude_path in common.config.profile.exclude_path { + exclude_forward, _ := filepath.to_slash(exclude_path, context.temp_allocator) + + if exclude_forward[len(exclude_forward) - 2:] == "**" { + lower_pkg := strings.to_lower(pkg) + lower_exclude := strings.to_lower(exclude_forward[:len(exclude_forward) - 3]) + if strings.contains(lower_pkg, lower_exclude) { + continue _pkg + } + } else { + lower_pkg := strings.to_lower(pkg) + lower_exclude := strings.to_lower(exclude_forward) + if lower_pkg == lower_exclude { + continue _pkg + } } } - } - try_build_package(pkg) - - if results, ok := fuzzy_search(query, {pkg}, "", resolve_fields = true); ok { - for result in results { - symbol := WorkspaceSymbol { - name = result.symbol.name, - location = {range = result.symbol.range, uri = result.symbol.uri}, - kind = symbol_kind_to_type(result.symbol.type), - } + try_build_package(pkg) + append(&cache.pkgs, strings.clone(pkg, context.allocator)) + } + cache.time = time.now() + } - append(&symbols, symbol) + symbols := make([dynamic]WorkspaceSymbol, 0, 100, context.temp_allocator) + if results, ok := fuzzy_search(query, cache.pkgs[:], "", resolve_fields = false); ok { + for result in results { + symbol := WorkspaceSymbol { + name = result.symbol.name, + location = {range = result.symbol.range, uri = result.symbol.uri}, + kind = symbol_kind_to_type(result.symbol.type), } + + append(&symbols, symbol) } } |