Skip to content

Commit

Permalink
Gets the nimsuggest path from nimble when nimble has nimdir
Browse files Browse the repository at this point in the history
This depends on nim-lang/nimble#1221
It also needs to be tested in Win.

While developing this found an issue with the project discovery, it uses `nim dump` but it doesnt seem to end when Nim is a local dep, it takes too long. Will try to speed it up in the nimble side of things
  • Loading branch information
jmgomez committed May 22, 2024
1 parent 97ffd6d commit 2bef5bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
18 changes: 17 additions & 1 deletion nimlangserver.nim
Original file line number Diff line number Diff line change
Expand Up @@ -665,12 +665,28 @@ proc getWorkingDir(ls: LanguageServer, path: string): Future[string] {.async.} =
result = rootPath.string / m.directory
break;

proc getNimSuggestPath(ls: LanguageServer, conf: NlsConfig, workingDir: string): string =
#Attempting to see if the project is using a custom Nim version, if it's the case this will be slower than usual
let info: string = execProcess("nimble --nimdir ", workingDir)
var nimDir = ""
const NimDirSplit = "nimdir:"
for line in info.splitLines:
if NimDirSplit in line:
nimDir = line.split(NimDirSplit)[1].strip()

result = expandTilde(conf.nimsuggestPath.get(""))
if result == "":
if nimDir != "" and nimDir.dirExists:
ls.showMessage(fmt "Using nimsuggest from your nimble project", MessageType.Info)
result = nimDir / "nimsuggest" #TODO test on win
else:
result = findExe "nimsuggest"

proc createOrRestartNimsuggest(ls: LanguageServer, projectFile: string, uri = ""): void {.gcsafe.} =
let
configuration = ls.getWorkspaceConfiguration().waitFor()
nimsuggestPath = expandTilde(configuration.nimsuggestPath.get("nimsuggest"))
workingDir = ls.getWorkingDir(projectFile).waitFor()
nimsuggestPath = ls.getNimSuggestPath(configuration, workingDir)
timeout = configuration.timeout.get(REQUEST_TIMEOUT)
restartCallback = proc (ns: Nimsuggest) {.gcsafe.} =
warn "Restarting the server due to requests being to slow", projectFile = projectFile
Expand Down
7 changes: 3 additions & 4 deletions suggestapi.nim
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,9 @@ proc createNimsuggest*(root: string,
thread: Thread[tuple[pipe: AsyncPipe, process: Process]]
stderrThread: Thread[tuple[root: string, process: Process]]
input = pipe.asyncPipeInput
fullPath = findExe(nimsuggestPath)

info "Starting nimsuggest", root = root, timeout = timeout, path = nimsuggestPath,
fullPath = fullPath, workingDir = workingDir
info "Starting nimsuggest", root = root, timeout = timeout, path = nimsuggestPath,
workingDir = workingDir

result = Nimsuggest()
result.requestQueue = Deque[SuggestCall]()
Expand All @@ -332,7 +331,7 @@ proc createNimsuggest*(root: string,
result.timeoutCallback = timeoutCallback
result.errorCallback = errorCallback

if fullPath != "":
if nimsuggestPath != "":
result.protocolVersion = detectNimsuggestVersion(root, nimsuggestPath, workingDir)
if result.protocolVersion > HighestSupportedNimSuggestProtocolVersion:
result.protocolVersion = HighestSupportedNimSuggestProtocolVersion
Expand Down

0 comments on commit 2bef5bd

Please sign in to comment.