nimsuggest: add a command that returns the project file (#12411)
This can be used to let nimsuggest users know which project is nimsuggest being in charge of, so they can know when should a new nimsuggest instance be spawned. An additional feature is to debug the project file finding feature.
This commit is contained in:
parent
eeffa0163f
commit
f957266574
2 changed files with 13 additions and 2 deletions
|
|
@ -118,7 +118,7 @@ type
|
||||||
|
|
||||||
IdeCmd* = enum
|
IdeCmd* = enum
|
||||||
ideNone, ideSug, ideCon, ideDef, ideUse, ideDus, ideChk, ideMod,
|
ideNone, ideSug, ideCon, ideDef, ideUse, ideDus, ideChk, ideMod,
|
||||||
ideHighlight, ideOutline, ideKnown, ideMsg
|
ideHighlight, ideOutline, ideKnown, ideMsg, ideProject
|
||||||
|
|
||||||
Feature* = enum ## experimental features; DO NOT RENAME THESE!
|
Feature* = enum ## experimental features; DO NOT RENAME THESE!
|
||||||
implicitDeref,
|
implicitDeref,
|
||||||
|
|
@ -709,6 +709,7 @@ proc parseIdeCmd*(s: string): IdeCmd =
|
||||||
of "outline": ideOutline
|
of "outline": ideOutline
|
||||||
of "known": ideKnown
|
of "known": ideKnown
|
||||||
of "msg": ideMsg
|
of "msg": ideMsg
|
||||||
|
of "project": ideProject
|
||||||
else: ideNone
|
else: ideNone
|
||||||
|
|
||||||
proc `$`*(c: IdeCmd): string =
|
proc `$`*(c: IdeCmd): string =
|
||||||
|
|
@ -725,6 +726,7 @@ proc `$`*(c: IdeCmd): string =
|
||||||
of ideOutline: "outline"
|
of ideOutline: "outline"
|
||||||
of ideKnown: "known"
|
of ideKnown: "known"
|
||||||
of ideMsg: "msg"
|
of ideMsg: "msg"
|
||||||
|
of ideProject: "project"
|
||||||
|
|
||||||
proc floatInt64Align*(conf: ConfigRef): int16 =
|
proc floatInt64Align*(conf: ConfigRef): int16 =
|
||||||
## Returns either 4 or 8 depending on reasons.
|
## Returns either 4 or 8 depending on reasons.
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ proc myLog(s: string) =
|
||||||
|
|
||||||
const
|
const
|
||||||
seps = {':', ';', ' ', '\t'}
|
seps = {':', ';', ' ', '\t'}
|
||||||
Help = "usage: sug|con|def|use|dus|chk|mod|highlight|outline|known file.nim[;dirtyfile.nim]:line:col\n" &
|
Help = "usage: sug|con|def|use|dus|chk|mod|highlight|outline|known|project file.nim[;dirtyfile.nim]:line:col\n" &
|
||||||
"type 'quit' to quit\n" &
|
"type 'quit' to quit\n" &
|
||||||
"type 'debug' to toggle debug mode on/off\n" &
|
"type 'debug' to toggle debug mode on/off\n" &
|
||||||
"type 'terse' to toggle terse mode on/off"
|
"type 'terse' to toggle terse mode on/off"
|
||||||
|
|
@ -245,6 +245,7 @@ proc toStdout() {.gcsafe.} =
|
||||||
of ideNone: break
|
of ideNone: break
|
||||||
of ideMsg: echo res.doc
|
of ideMsg: echo res.doc
|
||||||
of ideKnown: echo res.quality == 1
|
of ideKnown: echo res.quality == 1
|
||||||
|
of ideProject: echo res.filePath
|
||||||
else: echo res
|
else: echo res
|
||||||
|
|
||||||
proc toSocket(stdoutSocket: Socket) {.gcsafe.} =
|
proc toSocket(stdoutSocket: Socket) {.gcsafe.} =
|
||||||
|
|
@ -254,6 +255,7 @@ proc toSocket(stdoutSocket: Socket) {.gcsafe.} =
|
||||||
of ideNone: break
|
of ideNone: break
|
||||||
of ideMsg: stdoutSocket.send(res.doc & "\c\L")
|
of ideMsg: stdoutSocket.send(res.doc & "\c\L")
|
||||||
of ideKnown: stdoutSocket.send($(res.quality == 1) & "\c\L")
|
of ideKnown: stdoutSocket.send($(res.quality == 1) & "\c\L")
|
||||||
|
of ideProject: stdoutSocket.send(res.filePath & "\c\L")
|
||||||
else: stdoutSocket.send($res & "\c\L")
|
else: stdoutSocket.send($res & "\c\L")
|
||||||
|
|
||||||
proc toEpc(client: Socket; uid: BiggestInt) {.gcsafe.} =
|
proc toEpc(client: Socket; uid: BiggestInt) {.gcsafe.} =
|
||||||
|
|
@ -266,6 +268,8 @@ proc toEpc(client: Socket; uid: BiggestInt) {.gcsafe.} =
|
||||||
list.add sexp(res.doc)
|
list.add sexp(res.doc)
|
||||||
of ideKnown:
|
of ideKnown:
|
||||||
list.add sexp(res.quality == 1)
|
list.add sexp(res.quality == 1)
|
||||||
|
of ideProject:
|
||||||
|
list.add sexp(res.filePath)
|
||||||
else:
|
else:
|
||||||
list.add sexp(res)
|
list.add sexp(res)
|
||||||
returnEpc(client, uid, list)
|
returnEpc(client, uid, list)
|
||||||
|
|
@ -435,6 +439,7 @@ proc execCmd(cmd: string; graph: ModuleGraph; cachedMsgs: CachedMsgs) =
|
||||||
of "debug": toggle optIdeDebug
|
of "debug": toggle optIdeDebug
|
||||||
of "terse": toggle optIdeTerse
|
of "terse": toggle optIdeTerse
|
||||||
of "known": conf.ideCmd = ideKnown
|
of "known": conf.ideCmd = ideKnown
|
||||||
|
of "project": conf.ideCmd = ideProject
|
||||||
else: err()
|
else: err()
|
||||||
var dirtyfile = ""
|
var dirtyfile = ""
|
||||||
var orig = ""
|
var orig = ""
|
||||||
|
|
@ -454,6 +459,8 @@ proc execCmd(cmd: string; graph: ModuleGraph; cachedMsgs: CachedMsgs) =
|
||||||
|
|
||||||
if conf.ideCmd == ideKnown:
|
if conf.ideCmd == ideKnown:
|
||||||
results.send(Suggest(section: ideKnown, quality: ord(fileInfoKnown(conf, AbsoluteFile orig))))
|
results.send(Suggest(section: ideKnown, quality: ord(fileInfoKnown(conf, AbsoluteFile orig))))
|
||||||
|
elif conf.ideCmd == ideProject:
|
||||||
|
results.send(Suggest(section: ideProject, filePath: string conf.projectFull))
|
||||||
else:
|
else:
|
||||||
if conf.ideCmd == ideChk:
|
if conf.ideCmd == ideChk:
|
||||||
for cm in cachedMsgs: errorHook(conf, cm.info, cm.msg, cm.sev)
|
for cm in cachedMsgs: errorHook(conf, cm.info, cm.msg, cm.sev)
|
||||||
|
|
@ -741,6 +748,8 @@ else:
|
||||||
stderr.write s & "\n"
|
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))))
|
||||||
|
elif conf.ideCmd == ideProject:
|
||||||
|
retval.add(Suggest(section: ideProject, filePath: string conf.projectFull))
|
||||||
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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue