aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2022-07-23 15:54:34 +0200
committerDaniel Gavin <danielgavin5@hotmail.com>2022-07-23 15:54:34 +0200
commitd69761f1dc75599b1314a368ae98590ff79bb4c8 (patch)
treeabb39f483876a89eced0387f0642b14457ef0f54
parent952de6f87060a596a8dbd919b34e9225fb4357c9 (diff)
Make ols more robust by also looking in the path environment for odin
-rw-r--r--src/common/util.odin37
-rw-r--r--src/server/requests.odin6
2 files changed, 43 insertions, 0 deletions
diff --git a/src/common/util.odin b/src/common/util.odin
new file mode 100644
index 0000000..662d30d
--- /dev/null
+++ b/src/common/util.odin
@@ -0,0 +1,37 @@
+package common
+
+import "core:fmt"
+import "core:os"
+import "core:strings"
+import "core:path/filepath"
+
+when ODIN_OS == .Windows {
+ delimiter :: ";"
+} else {
+ delimiter :: ":"
+}
+
+//TODO(daniel): This is temporary and should not be needed after os2
+File_Mode_User_Executable :: os.File_Mode(1 << 8)
+
+lookup_in_path :: proc(name: string) -> (string, bool) {
+ path := os.get_env("path", context.temp_allocator)
+
+ for directory in strings.split_iterator(&path, delimiter) {
+ when ODIN_OS == .Windows {
+ name := fmt.tprintf("%v/%v.exe", directory, name)
+ if os.exists(name) {
+ return name, true
+ }
+ } else {
+ name := fmt.tprintf("%v/%v", directory, name)
+ if os.exists(name) {
+ if info, err := os.stat(name, context.temp_allocator); err == os.ERROR_NONE && (File_Mode_User_Executable & info.mode) != 0 {
+ return name, true
+ }
+ }
+ }
+ }
+
+ return "", false
+}
diff --git a/src/server/requests.odin b/src/server/requests.odin
index af03d90..47f0d74 100644
--- a/src/server/requests.odin
+++ b/src/server/requests.odin
@@ -449,6 +449,12 @@ request_initialize :: proc (params: json.Value, id: RequestId, config: ^common.C
odin_core_env := os.get_env("ODIN_ROOT", context.temp_allocator)
+ if odin_core_env == "" && "core" not_in config.collections {
+ if exe_path, ok := common.lookup_in_path("odin"); ok {
+ odin_core_env = path.dir(exe_path, context.temp_allocator)
+ }
+ }
+
if "core" not_in config.collections && odin_core_env != "" {
forward_path, _ := filepath.to_slash(odin_core_env, context.temp_allocator)
config.collections["core"] = path.join(elems = {forward_path, "core"}, allocator = context.allocator)