diff --git a/config/languages.nim b/config/languages.nim index b49cce7c..62babb30 100644 --- a/config/languages.nim +++ b/config/languages.nim @@ -11,6 +11,15 @@ else: setOption "editor.text.languages-server.url", "" setOption "editor.text.languages-server.port", 0 +proc loadLspConfigFromFile*(file: string) = + try: + let str = loadApplicationFile(file).get + let json = str.parseJson() + infof"Loaded lsp config from file: {json}" + setOption "editor.text.lsp", json + except: + info &"Failed to load lsp config from file: {getCurrentExceptionMsg()}\n{getCurrentException().getStackTrace()}" + setOption "editor.text.lsp.zig.path", "zls" setOption "editor.text.lsp.rust.path", "rust-analyzer" setOption "editor.text.lsp.nim.path", "nimlangserver" diff --git a/scripting/absytree_internal.nim b/scripting/absytree_internal.nim index 85080c5d..d67293e7 100644 --- a/scripting/absytree_internal.nim +++ b/scripting/absytree_internal.nim @@ -532,6 +532,9 @@ proc editor_model_findDeclaration_void_ModelDocumentEditor_bool_impl*( discard proc editor_getBackend_Backend_App_impl*(): Backend = discard +proc editor_loadApplicationFile_Option_string_App_string_impl*(path: string): Option[ + string] = + discard proc editor_toggleShowDrawnNodes_void_App_impl*() = discard proc editor_saveAppState_void_App_impl*() = diff --git a/scripting/absytree_internal_wasm.nim b/scripting/absytree_internal_wasm.nim index 9bd13ad2..1d20c43d 100644 --- a/scripting/absytree_internal_wasm.nim +++ b/scripting/absytree_internal_wasm.nim @@ -358,6 +358,8 @@ proc editor_model_loadLanguageModel_void_ModelDocumentEditor_impl( proc editor_model_findDeclaration_void_ModelDocumentEditor_bool_impl( self: ModelDocumentEditor; global: bool) {.importc.} proc editor_getBackend_Backend_App_impl(): Backend {.importc.} +proc editor_loadApplicationFile_Option_string_App_string_impl(path: string): Option[ + string] {.importc.} proc editor_toggleShowDrawnNodes_void_App_impl() {.importc.} proc editor_saveAppState_void_App_impl() {.importc.} proc editor_requestRender_void_App_bool_impl(redrawEverything: bool = false) {.importc.} diff --git a/scripting/editor_api.nim b/scripting/editor_api.nim index 694ddb89..9d71bc3e 100644 --- a/scripting/editor_api.nim +++ b/scripting/editor_api.nim @@ -12,6 +12,8 @@ else: proc getBackend*(): Backend = editor_getBackend_Backend_App_impl() +proc loadApplicationFile*(path: string): Option[string] = + editor_loadApplicationFile_Option_string_App_string_impl(path) proc toggleShowDrawnNodes*() = editor_toggleShowDrawnNodes_void_App_impl() proc saveAppState*() = diff --git a/scripting/editor_api_wasm.nim b/scripting/editor_api_wasm.nim index 6b42e74e..ce45013c 100644 --- a/scripting/editor_api_wasm.nim +++ b/scripting/editor_api_wasm.nim @@ -12,6 +12,21 @@ proc getBackend*(): Backend = result = parseJson($res).jsonTo(typeof(result)) +proc editor_loadApplicationFile_Option_string_App_string_wasm(arg: cstring): cstring {. + importc.} +proc loadApplicationFile*(path: string): Option[string] = + var argsJson = newJArray() + argsJson.add block: + when string is JsonNode: + path + else: + path.toJson() + let argsJsonString = $argsJson + let res {.used.} = editor_loadApplicationFile_Option_string_App_string_wasm( + argsJsonString.cstring) + result = parseJson($res).jsonTo(typeof(result)) + + proc editor_toggleShowDrawnNodes_void_App_wasm(arg: cstring): cstring {.importc.} proc toggleShowDrawnNodes*() = var argsJson = newJArray() diff --git a/src/app.nim b/src/app.nim index dda8f0ed..df2fa60b 100644 --- a/src/app.nim +++ b/src/app.nim @@ -987,6 +987,10 @@ static: proc getBackend*(self: App): Backend {.expose("editor").} = return self.backend +proc loadApplicationFile*(self: App, path: string): Option[string] {.expose("editor").} = + ## Load a file from the application directory (path is relative to the executable) + return fs.loadApplicationFile(path).some + proc toggleShowDrawnNodes*(self: App) {.expose("editor").} = self.platform.showDrawnNodes = not self.platform.showDrawnNodes