diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2025-06-22 23:06:13 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2025-06-22 23:06:13 +0200 |
| commit | 3d1b2a5d7849c16dac4acea8b205af15be3351f4 (patch) | |
| tree | e30deffd287d5b746fbd8fb7d951a95b942e8c74 /src/server | |
| parent | ce13ab49907f45331260454477d2c22856baf633 (diff) | |
Start working on caching the packages of your project that are not used yet.
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/caches.odin | 58 | ||||
| -rw-r--r-- | src/server/collector.odin | 13 | ||||
| -rw-r--r-- | src/server/completion.odin | 26 | ||||
| -rw-r--r-- | src/server/requests.odin | 12 | ||||
| -rw-r--r-- | src/server/when.odin | 26 |
5 files changed, 129 insertions, 6 deletions
diff --git a/src/server/caches.odin b/src/server/caches.odin index f8ca0d0..3d26e22 100644 --- a/src/server/caches.odin +++ b/src/server/caches.odin @@ -2,8 +2,14 @@ package server import "src:common" -import "core:time" +import "core:fmt" +import "core:log" import "core:mem/virtual" +import "core:os" +import "core:path/filepath" +import "core:slice" +import "core:strings" +import "core:time" //Used in semantic tokens and inlay hints to handle the entire file being resolved. @@ -30,6 +36,7 @@ resolve_entire_file_cached :: proc(document: ^Document) -> map[uintptr]SymbolAnd BuildCache :: struct { loaded_pkgs: map[string]PackageCacheInfo, + pkg_aliases: map[string][dynamic]string, } PackageCacheInfo :: struct { @@ -37,3 +44,52 @@ PackageCacheInfo :: struct { } build_cache: BuildCache + + +clear_all_package_aliases :: proc() { + for collection_name, alias_array in build_cache.pkg_aliases { + for alias in alias_array { + delete(alias) + } + delete(alias_array) + } + + clear(&build_cache.pkg_aliases) +} + +//Go through all the collections to find all the possible packages that exists +find_all_package_aliases :: proc() { + walk_proc :: proc(info: os.File_Info, in_err: os.Errno, user_data: rawptr) -> (err: os.Errno, skip_dir: bool) { + data := cast(^[dynamic]string)user_data + + if !info.is_dir && filepath.ext(info.name) == ".odin" { + dir := filepath.dir(info.fullpath, context.temp_allocator) + if !slice.contains(data[:], dir) { + append(data, dir) + } + } + + return in_err, false + } + + for k, v in common.config.collections { + pkgs := make([dynamic]string, context.temp_allocator) + filepath.walk(v, walk_proc, &pkgs) + + for pkg in pkgs { + if pkg, err := filepath.rel(v, pkg, context.temp_allocator); err == .None { + forward_pkg, _ := filepath.to_slash(pkg, context.temp_allocator) + if !strings.contains(forward_pkg, "/") { + continue + } + if k not_in build_cache.pkg_aliases { + build_cache.pkg_aliases[k] = make([dynamic]string) + } + + aliases := &build_cache.pkg_aliases[k] + + append(aliases, strings.clone(forward_pkg)) + } + } + } +} diff --git a/src/server/collector.odin b/src/server/collector.odin index f29f3aa..fb2588a 100644 --- a/src/server/collector.odin +++ b/src/server/collector.odin @@ -437,10 +437,16 @@ collect_objc :: proc(collection: ^SymbolCollection, attributes: []^ast.Attribute } } -collect_imports :: proc(collection: ^SymbolCollection, file: ast.File) { +collect_imports :: proc(collection: ^SymbolCollection, file: ast.File, directory: string) { + _pkg := get_index_unique_string(collection, directory) + + if _pkg, ok := collection.packages[_pkg]; ok { + + } } + collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: string) -> common.Error { forward, _ := filepath.to_slash(file.fullpath, context.temp_allocator) directory := path.dir(forward, context.temp_allocator) @@ -448,8 +454,6 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri exprs := collect_globals(file, true) - collect_imports(collection, file) - for expr in exprs { symbol: Symbol @@ -662,6 +666,9 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri } } + collect_imports(collection, file, directory) + + return .None } diff --git a/src/server/completion.odin b/src/server/completion.odin index 31c21f5..04d580a 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -1501,6 +1501,8 @@ get_identifier_completion :: proc( } } + append_non_imported_packages(ast_context, position_context, &items) + list.items = items[:] } @@ -1693,6 +1695,30 @@ get_range_from_selection_start_to_dot :: proc(position_context: ^DocumentPositio return {}, false } +append_non_imported_packages :: proc( + ast_context: ^AstContext, + position_context: ^DocumentPositionContext, + items: ^[dynamic]CompletionItem, +) { + + + for collection, pkgs in build_cache.pkg_aliases { + + for pkg in pkgs { + + //filepath.is_separator() + + } + + } + + for pkg in ast_context.imports { + //log.error(pkg) + } + + +} + append_magic_map_completion :: proc( position_context: ^DocumentPositionContext, symbol: Symbol, diff --git a/src/server/requests.odin b/src/server/requests.odin index 19a99b7..52df45c 100644 --- a/src/server/requests.odin +++ b/src/server/requests.odin @@ -410,7 +410,7 @@ read_ols_initialize_options :: proc(config: ^common.Config, ols_config: OlsConfi } if config.profile.os == "" { - config.profile.os = fmt.aprint(ODIN_OS) + config.profile.os = os_enum_to_string[ODIN_OS] } if config.profile.arch == "" { @@ -735,6 +735,8 @@ request_initialize :: proc( register_dynamic_capabilities(writer) } + find_all_package_aliases() + return .None } @@ -1477,13 +1479,21 @@ notification_did_change_watched_files :: proc( if uri, ok := common.parse_uri(change.uri, context.temp_allocator); ok { remove_index_file(uri) } + clear_all_package_aliases() + find_all_package_aliases() } else { if uri, ok := common.parse_uri(change.uri, context.temp_allocator); ok { if data, ok := os.read_entire_file(uri.path); ok { index_file(uri, cast(string)data) } } + if change.type == cast(int)FileChangeType.Created { + clear_all_package_aliases() + find_all_package_aliases() + } } + + } return .None diff --git a/src/server/when.odin b/src/server/when.odin index cf31bf0..e712596 100644 --- a/src/server/when.odin +++ b/src/server/when.odin @@ -1,5 +1,7 @@ +#+feature dynamic-literals package server +import "base:runtime" import "core:fmt" import "core:log" import "core:odin/ast" @@ -14,11 +16,33 @@ When_Expr :: union { ^ast.Expr, } +//Because we use configuration with os names that match the files instead of the enum, i.e. my_file_windows.odin, we have to convert back and fourth. +@(private = "file") +convert_os_string: map[string]string = { + "windows" = "Windows", + "darwin" = "Darwin", + "linux" = "Linux", + "essence" = "Essence", + "freebsd" = "FreeBSD", + "wasi" = "WASI", + "js" = "JS", + "freestanding" = "Freestanding", + "haiku" = "Haiku", + "openbsd" = "OpenBSD", + "netbsd" = "NetBSD", + "freebsd" = "FreeBSD", +} + resolve_when_ident :: proc(when_expr_map: map[string]When_Expr, ident: string) -> (When_Expr, bool) { switch ident { case "ODIN_OS": if common.config.profile.os != "" { - return common.config.profile.os, true + os, ok := convert_os_string[common.config.profile.os] + if ok { + return os, true + } else { + return fmt.tprint(ODIN_OS), true + } } else { return fmt.tprint(ODIN_OS), true } |