NIF-based goto-definition / find-all-usages for nim track.
This is the mainline-Nim port of nimony's idetools.nim. It answers a --def:FILE,LINE,COL / --usages:FILE,LINE,COL query by scanning the `.s.bif` files (binary NIF, see dist/nimony/src/lib/bif.nim) that the preceding nim ic frontend (nim track) emitted into the nimcache directory — NOT by re-running sem. NIF distinguishes a definition (SymbolDef token) from a use (Symbol token) syntactically, so goto-def / find-uses become plain token scans over type-checked NIF, which is more reliable than the classic PSym engine because generics and macros are type-checked in the NIF too.
Two passes (mirroring nimony's usages):
- Load the queried module's .s.bif and find the Symbol/SymbolDef token whose line info + identifier length contains conf.m.trackPos. That yields the mangled symbol NAME and whether it is global (>= 2 dots).
- --usages: emit every Symbol (use) token; --def: every SymbolDef. A global symbol is scanned across every module .s.bif; a local one only within the queried module.
IMPORTANT porting note: bif.load mints FRESH per-file pools, so a SymId from module A's buffer is meaningless in module B's. The cross-module match is therefore by the mangled NAME string, never by SymId (nimony can compare ids because it parses every text NIF into one shared global pool; we cannot).
Procs
proc runIdeQuery(conf: ConfigRef) {....raises: [OSError, Exception, KeyError, ValueError, IOError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, RootEffect, WriteIOEffect], forbids: [].}
- Entry point: called from main.nim after commandCheck when a --def/--usages query is active. Assumes the check just emitted the project's .s.bif files into getNimcacheDir(conf). Source Edit