diff options
| -rw-r--r-- | src/server/indexer.odin | 13 | ||||
| -rw-r--r-- | src/server/workspace_symbols.odin | 88 |
2 files changed, 53 insertions, 48 deletions
diff --git a/src/server/indexer.odin b/src/server/indexer.odin index 1afa1e8..e97c4f5 100644 --- a/src/server/indexer.odin +++ b/src/server/indexer.odin @@ -73,19 +73,8 @@ fuzzy_search :: proc( bool, ) { results, ok := memory_index_fuzzy_search(&indexer.index, name, pkgs, current_file, resolve_fields) - result := make([dynamic]FuzzyResult, context.temp_allocator) - if !ok { return {}, false } - - for r in results { - append(&result, r) - } - - slice.sort_by(result[:], proc(i, j: FuzzyResult) -> bool { - return j.score < i.score - }) - - return result[:], true + return results[:], true } 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) } } |