Skip to content

Commit

Permalink
Retrieves the version at compile time
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgomez committed Jan 26, 2024
1 parent fdcd323 commit 6d9c8ff
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions nimlangserver.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import macros, strformat, faststreams/async_backend,
json_rpc/streamconnection, os, sugar, sequtils, hashes, osproc,
suggestapi, protocol/enums, protocol/types, with, tables, strutils, sets,
./utils, ./pipes, chronicles, std/re, uri, "$nim/compiler/pathutils",
procmonitor, std/strscans, parsecfg, json_serialization, serialization/formats
procmonitor, std/strscans, json_serialization, serialization/formats


const
Expand Down Expand Up @@ -1131,10 +1131,18 @@ proc ensureStorageDir*: string =
discard existsOrCreateDir(result)

when isMainModule:

proc getVersionFromNimble(): string =
const content = staticRead("nimlangserver.nimble")
for v in content.splitLines:
if v.startsWith("version"):
return v.split("=")[^1].strip(chars = {' ', '"'})
return "unknown"

proc handleParams() =
if paramCount() > 0 and paramStr(1) in ["-v", "--version"]:
let p = loadConfig(getAppDir() / "nimlangserver.nimble")
echo p.getSectionValue("", "version")
const version = getVersionFromNimble()
echo version
quit()

proc main =
Expand Down

0 comments on commit 6d9c8ff

Please sign in to comment.