Skip to content

Commit 48ab0d6

Browse files
authored
Adds max fails to ns (#299)
1 parent 7d19194 commit 48ab0d6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

ls.nim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ type
172172
stdinContext*: ptr ReadStdinContext
173173
projectErrors*: seq[ProjectError]
174174
lastStatusSent: JsonNode
175+
failTable*: Table[string, int]
176+
#Project file to fail count
175177
#List of errors (crashes) nimsuggest has had since the lsp session started
176178

177179
Certainty* = enum
@@ -772,6 +774,16 @@ proc getNimsuggestInner(ls: LanguageServer, uri: string): Future[Nimsuggest] {.a
772774
uri = uri, projectFile = projectFileReused
773775
return await ls.projectFiles[projectFileReused].ns
774776

777+
const MaxFails = 10
778+
if projectFile in ls.failTable and ls.failTable[projectFile] >= MaxFails:
779+
let nextNs = ls.projectFiles.keys.toSeq.filterIt(it != projectFile)
780+
if nextNs.len > 0:
781+
let nextNs = nextNs[0]
782+
debug "Reusing nimsuggest instance for", uri = uri, projectFile = nextNs
783+
return await ls.projectFiles[nextNs].ns
784+
else:
785+
return nil
786+
775787
# Check multiple times with small delays
776788
var attempts = 0
777789
const maxAttempts = 10
@@ -977,6 +989,8 @@ proc onErrorCallback(args: (LanguageServer, string), project: Project) =
977989
ls = args[0]
978990
uri = args[1]
979991
debug "NimSuggest needed to be restarted due to an error "
992+
ls.failTable[project.file] = ls.failTable.getOrDefault(project.file, 0) + 1
993+
debug "Fail count", count = ls.failTable[project.file]
980994
let configuration = ls.getWorkspaceConfiguration().waitFor()
981995
warn "Server stopped.", projectFile = project.file
982996
try:

0 commit comments

Comments
 (0)