nimfind: improvements
This commit is contained in:
parent
632ec94b5d
commit
2104863910
2 changed files with 18 additions and 10 deletions
|
|
@ -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 ...
|
# for instance 'nextTry' is both in tables.nim and astalgo.nim ...
|
||||||
result = newSymNode(s, n.info)
|
result = newSymNode(s, n.info)
|
||||||
markUsed(c.config, n.info, s, c.graph.usageSym)
|
markUsed(c.config, n.info, s, c.graph.usageSym)
|
||||||
|
onUse(n.info, s)
|
||||||
else:
|
else:
|
||||||
# semantic checking requires a type; ``fitNode`` deals with it
|
# semantic checking requires a type; ``fitNode`` deals with it
|
||||||
# appropriately
|
# appropriately
|
||||||
|
|
@ -75,6 +76,7 @@ proc symChoice(c: PContext, n: PNode, s: PSym, r: TSymChoiceRule): PNode =
|
||||||
if a.kind != skModule:
|
if a.kind != skModule:
|
||||||
incl(a.flags, sfUsed)
|
incl(a.flags, sfUsed)
|
||||||
addSon(result, newSymNode(a, n.info))
|
addSon(result, newSymNode(a, n.info))
|
||||||
|
onUse(n.info, a)
|
||||||
a = nextOverloadIter(o, c, n)
|
a = nextOverloadIter(o, c, n)
|
||||||
|
|
||||||
proc semBindStmt(c: PContext, n: PNode, toBind: var IntSet): PNode =
|
proc semBindStmt(c: PContext, n: PNode, toBind: var IntSet): PNode =
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ proc createDb(db: DbConn) =
|
||||||
nimid integer not null,
|
nimid integer not null,
|
||||||
line integer not null,
|
line integer not null,
|
||||||
col integer not null,
|
col integer not null,
|
||||||
|
colB integer not null,
|
||||||
file integer not null,
|
file integer not null,
|
||||||
foreign key (file) references filenames(id),
|
foreign key (file) references filenames(id),
|
||||||
foreign key (nimid) references syms(nimid)
|
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) =
|
proc writeUsage(graph: ModuleGraph; s: PSym; info: TLineInfo) =
|
||||||
let f = FinderRef(graph.backend)
|
let f = FinderRef(graph.backend)
|
||||||
f.db.exec(sql"""insert into usages(nimid, line, col, file) values (?, ?, ?, ?)""",
|
f.db.exec(sql"""insert into usages(nimid, line, col, colB, file) values (?, ?, ?, ?, ?)""",
|
||||||
s.id, info.line, info.col,
|
s.id, info.line, info.col, info.col + s.name.s.len - 1,
|
||||||
toDbFileId(f.db, graph.config, info.fileIndex))
|
toDbFileId(f.db, graph.config, info.fileIndex))
|
||||||
|
|
||||||
proc performSearch(conf: ConfigRef; dbfile: AbsoluteFile) =
|
proc performSearch(conf: ConfigRef; dbfile: AbsoluteFile) =
|
||||||
|
|
@ -117,22 +118,27 @@ proc performSearch(conf: ConfigRef; dbfile: AbsoluteFile) =
|
||||||
database="nim")
|
database="nim")
|
||||||
let pos = conf.m.trackPos
|
let pos = conf.m.trackPos
|
||||||
let fid = toDbFileId(db, conf, pos.fileIndex)
|
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)
|
pos.line, fid, pos.col)
|
||||||
if row.len > 0:
|
if nimids.len > 0:
|
||||||
let known = toFullPath(conf, pos.fileIndex)
|
var idSet = ""
|
||||||
let nimid = db.getRow(sql"""select nimid from usages where line = ? and file = ? and col = ?""",
|
for id in nimids:
|
||||||
pos.line, fid, row[0])
|
if idSet.len > 0: idSet.add ", "
|
||||||
|
idSet.add id
|
||||||
|
var outputLater = ""
|
||||||
for r in db.rows(sql"""select line, col, filenames.fullpath from usages
|
for r in db.rows(sql"""select line, col, filenames.fullpath from usages
|
||||||
inner join filenames on filenames.id = file
|
inner join filenames on filenames.id = file
|
||||||
where nimid = ?""", nimid):
|
where nimid in (?)""", idSet):
|
||||||
let line = parseInt(r[0])
|
let line = parseInt(r[0])
|
||||||
let col = parseInt(r[1])
|
let col = parseInt(r[1])
|
||||||
let file = r[2]
|
let file = r[2]
|
||||||
if file == known and line == pos.line.int:
|
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:
|
else:
|
||||||
echo file, ":", line, ":", col+1
|
echo file, ":", line, ":", col+1
|
||||||
|
if outputLater.len > 0: stdout.write outputLater
|
||||||
close(db)
|
close(db)
|
||||||
|
|
||||||
proc setupDb(g: ModuleGraph; dbfile: AbsoluteFile) =
|
proc setupDb(g: ModuleGraph; dbfile: AbsoluteFile) =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue