diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2024-03-10 21:54:28 +0100 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2024-03-10 21:54:28 +0100 |
| commit | 89fd8a66c987703801288300a78376cdf140c198 (patch) | |
| tree | d5b73fcc631f6af1942935f7ac9fd9b2c4ed48b1 | |
| parent | e86f46836c66a3c55dbf321fa58c95a7bd237414 (diff) | |
Add fallback in `odin check` to try all directory with odin code in them.
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | ols.json | 22 | ||||
| -rw-r--r-- | src/server/check.odin | 43 | ||||
| -rw-r--r-- | src/server/requests.odin | 12 |
4 files changed, 46 insertions, 33 deletions
@@ -13,5 +13,5 @@ *node_modules /ols /odinfmt - +ols.json diff --git a/ols.json b/ols.json deleted file mode 100644 index 477305c..0000000 --- a/ols.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/DanielGavin/ols/master/misc/ols.schema.json", - "collections": [ - { - "name": "src", - "path": "src" - } - ], - "profiles": [ - { "name": "linux_profile", "os": "linux", "checker_path": ["src/main.odin"]}, - { "name": "windows_profile", "os": "windows", "checker_path": ["src/main.odin", "src"]} - ], - "profile": "windows_profile", - "enable_document_symbols": true, - "enable_semantic_tokens": true, - "enable_snippets": true, - "enable_references": true, - "enable_fake_methods": false, - "enable_inlay_hints": false, - "enable_procedure_snippet": false, - "verbose": false -}
\ No newline at end of file diff --git a/src/server/check.odin b/src/server/check.odin index d041320..a3804df 100644 --- a/src/server/check.odin +++ b/src/server/check.odin @@ -21,7 +21,50 @@ import "src:common" //Store uris we have reported on since last save. We use this to clear them on next save. uris_reported := make([dynamic]string) + +//If the user does not specify where to call odin check, it'll just find all directory with odin, and call them seperately. +fallback_find_odin_directories :: proc(config: ^common.Config) -> []string { + 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 + } + + data := make([dynamic]string, context.temp_allocator) + + if len(config.workspace_folders) > 0 { + if uri, ok := common.parse_uri( + config.workspace_folders[0].uri, + context.temp_allocator, + ); ok { + filepath.walk(uri.path, walk_proc, &data) + } + } + + return data[:] +} + check :: proc(paths: []string, writer: ^Writer, config: ^common.Config) { + paths := paths + + if len(paths) == 0 { + paths = fallback_find_odin_directories(config) + } + data := make([]byte, mem.Kilobyte * 200, context.temp_allocator) buffer: []byte diff --git a/src/server/requests.odin b/src/server/requests.odin index a877c69..00b649b 100644 --- a/src/server/requests.odin +++ b/src/server/requests.odin @@ -695,6 +695,7 @@ request_initialize :: proc( ) } + for format in initialize_params.capabilities.textDocument.hover.contentFormat { if format == "markdown" { config.hover_support_md = true @@ -1180,16 +1181,7 @@ notification_did_save :: proc( log.errorf("failed to collect symbols on save %v", ret) } - if len(config.profile.checker_path) > 0 { - check(config.profile.checker_path[:], writer, config) - } else { - if uri, ok := common.parse_uri( - config.workspace_folders[0].uri, - context.temp_allocator, - ); ok { - check({uri.path}, writer, config) - } - } + check(config.profile.checker_path[:], writer, config) return .None } |