aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2024-02-07 22:11:02 +0100
committerDanielGavin <danielgavin5@hotmail.com>2024-02-07 22:11:02 +0100
commit90244dd6d16c2499f05a12a2ab7c00769aeecd47 (patch)
treec023cbfcd6cdc6d8216505a5eaf64b1d304613e6
parent3e612a42670e1b581ece6f4a90382e0d830f3ef2 (diff)
Start working on profiles
-rw-r--r--README.md11
-rw-r--r--src/common/config.odin7
-rw-r--r--src/server/check.odin67
-rw-r--r--src/server/requests.odin23
-rw-r--r--src/server/types.odin2
5 files changed, 67 insertions, 43 deletions
diff --git a/README.md b/README.md
index 4438706..2a556c7 100644
--- a/README.md
+++ b/README.md
@@ -48,7 +48,12 @@ Example of `ols.json`:
"enable_semantic_tokens": false,
"enable_document_symbols": true,
"enable_hover": true,
- "enable_snippets": true
+ "enable_snippets": true,
+ "profile": "windows",
+ "profiles": [
+ { "name": "linux_profile", "os": "linux", "checker_path": "src/main.odin"},
+ { "name": "windows_profile", "os": "windows", "checker_path": "src"}
+ ]
}
```
@@ -78,6 +83,10 @@ Options:
`verbose`: Logs warnings instead of just errors.
+`profile`: What profile to currently use.
+
+`profiles`: List of different profiles that describe the environment ols is running under.
+
### Odinfmt configurations
Odinfmt reads configuration through `odinfmt.json`.
diff --git a/src/common/config.odin b/src/common/config.odin
index 71a6f4e..3adc98e 100644
--- a/src/common/config.odin
+++ b/src/common/config.odin
@@ -1,5 +1,11 @@
package common
+ConfigProfile :: struct {
+ os: string,
+ name: string,
+ checker_path: string,
+}
+
Config :: struct {
workspace_folders: [dynamic]WorkspaceFolder,
completion_support_md: bool,
@@ -29,6 +35,7 @@ Config :: struct {
checker_args: string,
checker_targets: []string,
client_name: string,
+ profile: ConfigProfile,
}
config: Config
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 {