aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-12-06 05:05:07 -0500
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-12-06 05:05:07 -0500
commitf1c77965bbdb137aa40d5890e52f71006aaa1470 (patch)
tree8e13f3810fcabd59fe509458515eb045094c6d9f
parent0cf7f19eb147ae20c7427395397a08627de23264 (diff)
Add support for ols config profiles with defines and arch
-rw-r--r--README.md9
-rw-r--r--misc/ols.schema.json11
-rw-r--r--src/main.odin8
-rw-r--r--src/server/requests.odin40
-rw-r--r--src/server/unmarshal.odin2
-rw-r--r--src/server/when.odin1
6 files changed, 39 insertions, 32 deletions
diff --git a/README.md b/README.md
index 0ea80d7..25c94c1 100644
--- a/README.md
+++ b/README.md
@@ -59,9 +59,10 @@ Example of `ols.json`:
"enable_snippets": true,
"profile": "default",
"profiles": [
- { "name": "default", "checker_path": ["src"]},
- { "name": "linux_profile", "os": "linux", "checker_path": ["src/main.odin"]},
- { "name": "windows_profile", "os": "windows", "checker_path": ["src"]}
+ { "name": "default", "checker_path": ["src"], "defines": { "ODIN_DEBUG": "false" }},
+ { "name": "linux_profile", "os": "linux", "checker_path": ["src/main.odin"], "defines": { "ODIN_DEBUG": "false" }},
+ { "name": "mac_profile", "os": "darwin", "arch": "arm64", "defines": { "ODIN_DEBUG": "false" }},
+ { "name": "windows_profile", "os": "windows", "checker_path": ["src"], "defines": { "ODIN_DEBUG": "false" }}
]
}
```
@@ -110,7 +111,7 @@ Options:
- `profile`: What profile to currently use.
-- `profiles`: List of different profiles that describe the environment ols is running under.
+- `profiles`: List of different profiles that describe the environment ols is running under. This allows you to define different operating systems, architectures and defines for `ols` to use during development, easily switching between them using the `profile` configuration.
### Odinfmt configurations
diff --git a/misc/ols.schema.json b/misc/ols.schema.json
index c3ad997..b5ebd93 100644
--- a/misc/ols.schema.json
+++ b/misc/ols.schema.json
@@ -128,6 +128,10 @@
"type": "string",
"description": "The operating system for the profile."
},
+ "arch": {
+ "type": "string",
+ "description": "The architecture for the profile."
+ },
"checker_path": {
"type": "array",
"description": "List of paths where to run the checker.",
@@ -141,6 +145,13 @@
"items": {
"type": "string"
}
+ },
+ "defines": {
+ "type": "object",
+ "description": "Key-value pairs of defines. Used for evaluating when expressions, for example `ODIN_DEBUG`. The value must be a string.",
+ "additionalProperties": {
+ "type": "string"
+ }
}
},
"required": ["name", "checker_path"],
diff --git a/src/main.odin b/src/main.odin
index a77b2b4..b4aad6f 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -2,20 +2,12 @@ package main
import "base:intrinsics"
-import "core:encoding/json"
import "core:fmt"
import "core:log"
import "core:mem"
import "core:os"
-import "core:reflect"
-import "core:slice"
-import "core:strconv"
-import "core:strings"
-import "core:sync"
import "core:thread"
-import "core:sys/windows"
-
import "src:common"
import "src:server"
diff --git a/src/server/requests.odin b/src/server/requests.odin
index 82d0ae2..9a7326a 100644
--- a/src/server/requests.odin
+++ b/src/server/requests.odin
@@ -363,12 +363,14 @@ read_ols_initialize_options :: proc(config: ^common.Config, ols_config: OlsConfi
config.enable_format = ols_config.enable_format.(bool) or_else config.enable_format
config.enable_hover = ols_config.enable_hover.(bool) or_else config.enable_hover
config.enable_semantic_tokens = ols_config.enable_semantic_tokens.(bool) or_else config.enable_semantic_tokens
- config.enable_unused_imports_reporting = ols_config.enable_unused_imports_reporting.(bool) or_else config.enable_unused_imports_reporting
+ config.enable_unused_imports_reporting =
+ ols_config.enable_unused_imports_reporting.(bool) or_else config.enable_unused_imports_reporting
config.enable_procedure_context =
ols_config.enable_procedure_context.(bool) or_else config.enable_procedure_context
config.enable_snippets = ols_config.enable_snippets.(bool) or_else config.enable_snippets
config.enable_references = ols_config.enable_references.(bool) or_else config.enable_references
- config.enable_document_highlights = ols_config.enable_document_highlights.(bool) or_else config.enable_document_highlights
+ config.enable_document_highlights =
+ ols_config.enable_document_highlights.(bool) or_else config.enable_document_highlights
config.enable_completion_matching =
ols_config.enable_completion_matching.(bool) or_else config.enable_completion_matching
config.enable_document_links = ols_config.enable_document_links.(bool) or_else config.enable_document_links
@@ -420,6 +422,11 @@ read_ols_initialize_options :: proc(config: ^common.Config, ols_config: OlsConfi
}
config.profile.os = strings.clone(profile.os)
+ config.profile.arch = strings.clone(profile.arch)
+
+ for key, value in profile.defines {
+ config.profile.defines[strings.clone(key)] = strings.clone(value)
+ }
break
}
@@ -652,17 +659,13 @@ request_initialize :: proc(
read_ols_config :: proc(file: string, config: ^common.Config, uri: common.Uri) {
if data, ok := os.read_entire_file(file, context.temp_allocator); ok {
- if value, err := json.parse(data = data, allocator = context.temp_allocator, parse_integers = true);
- err == .None {
- ols_config: OlsConfig
-
- if unmarshal(value, ols_config, context.temp_allocator) == nil {
- read_ols_initialize_options(config, ols_config, uri)
- } else {
- log.warnf("Failed to unmarshal %v", file)
- }
+ ols_config: OlsConfig
+
+ err := json.unmarshal(data, &ols_config, allocator = context.temp_allocator)
+ if err == nil {
+ read_ols_initialize_options(config, ols_config, uri)
} else {
- log.warnf("Failed to parse json %v", file)
+ log.errorf("Failed to unmarshal %v: %v", file, err)
}
} else {
log.warnf("Failed to read/find %v", file)
@@ -748,11 +751,9 @@ request_initialize :: proc(
tokenModifiers = semantic_token_modifier_names,
},
},
- inlayHintProvider = (
- config.enable_inlay_hints_params ||
+ inlayHintProvider = (config.enable_inlay_hints_params ||
config.enable_inlay_hints_default_params ||
- config.enable_inlay_hints_implicit_return
- ),
+ config.enable_inlay_hints_implicit_return),
documentSymbolProvider = config.enable_document_symbols,
hoverProvider = config.enable_hover,
documentFormattingProvider = config.enable_format,
@@ -1557,7 +1558,12 @@ request_highlights :: proc(
return .None
}
-request_code_action :: proc(params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
+request_code_action :: proc(
+ params: json.Value,
+ id: RequestId,
+ config: ^common.Config,
+ writer: ^Writer,
+) -> common.Error {
params_object, ok := params.(json.Object)
if !ok {
diff --git a/src/server/unmarshal.odin b/src/server/unmarshal.odin
index d93663c..04e155d 100644
--- a/src/server/unmarshal.odin
+++ b/src/server/unmarshal.odin
@@ -1,9 +1,7 @@
package server
import "base:runtime"
-
import "core:encoding/json"
-import "core:fmt"
import "core:mem"
import "core:strings"
diff --git a/src/server/when.odin b/src/server/when.odin
index 20ef128..ea1d397 100644
--- a/src/server/when.odin
+++ b/src/server/when.odin
@@ -3,7 +3,6 @@ package server
import "base:runtime"
import "core:fmt"
-import "core:log"
import "core:odin/ast"
import "core:strconv"