diff --git a/config.nims b/config.nims index bd743434..b6c94124 100644 --- a/config.nims +++ b/config.nims @@ -15,20 +15,35 @@ switch("d", "allowConsoleLogger") switch("d", "wasm3HasWasi") switch("d", "wasm3VerboseErrorMessages") + +# switches for debugging # switch("d", "wasm3EnableStrace2") # switch("d", "wasm3RecordBacktraces") - # switch("d", "wasm3LogModule") # switch("d", "wasm3LogCompile") # switch("d", "wasm3LogParse") # switch("d", "wasm3LogRuntime") # switch("d", "uiNodeDebugData") +# switch("d", "futureLogging") +# switch("d", "nimBurnFree") +# switch("d", "nimArcIds") +# switch("d", "traceArc") +# switch("d", "nimTypeNames") + +# checks +# --objChecks:off +# --fieldChecks:off +# --rangeChecks:off +# --boundChecks:off +# --overflowChecks:off +# --floatChecks:off +# --nanChecks:off +# --infChecks:off # switch("cc", "vcc") # switch("nimcache", "D:\\nc") -let mode = 0 -case mode +case 0 of 0: switch("d", "release") of 1: @@ -39,11 +54,11 @@ of 2: switch("cc", "vcc") switch("d", "debug") switch("debuginfo", "on") - switch("nimcache", "nimcache") of 3: switch("d", "release") switch("debuginfo", "on") - switch("cc", "vcc") + switch("stackTrace", "on") + switch("lineTrace", "on") switch("nimcache", "D:\\nc") else: discard diff --git a/src/absytree_dynlib.nim b/src/absytree_dynlib.nim index 09040014..d3de8ee0 100644 --- a/src/absytree_dynlib.nim +++ b/src/absytree_dynlib.nim @@ -14,7 +14,7 @@ else: static: echo "Compiling for unknown" -import std/[parseopt, options, macros] +import std/[parseopt, options, macros, tables] import misc/[custom_logger] import compilation_config, scripting_api, app_options @@ -85,10 +85,12 @@ proc shutdown() = if gApp.isNotNil: log lvlInfo, "Shutting down editor" gApp.shutdown() + gApp = nil if rend.isNotNil: log lvlInfo, "Shutting down platform" rend.deinit() + rend = nil proc NimMain() {.cdecl, importc.} @@ -108,6 +110,18 @@ proc absytree_poll(timeoutMs: int32) {.exportc, dynlib, cdecl.} = proc absytree_shutdown() {.exportc, dynlib, cdecl.} = echo "Shutting down Absytree..." shutdown() + + when isFutureLoggingEnabled: + while hasPendingOperations(): + debugf"Futures in progress:" + debugf"----------------------------" + for (info, x) in getFuturesInProgress().pairs: + debugf"{info.fromProc}: {info.stackTrace}" + debugf"----------------------------" + drain(100) + + else: + drain(10000) GC_FullCollect() proc absytree_input_keys*(self: ptr AppObject, input: cstring) {.exportc, dynlib, cdecl.} = diff --git a/src/ast/lang/cell_language.nim b/src/ast/lang/cell_language.nim index a0b3fe57..46fcf443 100644 --- a/src/ast/lang/cell_language.nim +++ b/src/ast/lang/cell_language.nim @@ -217,7 +217,7 @@ proc createCellLanguage*(): Future[Language] {.async.} = log lvlError, "createCellLanguage: Failed to load cell builder model" return Language nil - var language = createLanguageFromModel(model).await + var language = createLanguageFromModel(model, createBuilder = false).await language.name = "Cells" language.scopeComputers = scopeComputers return language diff --git a/src/ast/lang/lang_builder.nim b/src/ast/lang/lang_builder.nim index 0bd8f8c0..460bc7a1 100644 --- a/src/ast/lang/lang_builder.nim +++ b/src/ast/lang/lang_builder.nim @@ -462,12 +462,12 @@ proc updateLanguageFromModel*(language: Language, model: Model, updateBuilder: b return true -proc createLanguageFromModel*(model: Model, ctx = ModelComputationContextBase.none): Future[Language] {.async.} = +proc createLanguageFromModel*(model: Model, ctx = ModelComputationContextBase.none, createBuilder: bool = true): Future[Language] {.async.} = log lvlInfo, fmt"createLanguageFromModel {model.path} ({model.id})" let name = model.path.splitFile.name let language = newLanguage(model.id.LanguageId, name) - if not language.updateLanguageFromModel(model, ctx = ctx).await: + if not language.updateLanguageFromModel(model, ctx = ctx, updateBuilder = createBuilder).await: return Language nil return language diff --git a/src/ast/model.nim b/src/ast/model.nim index 5756adc3..48acd704 100644 --- a/src/ast/model.nim +++ b/src/ast/model.nim @@ -60,7 +60,7 @@ type role*: string class*: ClassId - NodeClass* = ref object + NodeClass* {.acyclic.} = ref object id {.getter.}: ClassId name {.getter.}: string alias {.getter.}: string @@ -78,13 +78,13 @@ type canBeRoot {.getter.}: bool registryIndex: int32 # Index in the global node registry (0 if not registered) - AstNode* = ref object + AstNode* {.acyclic.} = ref object id*: NodeId class*: ClassId registryIndex: int32 # Index in the global node registry (0 if not registered) model*: Model # gets set when inserted into a parent node which is in a model, or when inserted into a model - parent*: AstNode # gets set when inserted into a parent node + parent* {.cursor.}: AstNode # gets set when inserted into a parent node role*: RoleId # gets set when inserted into a parent node properties*: seq[tuple[role: RoleId, value: PropertyValue]] @@ -111,7 +111,7 @@ type ModelComputationContextBase* = ref object of RootObj - Language* = ref object + Language* {.acyclic.} = ref object name* : string id {.getter.}: LanguageId version {.getter.}: int diff --git a/src/ast/project.nim b/src/ast/project.nim index 01cfc467..1d3f515b 100644 --- a/src/ast/project.nim +++ b/src/ast/project.nim @@ -52,7 +52,10 @@ proc loadModelAsync*(project: Project, path: string): Future[Option[Model]] {.as let ws = getProjectWorkspace().await let jsonText = ws.loadFile(path).await - let json = jsonText.parseJson + + let json = jsonText.parseJson.catch: + log lvlError, &"project.loadModelAsync: Failed to parse json: {getCurrentExceptionMsg()}\n{getCurrentException().getStackTrace()}" + return Model.none var model = newModel() if not model.loadFromJsonAsync(project, ws, path, json, resolveLanguage, resolveModel).await: diff --git a/src/text/language/lsp_client.nim b/src/text/language/lsp_client.nim index 03012358..e50518b7 100644 --- a/src/text/language/lsp_client.nim +++ b/src/text/language/lsp_client.nim @@ -110,7 +110,7 @@ proc parseResponse(client: LSPClient): Future[JsonNode] {.async.} = if client.connection.isNil: log(lvlError, "[parseResponse] Connection is nil") - return nil + return JsonNode(nil) var success = true var lines = @[line]