Skip to content

Commit

Permalink
Adds Nim version to the notification so the user knows what version i…
Browse files Browse the repository at this point in the history
…s used
  • Loading branch information
jmgomez committed May 23, 2024
1 parent acbaf8a commit 8cc9e61
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion nimlangserver.nim
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,16 @@ proc getWorkingDir(ls: LanguageServer, path: string): Future[string] {.async.} =
result = rootPath.string / m.directory
break;

proc getNimVersion(nimDir: string): string =
let cmd =
if nimDir == "": "nim --version"
else: nimDir / "nim --version"
let info = execProcess(cmd)
const NimCompilerVersion = "Nim Compiler Version "
for line in info.splitLines:
if line.startsWith(NimCompilerVersion):
return line

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)
Expand All @@ -675,12 +685,15 @@ proc getNimSuggestPath(ls: LanguageServer, conf: NlsConfig, workingDir: string):
nimDir = line.split(NimDirSplit)[1].strip()

result = expandTilde(conf.nimsuggestPath.get(""))
var nimVersion = ""
if result == "":
if nimDir != "" and nimDir.dirExists:
ls.showMessage(fmt "Using nimsuggest from your nimble project", MessageType.Info)
nimVersion = getNimVersion(nimDir) & " from " & nimDir
result = nimDir / "nimsuggest"
else:
nimVersion = getNimVersion("")
result = findExe "nimsuggest"
ls.showMessage(fmt "Using {nimVersion}", MessageType.Info)

proc createOrRestartNimsuggest(ls: LanguageServer, projectFile: string, uri = ""): void {.gcsafe.} =
let
Expand Down

0 comments on commit 8cc9e61

Please sign in to comment.