Skip to content

Commit

Permalink
Moved config and git functionality out of app
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Oct 18, 2024
1 parent f8f4213 commit cf618e8
Show file tree
Hide file tree
Showing 32 changed files with 745 additions and 834 deletions.
4 changes: 2 additions & 2 deletions config/vscode_config_plugin.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import std/options

proc loadVSCodeSnippets*(file: string, language: string) {.expose("load-vscode-snippets").} =
loadWorkspaceFile file, proc(content: Option[string]) =
if content.isNone:
if content.isNone or content.get.len == 0:
return

try:
Expand All @@ -19,7 +19,7 @@ proc loadVSCodeSnippets*(file: string, language: string) {.expose("load-vscode-s

proc loadVSCodeDebuggerConfig*(file: string) {.expose("load-vscode-debugger-config").} =
loadWorkspaceFile file, proc(content: Option[string]) =
if content.isNone:
if content.isNone or content.get.len == 0:
return

try:
Expand Down
Binary file modified config/wasm/harpoon.wasm
Binary file not shown.
Binary file modified config/wasm/keybindings_plugin.wasm
Binary file not shown.
Binary file modified config/wasm/vscode_config_plugin.wasm
Binary file not shown.
62 changes: 62 additions & 0 deletions scripting/config_api_wasm.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import std/[json, options]
import scripting_api, misc/myjsonutils

## This file is auto generated, don't modify.


proc config_logOptions_void_ConfigService_wasm(arg: cstring): cstring {.importc.}
proc logOptions*() {.gcsafe, raises: [].} =
var argsJson = newJArray()
let argsJsonString = $argsJson
let res {.used.} = config_logOptions_void_ConfigService_wasm(
argsJsonString.cstring)


proc config_setOption_void_ConfigService_string_JsonNode_bool_wasm(arg: cstring): cstring {.
importc.}
proc setOption*(option: string; value: JsonNode; override: bool = true) {.
gcsafe, raises: [].} =
var argsJson = newJArray()
argsJson.add option.toJson()
argsJson.add value.toJson()
argsJson.add override.toJson()
let argsJsonString = $argsJson
let res {.used.} = config_setOption_void_ConfigService_string_JsonNode_bool_wasm(
argsJsonString.cstring)


proc config_getFlag_bool_ConfigService_string_bool_wasm(arg: cstring): cstring {.
importc.}
proc getFlag*(flag: string; default: bool = false): bool {.gcsafe, raises: [].} =
var argsJson = newJArray()
argsJson.add flag.toJson()
argsJson.add default.toJson()
let argsJsonString = $argsJson
let res {.used.} = config_getFlag_bool_ConfigService_string_bool_wasm(
argsJsonString.cstring)
try:
result = parseJson($res).jsonTo(typeof(result))
except:
raiseAssert(getCurrentExceptionMsg())


proc config_setFlag_void_ConfigService_string_bool_wasm(arg: cstring): cstring {.
importc.}
proc setFlag*(flag: string; value: bool) {.gcsafe, raises: [].} =
var argsJson = newJArray()
argsJson.add flag.toJson()
argsJson.add value.toJson()
let argsJsonString = $argsJson
let res {.used.} = config_setFlag_void_ConfigService_string_bool_wasm(
argsJsonString.cstring)


proc config_toggleFlag_void_ConfigService_string_wasm(arg: cstring): cstring {.
importc.}
proc toggleFlag*(flag: string) {.gcsafe, raises: [].} =
var argsJson = newJArray()
argsJson.add flag.toJson()
let argsJsonString = $argsJson
let res {.used.} = config_toggleFlag_void_ConfigService_string_wasm(
argsJsonString.cstring)

202 changes: 16 additions & 186 deletions scripting/editor_api_wasm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ import scripting_api, misc/myjsonutils
## This file is auto generated, don't modify.


proc editor_getOptionJson_JsonNode_ConfigService_string_JsonNode_wasm(
arg: cstring): cstring {.importc.}
proc getOptionJson*(path: string; default: JsonNode): JsonNode {.gcsafe,
raises: [].} =
var argsJson = newJArray()
argsJson.add path.toJson()
argsJson.add default.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_getOptionJson_JsonNode_ConfigService_string_JsonNode_wasm(
argsJsonString.cstring)
try:
result = parseJson($res).jsonTo(typeof(result))
except:
raiseAssert(getCurrentExceptionMsg())


proc editor_reapplyConfigKeybindings_void_App_bool_bool_bool_wasm(arg: cstring): cstring {.
importc.}
proc reapplyConfigKeybindings*(app: bool = false; home: bool = false;
Expand Down Expand Up @@ -241,52 +257,6 @@ proc openLocalWorkspace*(path: string) {.gcsafe, raises: [].} =
argsJsonString.cstring)


proc editor_getFlag_bool_App_string_bool_wasm(arg: cstring): cstring {.importc.}
proc getFlag*(flag: string; default: bool = false): bool {.gcsafe, raises: [].} =
var argsJson = newJArray()
argsJson.add flag.toJson()
argsJson.add default.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_getFlag_bool_App_string_bool_wasm(
argsJsonString.cstring)
try:
result = parseJson($res).jsonTo(typeof(result))
except:
raiseAssert(getCurrentExceptionMsg())


proc editor_setFlag_void_App_string_bool_wasm(arg: cstring): cstring {.importc.}
proc setFlag*(flag: string; value: bool) {.gcsafe, raises: [].} =
var argsJson = newJArray()
argsJson.add flag.toJson()
argsJson.add value.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_setFlag_void_App_string_bool_wasm(
argsJsonString.cstring)


proc editor_toggleFlag_void_App_string_wasm(arg: cstring): cstring {.importc.}
proc toggleFlag*(flag: string) {.gcsafe, raises: [].} =
var argsJson = newJArray()
argsJson.add flag.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_toggleFlag_void_App_string_wasm(
argsJsonString.cstring)


proc editor_setOption_void_App_string_JsonNode_bool_wasm(arg: cstring): cstring {.
importc.}
proc setOption*(option: string; value: JsonNode; override: bool = true) {.
gcsafe, raises: [].} =
var argsJson = newJArray()
argsJson.add option.toJson()
argsJson.add value.toJson()
argsJson.add override.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_setOption_void_App_string_JsonNode_bool_wasm(
argsJsonString.cstring)


proc editor_quit_void_App_wasm(arg: cstring): cstring {.importc.}
proc quit*() {.gcsafe, raises: [].} =
var argsJson = newJArray()
Expand Down Expand Up @@ -767,16 +737,6 @@ proc installTreesitterParser*(language: string; host: string = "github.com") {.
argsJsonString.cstring)


proc editor_chooseGitActiveFiles_void_App_bool_wasm(arg: cstring): cstring {.
importc.}
proc chooseGitActiveFiles*(all: bool = false) {.gcsafe, raises: [].} =
var argsJson = newJArray()
argsJson.add all.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_chooseGitActiveFiles_void_App_bool_wasm(
argsJsonString.cstring)


proc editor_exploreFiles_void_App_string_wasm(arg: cstring): cstring {.importc.}
proc exploreFiles*(root: string = "") {.gcsafe, raises: [].} =
var argsJson = newJArray()
Expand Down Expand Up @@ -884,13 +844,6 @@ proc saveSession*(sessionFile: string = "") {.gcsafe, raises: [].} =
argsJsonString.cstring)


proc editor_logOptions_void_App_wasm(arg: cstring): cstring {.importc.}
proc logOptions*() {.gcsafe, raises: [].} =
var argsJson = newJArray()
let argsJsonString = $argsJson
let res {.used.} = editor_logOptions_void_App_wasm(argsJsonString.cstring)


proc editor_dumpKeymapGraphViz_void_App_string_wasm(arg: cstring): cstring {.
importc.}
proc dumpKeymapGraphViz*(context: string = "") {.gcsafe, raises: [].} =
Expand Down Expand Up @@ -1290,129 +1243,6 @@ proc getSessionDataJson*(path: string; default: JsonNode): JsonNode {.gcsafe,
raiseAssert(getCurrentExceptionMsg())


proc editor_scriptGetOptionJson_JsonNode_string_JsonNode_wasm(arg: cstring): cstring {.
importc.}
proc scriptGetOptionJson*(path: string; default: JsonNode): JsonNode {.gcsafe,
raises: [].} =
var argsJson = newJArray()
argsJson.add path.toJson()
argsJson.add default.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_scriptGetOptionJson_JsonNode_string_JsonNode_wasm(
argsJsonString.cstring)
try:
result = parseJson($res).jsonTo(typeof(result))
except:
raiseAssert(getCurrentExceptionMsg())


proc editor_scriptGetOptionInt_int_string_int_wasm(arg: cstring): cstring {.
importc.}
proc scriptGetOptionInt*(path: string; default: int): int {.gcsafe, raises: [].} =
var argsJson = newJArray()
argsJson.add path.toJson()
argsJson.add default.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_scriptGetOptionInt_int_string_int_wasm(
argsJsonString.cstring)
try:
result = parseJson($res).jsonTo(typeof(result))
except:
raiseAssert(getCurrentExceptionMsg())


proc editor_scriptGetOptionFloat_float_string_float_wasm(arg: cstring): cstring {.
importc.}
proc scriptGetOptionFloat*(path: string; default: float): float {.gcsafe,
raises: [].} =
var argsJson = newJArray()
argsJson.add path.toJson()
argsJson.add default.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_scriptGetOptionFloat_float_string_float_wasm(
argsJsonString.cstring)
try:
result = parseJson($res).jsonTo(typeof(result))
except:
raiseAssert(getCurrentExceptionMsg())


proc editor_scriptGetOptionBool_bool_string_bool_wasm(arg: cstring): cstring {.
importc.}
proc scriptGetOptionBool*(path: string; default: bool): bool {.gcsafe,
raises: [].} =
var argsJson = newJArray()
argsJson.add path.toJson()
argsJson.add default.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_scriptGetOptionBool_bool_string_bool_wasm(
argsJsonString.cstring)
try:
result = parseJson($res).jsonTo(typeof(result))
except:
raiseAssert(getCurrentExceptionMsg())


proc editor_scriptGetOptionString_string_string_string_wasm(arg: cstring): cstring {.
importc.}
proc scriptGetOptionString*(path: string; default: string): string {.gcsafe,
raises: [].} =
var argsJson = newJArray()
argsJson.add path.toJson()
argsJson.add default.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_scriptGetOptionString_string_string_string_wasm(
argsJsonString.cstring)
try:
result = parseJson($res).jsonTo(typeof(result))
except:
raiseAssert(getCurrentExceptionMsg())


proc editor_scriptSetOptionInt_void_string_int_wasm(arg: cstring): cstring {.
importc.}
proc scriptSetOptionInt*(path: string; value: int) {.gcsafe, raises: [].} =
var argsJson = newJArray()
argsJson.add path.toJson()
argsJson.add value.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_scriptSetOptionInt_void_string_int_wasm(
argsJsonString.cstring)


proc editor_scriptSetOptionFloat_void_string_float_wasm(arg: cstring): cstring {.
importc.}
proc scriptSetOptionFloat*(path: string; value: float) {.gcsafe, raises: [].} =
var argsJson = newJArray()
argsJson.add path.toJson()
argsJson.add value.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_scriptSetOptionFloat_void_string_float_wasm(
argsJsonString.cstring)


proc editor_scriptSetOptionBool_void_string_bool_wasm(arg: cstring): cstring {.
importc.}
proc scriptSetOptionBool*(path: string; value: bool) {.gcsafe, raises: [].} =
var argsJson = newJArray()
argsJson.add path.toJson()
argsJson.add value.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_scriptSetOptionBool_void_string_bool_wasm(
argsJsonString.cstring)


proc editor_scriptSetOptionString_void_string_string_wasm(arg: cstring): cstring {.
importc.}
proc scriptSetOptionString*(path: string; value: string) {.gcsafe, raises: [].} =
var argsJson = newJArray()
argsJson.add path.toJson()
argsJson.add value.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_scriptSetOptionString_void_string_string_wasm(
argsJsonString.cstring)


proc editor_scriptSetCallback_void_string_int_wasm(arg: cstring): cstring {.
importc.}
proc scriptSetCallback*(path: string; id: int) {.gcsafe, raises: [].} =
Expand Down
4 changes: 4 additions & 0 deletions scripting/plugin_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export scripting_api

import collab_api_wasm
export collab_api_wasm
import config_api_wasm
export config_api_wasm
import debugger_api_wasm
export debugger_api_wasm
import editor_api_wasm
Expand All @@ -17,5 +19,7 @@ import lsp_api_wasm
export lsp_api_wasm
import popup_selector_api_wasm
export popup_selector_api_wasm
import vcs_api_wasm
export vcs_api_wasm

const enableAst* = false
30 changes: 5 additions & 25 deletions scripting/plugin_runtime.nim
Original file line number Diff line number Diff line change
Expand Up @@ -140,34 +140,14 @@ proc getLineCount*(editor: TextDocumentEditor): int =
return scriptGetTextEditorLineCount(editor.id)

proc getOption*[T](path: string, default: T = T.default): T =
when T is bool:
return scriptGetOptionBool(path, default).T
elif T is enum:
return parseEnum[T](scriptGetOptionString(path, ""), default)
elif T is Ordinal:
return scriptGetOptionInt(path, default).T
elif T is float32 | float64:
return scriptGetOptionFloat(path, default).T
elif T is string:
return scriptGetOptionString(path, default)
else:
let json: JsonNode = scriptGetOptionJson(path, newJNull())
try:
let json: JsonNode = plugin_api.getOptionJson(path, newJNull())
return json.jsonTo T
except:
return default

proc setOption*[T](path: string, value: T) =
# echo "setOption ", path, ", ", value
when T is bool:
scriptSetOptionBool(path, value)
elif T is enum:
scriptSetOptionString(path, $value)
elif T is Ordinal:
scriptSetOptionInt(path, value.int)
elif T is float32 | float64:
scriptSetOptionFloat(path, value.float64)
elif T is string:
scriptSetOptionString(path, value)
else:
{.fatal: ("Can't set option with type " & $T).}
plugin_api.setOption(path, value.toJson)

proc getSessionData*[T](path: string, default: T = T.default): T =
return getSessionDataJson(path, default.toJson).jsonTo(T)
Expand Down
15 changes: 15 additions & 0 deletions scripting/vcs_api_wasm.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import std/[json, options]
import scripting_api, misc/myjsonutils

## This file is auto generated, don't modify.


proc vcs_chooseGitActiveFiles_void_VCSService_bool_wasm(arg: cstring): cstring {.
importc.}
proc chooseGitActiveFiles*(all: bool = false) {.gcsafe, raises: [].} =
var argsJson = newJArray()
argsJson.add all.toJson()
let argsJsonString = $argsJson
let res {.used.} = vcs_chooseGitActiveFiles_void_VCSService_bool_wasm(
argsJsonString.cstring)

Loading

0 comments on commit cf618e8

Please sign in to comment.