Skip to content

Commit

Permalink
added ability for loading lsp config from a file
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Mar 12, 2024
1 parent 0fb949e commit 8080f61
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions config/languages.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions scripting/absytree_internal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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*() =
Expand Down
2 changes: 2 additions & 0 deletions scripting/absytree_internal_wasm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.}
Expand Down
2 changes: 2 additions & 0 deletions scripting/editor_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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*() =
Expand Down
15 changes: 15 additions & 0 deletions scripting/editor_api_wasm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions src/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8080f61

Please sign in to comment.