Skip to content

WIP: tracking support for IDE integration #923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/nimony/nifconfig.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import platform
include nifprelude

type
TrackPosition* = object
line*, col*: int
filename*: string

NifConfig* = object
defines*: HashSet[string]
paths*, nimblePaths*: seq[string]
Expand All @@ -22,6 +26,7 @@ type
compat*: bool
targetCPU*: TSystemCPU
targetOS*: TSystemOS
toTrack*: seq[TrackPosition]

proc initNifConfig*(): NifConfig =
result = NifConfig()
Expand Down
27 changes: 26 additions & 1 deletion src/nimony/nimony.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const
Version = "0.2"
Usage = "Nimony Compiler. Version " & Version & """

(c) 2024 Andreas Rumpf
(c) 2024-2025 Andreas Rumpf
Usage:
nimony [options] [command]
Command:
Expand All @@ -40,6 +40,7 @@ Options:
--silentMake suppresses make output
--nimcache:PATH set the path used for generated files
--boundchecks:on|off turn bound checks on or off
--track:file,line,col track the given position for editor integration
--version show the version
--help show this help
"""
Expand All @@ -58,6 +59,27 @@ proc processSingleModule(nimFile: string; config: sink NifConfig; moduleFlags: s
quoteShell(src)
semcheck(src, dest, ensureMove config, moduleFlags, commandLineArgs, true)

proc parseTrack(s: string): TrackPosition =
# --------------------------------------------------------------------------
# Format: file,line,col
# --------------------------------------------------------------------------
var i = 0
var line = 0
var col = 0
while i < s.len and s[i] != ',':
inc i
let filenameEnd = i
if i < s.len and s[i] == ',': inc i

while i < s.len and s[i] in {'0'..'9'}:
line = line * 10 + (ord(s[i]) - ord('0'))
inc i
if i < s.len and s[i] == ',': inc i
while i < s.len and s[i] in {'0'..'9'}:
col = col * 10 + (ord(s[i]) - ord('0'))
inc i
result = TrackPosition(line: line, col: col, filename: s.substr(0, filenameEnd-1))

type
Command = enum
None, SingleModule, FullProject
Expand Down Expand Up @@ -146,6 +168,9 @@ proc handleCmdLine() =
of "nimcache":
config.nifcachePath = val
forwardArgNifc = true
of "track":
config.toTrack.add parseTrack(val)
forwardArg = false
else: writeHelp()
if forwardArg:
commandLineArgs.add " --" & key
Expand Down