Skip to content

Commit

Permalink
Fixed crash when closing log document
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed May 12, 2024
1 parent a5d69ba commit 3b5c9a4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 0 additions & 4 deletions src/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1576,10 +1576,6 @@ proc getEditorsForDocument(self: App, document: Document): seq[DocumentEditor] =
result.add editor

proc closeUnusedDocuments*(self: App) =
debugf"closeUnusedDocuments start"
defer:
debugf"closeUnusedDocuments done"

let documents = self.documents
for document in documents:
if document == self.logDocument:
Expand Down
12 changes: 5 additions & 7 deletions src/misc/custom_logger.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type
consoleLogger: Option[logging.Logger]
fileLogger: Option[FileLogger]

# proc indentString*(logger: CustomLogger): string =
# " ".repeat(logger.indentLevel)
proc indentString*(logger: CustomLogger): string =
" ".repeat(logger.indentLevel)

proc newCustomLogger*(levelThreshold = logging.lvlAll, fmtStr = logging.defaultFmtStr): CustomLogger =
new result
Expand Down Expand Up @@ -49,10 +49,9 @@ proc toggleConsoleLogger*(self: CustomLogger) =
let isTerminal {.used.} = when declared(isatty): isatty(stdout) else: false

method log(self: CustomLogger, level: logging.Level, args: varargs[string, `$`]) =
# let msg = self.indentString & substituteLog("", level, args)
let msg = self.indentString & logging.substituteLog("", level, args)
if self.fileLogger.getSome(l):
# logging.log(l, level, msg)
logging.log(l, level, args)
logging.log(l, level, msg)

if self.consoleLogger.getSome(l):
when not defined(js):
Expand All @@ -67,8 +66,7 @@ method log(self: CustomLogger, level: logging.Level, args: varargs[string, `$`])
else: rgb(255, 255, 255)
stdout.write(ansiForegroundColorCode(color))

# logging.log(l, level, msg)
logging.log(l, level, args)
logging.log(l, level, msg)

when not defined(js):
if isTerminal:
Expand Down
10 changes: 8 additions & 2 deletions src/text/text_editor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,14 @@ method deinit*(self: TextDocumentEditor) =
self.diffDocument.deinit()
self.diffDocument = nil

self.clearDocument()

if self.blinkCursorTask.isNotNil: self.blinkCursorTask.pause()
if self.updateCompletionsTask.isNotNil: self.updateCompletionsTask.pause()
if self.inlayHintsTask.isNotNil: self.inlayHintsTask.pause()
if self.showHoverTask.isNotNil: self.showHoverTask.pause()
if self.hideHoverTask.isNotNil: self.hideHoverTask.pause()

self.clearDocument()

if self.completionEngine.isNotNil:
self.completionEngine.onCompletionsUpdated.unsubscribe(self.onCompletionsUpdatedHandle)

Expand Down Expand Up @@ -2603,7 +2603,13 @@ proc showHoverForDelayed*(self: TextDocumentEditor, cursor: Cursor) =
self.markDirty()

proc updateInlayHintsAsync*(self: TextDocumentEditor): Future[void] {.async.} =
if self.document.isNil:
return

if self.document.getLanguageServer().await.getSome(ls):
if self.document.isNil:
return

let visibleRange = self.visibleTextRange(self.screenLineCount)
let inlayHints = await ls.getInlayHints(self.document.fullPath, visibleRange)
# todo: detect if canceled instead
Expand Down

0 comments on commit 3b5c9a4

Please sign in to comment.