Moved some code around in nimsuggest to avoid crash when run as library (#9818)
* Moved some code around in nimsuggest to avoid crash when run as library * Moved the common executecallback setting to a procedure * Fixed slight issue
This commit is contained in:
parent
abbafe606e
commit
3f546b70ed
1 changed files with 22 additions and 8 deletions
|
|
@ -159,19 +159,13 @@ proc symFromInfo(graph: ModuleGraph; trackPos: TLineInfo): PSym =
|
||||||
if m != nil and m.ast != nil:
|
if m != nil and m.ast != nil:
|
||||||
result = findNode(m.ast, trackPos)
|
result = findNode(m.ast, trackPos)
|
||||||
|
|
||||||
proc execute(cmd: IdeCmd, file, dirtyfile: AbsoluteFile, line, col: int;
|
proc executeNoHooks(cmd: IdeCmd, file, dirtyfile: AbsoluteFile, line, col: int;
|
||||||
graph: ModuleGraph) =
|
graph: ModuleGraph) =
|
||||||
let conf = graph.config
|
let conf = graph.config
|
||||||
myLog("cmd: " & $cmd & ", file: " & file.string &
|
myLog("cmd: " & $cmd & ", file: " & file.string &
|
||||||
", dirtyFile: " & dirtyfile.string &
|
", dirtyFile: " & dirtyfile.string &
|
||||||
"[" & $line & ":" & $col & "]")
|
"[" & $line & ":" & $col & "]")
|
||||||
conf.ideCmd = cmd
|
conf.ideCmd = cmd
|
||||||
if cmd == ideChk:
|
|
||||||
conf.structuredErrorHook = errorHook
|
|
||||||
conf.writelnHook = myLog
|
|
||||||
else:
|
|
||||||
conf.structuredErrorHook = nil
|
|
||||||
conf.writelnHook = myLog
|
|
||||||
if cmd == ideUse and conf.suggestVersion != 0:
|
if cmd == ideUse and conf.suggestVersion != 0:
|
||||||
graph.resetAllModules()
|
graph.resetAllModules()
|
||||||
var isKnownFile = true
|
var isKnownFile = true
|
||||||
|
|
@ -204,6 +198,16 @@ proc execute(cmd: IdeCmd, file, dirtyfile: AbsoluteFile, line, col: int;
|
||||||
else:
|
else:
|
||||||
localError(conf, conf.m.trackPos, "found no symbol at this position " & (conf $ conf.m.trackPos))
|
localError(conf, conf.m.trackPos, "found no symbol at this position " & (conf $ conf.m.trackPos))
|
||||||
|
|
||||||
|
proc execute(cmd: IdeCmd, file, dirtyfile: AbsoluteFile, line, col: int;
|
||||||
|
graph: ModuleGraph) =
|
||||||
|
if cmd == ideChk:
|
||||||
|
graph.config.structuredErrorHook = errorHook
|
||||||
|
graph.config.writelnHook = myLog
|
||||||
|
else:
|
||||||
|
graph.config.structuredErrorHook = nil
|
||||||
|
graph.config.writelnHook = myLog
|
||||||
|
executeNoHooks(cmd, file, dirtyfile, line, col, graph)
|
||||||
|
|
||||||
proc executeEpc(cmd: IdeCmd, args: SexpNode;
|
proc executeEpc(cmd: IdeCmd, args: SexpNode;
|
||||||
graph: ModuleGraph) =
|
graph: ModuleGraph) =
|
||||||
let
|
let
|
||||||
|
|
@ -707,10 +711,20 @@ else:
|
||||||
retval.add(Suggest(section: ideMsg, doc: line))
|
retval.add(Suggest(section: ideMsg, doc: line))
|
||||||
conf.suggestionResultHook = proc (s: Suggest) =
|
conf.suggestionResultHook = proc (s: Suggest) =
|
||||||
retval.add(s)
|
retval.add(s)
|
||||||
|
conf.writelnHook = proc (s: string) =
|
||||||
|
stderr.write s & "\n"
|
||||||
if conf.ideCmd == ideKnown:
|
if conf.ideCmd == ideKnown:
|
||||||
retval.add(Suggest(section: ideKnown, quality: ord(fileInfoKnown(conf, file))))
|
retval.add(Suggest(section: ideKnown, quality: ord(fileInfoKnown(conf, file))))
|
||||||
else:
|
else:
|
||||||
if conf.ideCmd == ideChk:
|
if conf.ideCmd == ideChk:
|
||||||
for cm in nimsuggest.cachedMsgs: errorHook(conf, cm.info, cm.msg, cm.sev)
|
for cm in nimsuggest.cachedMsgs: errorHook(conf, cm.info, cm.msg, cm.sev)
|
||||||
execute(conf.ideCmd, file, dirtyfile, line, col, nimsuggest.graph)
|
if conf.ideCmd == ideChk:
|
||||||
|
conf.structuredErrorHook = proc (conf: ConfigRef; info: TLineInfo; msg: string; sev: Severity) =
|
||||||
|
retval.add(Suggest(section: ideChk, filePath: toFullPath(conf, info),
|
||||||
|
line: toLinenumber(info), column: toColumn(info), doc: msg,
|
||||||
|
forth: $sev))
|
||||||
|
|
||||||
|
else:
|
||||||
|
conf.structuredErrorHook = nil
|
||||||
|
executeNoHooks(conf.ideCmd, file, dirtyfile, line, col, nimsuggest.graph)
|
||||||
return retval
|
return retval
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue