mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 23:54:19 +00:00
nimfind: improvements
This commit is contained in:
@@ -64,6 +64,7 @@ proc symChoice(c: PContext, n: PNode, s: PSym, r: TSymChoiceRule): PNode =
|
||||
# for instance 'nextTry' is both in tables.nim and astalgo.nim ...
|
||||
result = newSymNode(s, n.info)
|
||||
markUsed(c.config, n.info, s, c.graph.usageSym)
|
||||
onUse(n.info, s)
|
||||
else:
|
||||
# semantic checking requires a type; ``fitNode`` deals with it
|
||||
# appropriately
|
||||
@@ -75,6 +76,7 @@ proc symChoice(c: PContext, n: PNode, s: PSym, r: TSymChoiceRule): PNode =
|
||||
if a.kind != skModule:
|
||||
incl(a.flags, sfUsed)
|
||||
addSon(result, newSymNode(a, n.info))
|
||||
onUse(n.info, a)
|
||||
a = nextOverloadIter(o, c, n)
|
||||
|
||||
proc semBindStmt(c: PContext, n: PNode, toBind: var IntSet): PNode =
|
||||
|
||||
@@ -72,6 +72,7 @@ proc createDb(db: DbConn) =
|
||||
nimid integer not null,
|
||||
line integer not null,
|
||||
col integer not null,
|
||||
colB integer not null,
|
||||
file integer not null,
|
||||
foreign key (file) references filenames(id),
|
||||
foreign key (nimid) references syms(nimid)
|
||||
@@ -108,8 +109,8 @@ proc writeDefResolveForward(graph: ModuleGraph; s: PSym; info: TLineInfo) =
|
||||
|
||||
proc writeUsage(graph: ModuleGraph; s: PSym; info: TLineInfo) =
|
||||
let f = FinderRef(graph.backend)
|
||||
f.db.exec(sql"""insert into usages(nimid, line, col, file) values (?, ?, ?, ?)""",
|
||||
s.id, info.line, info.col,
|
||||
f.db.exec(sql"""insert into usages(nimid, line, col, colB, file) values (?, ?, ?, ?, ?)""",
|
||||
s.id, info.line, info.col, info.col + s.name.s.len - 1,
|
||||
toDbFileId(f.db, graph.config, info.fileIndex))
|
||||
|
||||
proc performSearch(conf: ConfigRef; dbfile: AbsoluteFile) =
|
||||
@@ -117,22 +118,27 @@ proc performSearch(conf: ConfigRef; dbfile: AbsoluteFile) =
|
||||
database="nim")
|
||||
let pos = conf.m.trackPos
|
||||
let fid = toDbFileId(db, conf, pos.fileIndex)
|
||||
var row = db.getRow(sql"""select max(col) from usages where line = ? and file = ? and ? >= col""",
|
||||
let known = toFullPath(conf, pos.fileIndex)
|
||||
let nimids = db.getRow(sql"""select distinct nimid from usages where line = ? and file = ? and ? between col and colB""",
|
||||
pos.line, fid, pos.col)
|
||||
if row.len > 0:
|
||||
let known = toFullPath(conf, pos.fileIndex)
|
||||
let nimid = db.getRow(sql"""select nimid from usages where line = ? and file = ? and col = ?""",
|
||||
pos.line, fid, row[0])
|
||||
if nimids.len > 0:
|
||||
var idSet = ""
|
||||
for id in nimids:
|
||||
if idSet.len > 0: idSet.add ", "
|
||||
idSet.add id
|
||||
var outputLater = ""
|
||||
for r in db.rows(sql"""select line, col, filenames.fullpath from usages
|
||||
inner join filenames on filenames.id = file
|
||||
where nimid = ?""", nimid):
|
||||
inner join filenames on filenames.id = file
|
||||
where nimid in (?)""", idSet):
|
||||
let line = parseInt(r[0])
|
||||
let col = parseInt(r[1])
|
||||
let file = r[2]
|
||||
if file == known and line == pos.line.int:
|
||||
discard "don't output the line we already know"
|
||||
# output the line we already know last:
|
||||
outputLater.add file & ":" & $line & ":" & $(col+1) & "\n"
|
||||
else:
|
||||
echo file, ":", line, ":", col+1
|
||||
if outputLater.len > 0: stdout.write outputLater
|
||||
close(db)
|
||||
|
||||
proc setupDb(g: ModuleGraph; dbfile: AbsoluteFile) =
|
||||
|
||||
Reference in New Issue
Block a user