diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2024-02-07 22:11:02 +0100 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2024-02-07 22:11:02 +0100 |
| commit | 90244dd6d16c2499f05a12a2ab7c00769aeecd47 (patch) | |
| tree | c023cbfcd6cdc6d8216505a5eaf64b1d304613e6 /src/server | |
| parent | 3e612a42670e1b581ece6f4a90382e0d830f3ef2 (diff) | |
Start working on profiles
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/check.odin | 67 | ||||
| -rw-r--r-- | src/server/requests.odin | 23 | ||||
| -rw-r--r-- | src/server/types.odin | 2 |
3 files changed, 50 insertions, 42 deletions
diff --git a/src/server/check.odin b/src/server/check.odin index 9e6de6b..cae7587 100644 --- a/src/server/check.odin +++ b/src/server/check.odin @@ -18,7 +18,10 @@ import "core:thread" import "shared:common" -check :: proc(uri: common.Uri, writer: ^Writer, config: ^common.Config) { +//Store uris we have reported on since last save. We use this to clear them on next save. +uris_reported := make([dynamic]string) + +check :: proc(path: string, writer: ^Writer, config: ^common.Config) { data := make([]byte, mem.Kilobyte * 200, context.temp_allocator) buffer: []byte @@ -45,36 +48,25 @@ check :: proc(uri: common.Uri, writer: ^Writer, config: ^common.Config) { command = "odin" } + entry_point_opt := + filepath.ext(path) == ".odin" ? "-file" : "-no-entry-point" + if code, ok, buffer = common.run_executable( fmt.tprintf( - "%v check %s %s -no-entry-point %s %s", + "%v check %s %s %s %s %s", command, - uri.path, + path, strings.to_string(collection_builder), + entry_point_opt, config.checker_args, ODIN_OS == .Linux || ODIN_OS == .Darwin ? "2>&1" : "", ), &data, ); !ok { - log.errorf( - "Odin check failed with code %v for file %v", - code, - uri.path, - ) + log.errorf("Odin check failed with code %v for file %v", code, path) return } - log.error( - fmt.tprintf( - "%v check %s %s -no-entry-point %s %s", - command, - path.dir(uri.path, context.temp_allocator), - strings.to_string(collection_builder), - config.checker_args, - ODIN_OS == .Linux || ODIN_OS == .Darwin ? "2>&1" : "", - ), - ) - s: scanner.Scanner scanner.init(&s, string(buffer)) @@ -224,31 +216,30 @@ check :: proc(uri: common.Uri, writer: ^Writer, config: ^common.Config) { ) } - matches, err := filepath.glob( - fmt.tprintf("%v/*.odin", path.dir(uri.path, context.temp_allocator)), - ) + for uri in uris_reported { - if err == .None { - for match in matches { - uri := common.create_uri(match, context.temp_allocator) + log.errorf("clear %v", uri) - params := NotificationPublishDiagnosticsParams { - uri = uri.uri, - diagnostics = {}, - } + params := NotificationPublishDiagnosticsParams { + uri = uri, + diagnostics = {}, + } - notifaction := Notification { - jsonrpc = "2.0", - method = "textDocument/publishDiagnostics", - params = params, - } + notifaction := Notification { + jsonrpc = "2.0", + method = "textDocument/publishDiagnostics", + params = params, + } - if writer != nil { - send_notification(notifaction, writer) - } + if writer != nil { + send_notification(notifaction, writer) } + + delete(uri) } + clear(&uris_reported) + for k, v in errors { uri := common.create_uri(k, context.temp_allocator) @@ -263,6 +254,8 @@ check :: proc(uri: common.Uri, writer: ^Writer, config: ^common.Config) { params = params, } + append(&uris_reported, strings.clone(uri.uri)) + if writer != nil { send_notification(notifaction, writer) } diff --git a/src/server/requests.odin b/src/server/requests.odin index 35a2865..3da2d6c 100644 --- a/src/server/requests.odin +++ b/src/server/requests.odin @@ -443,6 +443,20 @@ read_ols_initialize_options :: proc( ) } + for profile in ols_config.profiles { + if ols_config.profile == profile.name { + if filepath.is_abs(ols_config.profile) { + config.profile.checker_path = strings.clone( + profile.checker_path, + ) + } else { + config.profile.checker_path = path.join( + elems = {uri.path, profile.checker_path}, + ) + } + } + } + config.checker_targets = slice.clone( ols_config.checker_targets, context.allocator, @@ -1146,11 +1160,10 @@ notification_did_save :: proc( log.errorf("failed to collect symbols on save %v", ret) } - if uri, ok := common.parse_uri( - config.workspace_folders[0].uri, - context.temp_allocator, - ); ok { - check(uri, writer, config) + if config.profile.checker_path != "" { + check(config.profile.checker_path, writer, config) + } else { + check(config.workspace_folders[0].uri, writer, config) } return .None diff --git a/src/server/types.odin b/src/server/types.odin index 3903c73..24c5827 100644 --- a/src/server/types.odin +++ b/src/server/types.odin @@ -354,6 +354,8 @@ OlsConfig :: struct { odin_command: string, checker_args: string, checker_targets: []string, + profiles: [dynamic]common.ConfigProfile, + profile: string, } OlsConfigCollection :: struct { |