make nimsuggest compile again
This commit is contained in:
parent
dc4aa47c29
commit
e4c088721a
7 changed files with 97 additions and 89 deletions
|
|
@ -152,7 +152,7 @@ proc myImportModule(c: PContext, n: PNode): PSym =
|
||||||
message(c.config, n.info, warnDeprecated, result.constraint.strVal & "; " & result.name.s)
|
message(c.config, n.info, warnDeprecated, result.constraint.strVal & "; " & result.name.s)
|
||||||
else:
|
else:
|
||||||
message(c.config, n.info, warnDeprecated, result.name.s)
|
message(c.config, n.info, warnDeprecated, result.name.s)
|
||||||
suggestSym(n.info, result, c.graph.usageSym, false)
|
suggestSym(c.config, n.info, result, c.graph.usageSym, false)
|
||||||
|
|
||||||
proc impMod(c: PContext; it: PNode) =
|
proc impMod(c: PContext; it: PNode) =
|
||||||
let m = myImportModule(c, it)
|
let m = myImportModule(c, it)
|
||||||
|
|
|
||||||
|
|
@ -274,7 +274,7 @@ template tokenEnd(tok, pos) {.dirty.} =
|
||||||
when defined(nimsuggest):
|
when defined(nimsuggest):
|
||||||
let colB = getColNumber(L, pos)+1
|
let colB = getColNumber(L, pos)+1
|
||||||
if L.fileIdx == gTrackPos.fileIndex and gTrackPos.col in colA..colB and
|
if L.fileIdx == gTrackPos.fileIndex and gTrackPos.col in colA..colB and
|
||||||
L.lineNumber == gTrackPos.line.int and gIdeCmd in {ideSug, ideCon}:
|
L.lineNumber == gTrackPos.line.int and L.config.ideCmd in {ideSug, ideCon}:
|
||||||
L.cursor = CursorPosition.InToken
|
L.cursor = CursorPosition.InToken
|
||||||
gTrackPos.col = colA.int16
|
gTrackPos.col = colA.int16
|
||||||
colA = 0
|
colA = 0
|
||||||
|
|
@ -285,7 +285,7 @@ template tokenEndIgnore(tok, pos) =
|
||||||
when defined(nimsuggest):
|
when defined(nimsuggest):
|
||||||
let colB = getColNumber(L, pos)
|
let colB = getColNumber(L, pos)
|
||||||
if L.fileIdx == gTrackPos.fileIndex and gTrackPos.col in colA..colB and
|
if L.fileIdx == gTrackPos.fileIndex and gTrackPos.col in colA..colB and
|
||||||
L.lineNumber == gTrackPos.line.int and gIdeCmd in {ideSug, ideCon}:
|
L.lineNumber == gTrackPos.line.int and L.config.ideCmd in {ideSug, ideCon}:
|
||||||
gTrackPos.fileIndex = trackPosInvalidFileIdx
|
gTrackPos.fileIndex = trackPosInvalidFileIdx
|
||||||
gTrackPos.line = 0'u16
|
gTrackPos.line = 0'u16
|
||||||
colA = 0
|
colA = 0
|
||||||
|
|
@ -299,7 +299,7 @@ template tokenEndPrevious(tok, pos) =
|
||||||
# the cursor in a string literal or comment:
|
# the cursor in a string literal or comment:
|
||||||
let colB = getColNumber(L, pos)
|
let colB = getColNumber(L, pos)
|
||||||
if L.fileIdx == gTrackPos.fileIndex and gTrackPos.col in colA..colB and
|
if L.fileIdx == gTrackPos.fileIndex and gTrackPos.col in colA..colB and
|
||||||
L.lineNumber == gTrackPos.line.int and gIdeCmd in {ideSug, ideCon}:
|
L.lineNumber == gTrackPos.line.int and L.config.ideCmd in {ideSug, ideCon}:
|
||||||
L.cursor = CursorPosition.BeforeToken
|
L.cursor = CursorPosition.BeforeToken
|
||||||
gTrackPos = L.previousToken
|
gTrackPos = L.previousToken
|
||||||
gTrackPosAttached = true
|
gTrackPosAttached = true
|
||||||
|
|
@ -1122,7 +1122,7 @@ proc rawGetTok*(L: var TLexer, tok: var TToken) =
|
||||||
tok.tokType = tkParLe
|
tok.tokType = tkParLe
|
||||||
when defined(nimsuggest):
|
when defined(nimsuggest):
|
||||||
if L.fileIdx == gTrackPos.fileIndex and tok.col < gTrackPos.col and
|
if L.fileIdx == gTrackPos.fileIndex and tok.col < gTrackPos.col and
|
||||||
tok.line == gTrackPos.line.int and gIdeCmd == ideCon:
|
tok.line == gTrackPos.line.int and L.config.ideCmd == ideCon:
|
||||||
gTrackPos.col = tok.col.int16
|
gTrackPos.col = tok.col.int16
|
||||||
of ')':
|
of ')':
|
||||||
tok.tokType = tkParRi
|
tok.tokType = tkParRi
|
||||||
|
|
@ -1143,7 +1143,7 @@ proc rawGetTok*(L: var TLexer, tok: var TToken) =
|
||||||
of '.':
|
of '.':
|
||||||
when defined(nimsuggest):
|
when defined(nimsuggest):
|
||||||
if L.fileIdx == gTrackPos.fileIndex and tok.col+1 == gTrackPos.col and
|
if L.fileIdx == gTrackPos.fileIndex and tok.col+1 == gTrackPos.col and
|
||||||
tok.line == gTrackPos.line.int and gIdeCmd == ideSug:
|
tok.line == gTrackPos.line.int and L.config.ideCmd == ideSug:
|
||||||
tok.tokType = tkDot
|
tok.tokType = tkDot
|
||||||
L.cursor = CursorPosition.InToken
|
L.cursor = CursorPosition.InToken
|
||||||
gTrackPos.col = tok.col.int16
|
gTrackPos.col = tok.col.int16
|
||||||
|
|
|
||||||
|
|
@ -2154,7 +2154,7 @@ proc semBlock(c: PContext, n: PNode): PNode =
|
||||||
if sfGenSym notin labl.flags:
|
if sfGenSym notin labl.flags:
|
||||||
addDecl(c, labl)
|
addDecl(c, labl)
|
||||||
n.sons[0] = newSymNode(labl, n.sons[0].info)
|
n.sons[0] = newSymNode(labl, n.sons[0].info)
|
||||||
suggestSym(n.sons[0].info, labl, c.graph.usageSym)
|
suggestSym(c.config, n.sons[0].info, labl, c.graph.usageSym)
|
||||||
styleCheckDef(labl)
|
styleCheckDef(labl)
|
||||||
n.sons[1] = semExpr(c, n.sons[1])
|
n.sons[1] = semExpr(c, n.sons[1])
|
||||||
n.typ = n.sons[1].typ
|
n.typ = n.sons[1].typ
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ proc semBreakOrContinue(c: PContext, n: PNode): PNode =
|
||||||
x.info = n.info
|
x.info = n.info
|
||||||
incl(s.flags, sfUsed)
|
incl(s.flags, sfUsed)
|
||||||
n.sons[0] = x
|
n.sons[0] = x
|
||||||
suggestSym(x.info, s, c.graph.usageSym)
|
suggestSym(c.config, x.info, s, c.graph.usageSym)
|
||||||
styleCheckUse(x.info, s)
|
styleCheckUse(x.info, s)
|
||||||
else:
|
else:
|
||||||
localError(c.config, n.info, errInvalidControlFlowX % s.name.s)
|
localError(c.config, n.info, errInvalidControlFlowX % s.name.s)
|
||||||
|
|
@ -203,7 +203,7 @@ proc semCase(c: PContext, n: PNode): PNode =
|
||||||
for i in countup(1, sonsLen(n) - 1):
|
for i in countup(1, sonsLen(n) - 1):
|
||||||
var x = n.sons[i]
|
var x = n.sons[i]
|
||||||
when defined(nimsuggest):
|
when defined(nimsuggest):
|
||||||
if gIdeCmd == ideSug and exactEquals(gTrackPos, x.info) and caseTyp.kind == tyEnum:
|
if c.config.ideCmd == ideSug and exactEquals(gTrackPos, x.info) and caseTyp.kind == tyEnum:
|
||||||
suggestEnum(c, x, caseTyp)
|
suggestEnum(c, x, caseTyp)
|
||||||
case x.kind
|
case x.kind
|
||||||
of nkOfBranch:
|
of nkOfBranch:
|
||||||
|
|
@ -365,7 +365,7 @@ proc semIdentDef(c: PContext, n: PNode, kind: TSymKind): PSym =
|
||||||
result = semIdentWithPragma(c, kind, n, {})
|
result = semIdentWithPragma(c, kind, n, {})
|
||||||
if result.owner.kind == skModule:
|
if result.owner.kind == skModule:
|
||||||
incl(result.flags, sfGlobal)
|
incl(result.flags, sfGlobal)
|
||||||
suggestSym(n.info, result, c.graph.usageSym)
|
suggestSym(c.config, n.info, result, c.graph.usageSym)
|
||||||
styleCheckDef(result)
|
styleCheckDef(result)
|
||||||
|
|
||||||
proc checkNilable(c: PContext; v: PSym) =
|
proc checkNilable(c: PContext; v: PSym) =
|
||||||
|
|
|
||||||
|
|
@ -672,7 +672,7 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
|
||||||
else: rectype.sym
|
else: rectype.sym
|
||||||
for i in countup(0, sonsLen(n)-3):
|
for i in countup(0, sonsLen(n)-3):
|
||||||
var f = semIdentWithPragma(c, skField, n.sons[i], {sfExported})
|
var f = semIdentWithPragma(c, skField, n.sons[i], {sfExported})
|
||||||
suggestSym(n.sons[i].info, f, c.graph.usageSym)
|
suggestSym(c.config, n.sons[i].info, f, c.graph.usageSym)
|
||||||
f.typ = typ
|
f.typ = typ
|
||||||
f.position = pos
|
f.position = pos
|
||||||
if fieldOwner != nil and
|
if fieldOwner != nil and
|
||||||
|
|
|
||||||
|
|
@ -342,12 +342,12 @@ proc suggestFieldAccess(c: PContext, n, field: PNode, outputs: var Suggestions)
|
||||||
when defined(nimsuggest):
|
when defined(nimsuggest):
|
||||||
if n.kind == nkSym and n.sym.kind == skError and suggestVersion == 0:
|
if n.kind == nkSym and n.sym.kind == skError and suggestVersion == 0:
|
||||||
# consider 'foo.|' where 'foo' is some not imported module.
|
# consider 'foo.|' where 'foo' is some not imported module.
|
||||||
let fullPath = findModule(n.sym.name.s, n.info.toFullPath)
|
let fullPath = findModule(c.config, n.sym.name.s, n.info.toFullPath)
|
||||||
if fullPath.len == 0:
|
if fullPath.len == 0:
|
||||||
# error: no known module name:
|
# error: no known module name:
|
||||||
typ = nil
|
typ = nil
|
||||||
else:
|
else:
|
||||||
let m = gImportModule(c.graph, c.module, fullpath.fileInfoIdx, c.cache)
|
let m = gImportModule(c.graph, c.module, fileInfoIdx(c.config, fullpath), c.cache)
|
||||||
if m == nil: typ = nil
|
if m == nil: typ = nil
|
||||||
else:
|
else:
|
||||||
for it in items(n.sym.tab):
|
for it in items(n.sym.tab):
|
||||||
|
|
@ -457,7 +457,7 @@ proc ensureIdx[T](x: var T, y: int) =
|
||||||
proc ensureSeq[T](x: var seq[T]) =
|
proc ensureSeq[T](x: var seq[T]) =
|
||||||
if x == nil: newSeq(x, 0)
|
if x == nil: newSeq(x, 0)
|
||||||
|
|
||||||
proc suggestSym*(info: TLineInfo; s: PSym; usageSym: var PSym; isDecl=true) {.inline.} =
|
proc suggestSym*(conf: ConfigRef; info: TLineInfo; s: PSym; usageSym: var PSym; isDecl=true) {.inline.} =
|
||||||
## misnamed: should be 'symDeclared'
|
## misnamed: should be 'symDeclared'
|
||||||
when defined(nimsuggest):
|
when defined(nimsuggest):
|
||||||
if suggestVersion == 0:
|
if suggestVersion == 0:
|
||||||
|
|
@ -466,17 +466,17 @@ proc suggestSym*(info: TLineInfo; s: PSym; usageSym: var PSym; isDecl=true) {.in
|
||||||
else:
|
else:
|
||||||
s.addNoDup(info)
|
s.addNoDup(info)
|
||||||
|
|
||||||
if gIdeCmd == ideUse:
|
if conf.ideCmd == ideUse:
|
||||||
findUsages(info, s, usageSym)
|
findUsages(info, s, usageSym)
|
||||||
elif gIdeCmd == ideDef:
|
elif conf.ideCmd == ideDef:
|
||||||
findDefinition(info, s)
|
findDefinition(info, s)
|
||||||
elif gIdeCmd == ideDus and s != nil:
|
elif conf.ideCmd == ideDus and s != nil:
|
||||||
if isTracked(info, s.name.s.len):
|
if isTracked(info, s.name.s.len):
|
||||||
suggestResult(symToSuggest(s, isLocal=false, ideDef, info, 100, PrefixMatch.None, false, 0))
|
suggestResult(symToSuggest(s, isLocal=false, ideDef, info, 100, PrefixMatch.None, false, 0))
|
||||||
findUsages(info, s, usageSym)
|
findUsages(info, s, usageSym)
|
||||||
elif gIdeCmd == ideHighlight and info.fileIndex == gTrackPos.fileIndex:
|
elif conf.ideCmd == ideHighlight and info.fileIndex == gTrackPos.fileIndex:
|
||||||
suggestResult(symToSuggest(s, isLocal=false, ideHighlight, info, 100, PrefixMatch.None, false, 0))
|
suggestResult(symToSuggest(s, isLocal=false, ideHighlight, info, 100, PrefixMatch.None, false, 0))
|
||||||
elif gIdeCmd == ideOutline and info.fileIndex == gTrackPos.fileIndex and
|
elif conf.ideCmd == ideOutline and info.fileIndex == gTrackPos.fileIndex and
|
||||||
isDecl:
|
isDecl:
|
||||||
suggestResult(symToSuggest(s, isLocal=false, ideOutline, info, 100, PrefixMatch.None, false, 0))
|
suggestResult(symToSuggest(s, isLocal=false, ideOutline, info, 100, PrefixMatch.None, false, 0))
|
||||||
|
|
||||||
|
|
@ -499,7 +499,7 @@ proc markUsed(conf: ConfigRef; info: TLineInfo; s: PSym; usageSym: var PSym) =
|
||||||
if sfDeprecated in s.flags: warnAboutDeprecated(conf, info, s)
|
if sfDeprecated in s.flags: warnAboutDeprecated(conf, info, s)
|
||||||
if sfError in s.flags: localError(conf, info, "usage of '$1' is a user-defined error" % s.name.s)
|
if sfError in s.flags: localError(conf, info, "usage of '$1' is a user-defined error" % s.name.s)
|
||||||
when defined(nimsuggest):
|
when defined(nimsuggest):
|
||||||
suggestSym(info, s, usageSym, false)
|
suggestSym(conf, info, s, usageSym, false)
|
||||||
|
|
||||||
proc useSym*(conf: ConfigRef; sym: PSym; usageSym: var PSym): PNode =
|
proc useSym*(conf: ConfigRef; sym: PSym; usageSym: var PSym): PNode =
|
||||||
result = newSymNode(sym)
|
result = newSymNode(sym)
|
||||||
|
|
|
||||||
|
|
@ -158,9 +158,10 @@ proc symFromInfo(graph: ModuleGraph; gTrackPos: TLineInfo): PSym =
|
||||||
|
|
||||||
proc execute(cmd: IdeCmd, file, dirtyfile: string, line, col: int;
|
proc execute(cmd: IdeCmd, file, dirtyfile: string, line, col: int;
|
||||||
graph: ModuleGraph; cache: IdentCache) =
|
graph: ModuleGraph; cache: IdentCache) =
|
||||||
|
let conf = graph.config
|
||||||
myLog("cmd: " & $cmd & ", file: " & file & ", dirtyFile: " & dirtyfile &
|
myLog("cmd: " & $cmd & ", file: " & file & ", dirtyFile: " & dirtyfile &
|
||||||
"[" & $line & ":" & $col & "]")
|
"[" & $line & ":" & $col & "]")
|
||||||
gIdeCmd = cmd
|
conf.ideCmd = cmd
|
||||||
if cmd == ideChk:
|
if cmd == ideChk:
|
||||||
msgs.structuredErrorHook = errorHook
|
msgs.structuredErrorHook = errorHook
|
||||||
msgs.writelnHook = myLog
|
msgs.writelnHook = myLog
|
||||||
|
|
@ -170,33 +171,33 @@ proc execute(cmd: IdeCmd, file, dirtyfile: string, line, col: int;
|
||||||
if cmd == ideUse and suggestVersion != 0:
|
if cmd == ideUse and suggestVersion != 0:
|
||||||
graph.resetAllModules()
|
graph.resetAllModules()
|
||||||
var isKnownFile = true
|
var isKnownFile = true
|
||||||
let dirtyIdx = file.fileInfoIdx(isKnownFile)
|
let dirtyIdx = fileInfoIdx(conf, file, isKnownFile)
|
||||||
|
|
||||||
if dirtyfile.len != 0: msgs.setDirtyFile(dirtyIdx, dirtyfile)
|
if dirtyfile.len != 0: msgs.setDirtyFile(dirtyIdx, dirtyfile)
|
||||||
else: msgs.setDirtyFile(dirtyIdx, nil)
|
else: msgs.setDirtyFile(dirtyIdx, nil)
|
||||||
|
|
||||||
gTrackPos = newLineInfo(dirtyIdx, line, col)
|
gTrackPos = newLineInfo(dirtyIdx, line, col)
|
||||||
gTrackPosAttached = false
|
gTrackPosAttached = false
|
||||||
gErrorCounter = 0
|
conf.errorCounter = 0
|
||||||
if suggestVersion == 1:
|
if suggestVersion == 1:
|
||||||
graph.usageSym = nil
|
graph.usageSym = nil
|
||||||
if not isKnownFile:
|
if not isKnownFile:
|
||||||
graph.compileProject(cache)
|
graph.compileProject(cache)
|
||||||
if suggestVersion == 0 and gIdeCmd in {ideUse, ideDus} and
|
if suggestVersion == 0 and conf.ideCmd in {ideUse, ideDus} and
|
||||||
dirtyfile.len == 0:
|
dirtyfile.len == 0:
|
||||||
discard "no need to recompile anything"
|
discard "no need to recompile anything"
|
||||||
else:
|
else:
|
||||||
let modIdx = graph.parentModule(dirtyIdx)
|
let modIdx = graph.parentModule(dirtyIdx)
|
||||||
graph.markDirty dirtyIdx
|
graph.markDirty dirtyIdx
|
||||||
graph.markClientsDirty dirtyIdx
|
graph.markClientsDirty dirtyIdx
|
||||||
if gIdeCmd != ideMod:
|
if conf.ideCmd != ideMod:
|
||||||
graph.compileProject(cache, modIdx)
|
graph.compileProject(cache, modIdx)
|
||||||
if gIdeCmd in {ideUse, ideDus}:
|
if conf.ideCmd in {ideUse, ideDus}:
|
||||||
let u = if suggestVersion != 1: graph.symFromInfo(gTrackPos) else: graph.usageSym
|
let u = if suggestVersion != 1: graph.symFromInfo(gTrackPos) else: graph.usageSym
|
||||||
if u != nil:
|
if u != nil:
|
||||||
listUsages(u)
|
listUsages(u)
|
||||||
else:
|
else:
|
||||||
localError(gTrackPos, "found no symbol at this position " & $gTrackPos)
|
localError(conf, gTrackPos, "found no symbol at this position " & $gTrackPos)
|
||||||
|
|
||||||
proc executeEpc(cmd: IdeCmd, args: SexpNode;
|
proc executeEpc(cmd: IdeCmd, args: SexpNode;
|
||||||
graph: ModuleGraph; cache: IdentCache) =
|
graph: ModuleGraph; cache: IdentCache) =
|
||||||
|
|
@ -257,7 +258,7 @@ proc toEpc(client: Socket; uid: BiggestInt) {.gcsafe.} =
|
||||||
|
|
||||||
template setVerbosity(level: typed) =
|
template setVerbosity(level: typed) =
|
||||||
gVerbosity = level
|
gVerbosity = level
|
||||||
gNotes = NotesVerbosity[gVerbosity]
|
conf.notes = NotesVerbosity[gVerbosity]
|
||||||
|
|
||||||
proc connectToNextFreePort(server: Socket, host: string): Port =
|
proc connectToNextFreePort(server: Socket, host: string): Port =
|
||||||
server.bindaddr(Port(0), host)
|
server.bindaddr(Port(0), host)
|
||||||
|
|
@ -349,16 +350,18 @@ proc replEpc(x: ThreadParams) {.thread.} =
|
||||||
of "call":
|
of "call":
|
||||||
let
|
let
|
||||||
uid = message[1].getNum
|
uid = message[1].getNum
|
||||||
|
cmd = message[2].getSymbol
|
||||||
args = message[3]
|
args = message[3]
|
||||||
|
|
||||||
gIdeCmd = parseIdeCmd(message[2].getSymbol)
|
when false:
|
||||||
case gIdeCmd
|
x.ideCmd[] = parseIdeCmd(message[2].getSymbol)
|
||||||
|
case x.ideCmd[]
|
||||||
of ideSug, ideCon, ideDef, ideUse, ideDus, ideOutline, ideHighlight:
|
of ideSug, ideCon, ideDef, ideUse, ideDus, ideOutline, ideHighlight:
|
||||||
setVerbosity(0)
|
setVerbosity(0)
|
||||||
else: discard
|
else: discard
|
||||||
let cmd = $gIdeCmd & " " & args.argsToStr
|
let fullCmd = cmd & " " & args.argsToStr
|
||||||
myLog "MSG CMD: " & cmd
|
myLog "MSG CMD: " & fullCmd
|
||||||
requests.send(cmd)
|
requests.send(fullCmd)
|
||||||
toEpc(client, uid)
|
toEpc(client, uid)
|
||||||
of "methods":
|
of "methods":
|
||||||
returnEpc(client, message[1].getNum, listEpc())
|
returnEpc(client, message[1].getNum, listEpc())
|
||||||
|
|
@ -375,6 +378,8 @@ proc replEpc(x: ThreadParams) {.thread.} =
|
||||||
quit errMessage
|
quit errMessage
|
||||||
|
|
||||||
proc execCmd(cmd: string; graph: ModuleGraph; cache: IdentCache; cachedMsgs: CachedMsgs) =
|
proc execCmd(cmd: string; graph: ModuleGraph; cache: IdentCache; cachedMsgs: CachedMsgs) =
|
||||||
|
let conf = graph.config
|
||||||
|
|
||||||
template sentinel() =
|
template sentinel() =
|
||||||
# send sentinel for the input reading thread:
|
# send sentinel for the input reading thread:
|
||||||
results.send(Suggest(section: ideNone))
|
results.send(Suggest(section: ideNone))
|
||||||
|
|
@ -395,21 +400,21 @@ proc execCmd(cmd: string; graph: ModuleGraph; cache: IdentCache; cachedMsgs: Cac
|
||||||
var opc = ""
|
var opc = ""
|
||||||
var i = parseIdent(cmd, opc, 0)
|
var i = parseIdent(cmd, opc, 0)
|
||||||
case opc.normalize
|
case opc.normalize
|
||||||
of "sug": gIdeCmd = ideSug
|
of "sug": conf.ideCmd = ideSug
|
||||||
of "con": gIdeCmd = ideCon
|
of "con": conf.ideCmd = ideCon
|
||||||
of "def": gIdeCmd = ideDef
|
of "def": conf.ideCmd = ideDef
|
||||||
of "use": gIdeCmd = ideUse
|
of "use": conf.ideCmd = ideUse
|
||||||
of "dus": gIdeCmd = ideDus
|
of "dus": conf.ideCmd = ideDus
|
||||||
of "mod": gIdeCmd = ideMod
|
of "mod": conf.ideCmd = ideMod
|
||||||
of "chk": gIdeCmd = ideChk
|
of "chk": conf.ideCmd = ideChk
|
||||||
of "highlight": gIdeCmd = ideHighlight
|
of "highlight": conf.ideCmd = ideHighlight
|
||||||
of "outline": gIdeCmd = ideOutline
|
of "outline": conf.ideCmd = ideOutline
|
||||||
of "quit":
|
of "quit":
|
||||||
sentinel()
|
sentinel()
|
||||||
quit()
|
quit()
|
||||||
of "debug": toggle optIdeDebug
|
of "debug": toggle optIdeDebug
|
||||||
of "terse": toggle optIdeTerse
|
of "terse": toggle optIdeTerse
|
||||||
of "known": gIdeCmd = ideKnown
|
of "known": conf.ideCmd = ideKnown
|
||||||
else: err()
|
else: err()
|
||||||
var dirtyfile = ""
|
var dirtyfile = ""
|
||||||
var orig = ""
|
var orig = ""
|
||||||
|
|
@ -423,17 +428,17 @@ proc execCmd(cmd: string; graph: ModuleGraph; cache: IdentCache; cachedMsgs: Cac
|
||||||
i += skipWhile(cmd, seps, i)
|
i += skipWhile(cmd, seps, i)
|
||||||
i += parseInt(cmd, col, i)
|
i += parseInt(cmd, col, i)
|
||||||
|
|
||||||
if gIdeCmd == ideKnown:
|
if conf.ideCmd == ideKnown:
|
||||||
results.send(Suggest(section: ideKnown, quality: ord(fileInfoKnown(orig))))
|
results.send(Suggest(section: ideKnown, quality: ord(fileInfoKnown(conf, orig))))
|
||||||
else:
|
else:
|
||||||
if gIdeCmd == ideChk:
|
if conf.ideCmd == ideChk:
|
||||||
for cm in cachedMsgs: errorHook(cm.info, cm.msg, cm.sev)
|
for cm in cachedMsgs: errorHook(cm.info, cm.msg, cm.sev)
|
||||||
execute(gIdeCmd, orig, dirtyfile, line, col, graph, cache)
|
execute(conf.ideCmd, orig, dirtyfile, line, col, graph, cache)
|
||||||
sentinel()
|
sentinel()
|
||||||
|
|
||||||
proc recompileFullProject(graph: ModuleGraph; cache: IdentCache) =
|
proc recompileFullProject(graph: ModuleGraph; cache: IdentCache) =
|
||||||
#echo "recompiling full project"
|
#echo "recompiling full project"
|
||||||
resetSystemArtifacts()
|
resetSystemArtifacts(graph)
|
||||||
vm.globalCtx = nil
|
vm.globalCtx = nil
|
||||||
graph.resetAllModules()
|
graph.resetAllModules()
|
||||||
GC_fullcollect()
|
GC_fullcollect()
|
||||||
|
|
@ -441,8 +446,9 @@ proc recompileFullProject(graph: ModuleGraph; cache: IdentCache) =
|
||||||
#echo GC_getStatistics()
|
#echo GC_getStatistics()
|
||||||
|
|
||||||
proc mainThread(graph: ModuleGraph; cache: IdentCache) =
|
proc mainThread(graph: ModuleGraph; cache: IdentCache) =
|
||||||
|
let conf = graph.config
|
||||||
if gLogging:
|
if gLogging:
|
||||||
for it in searchPaths:
|
for it in conf.searchPaths:
|
||||||
log(it)
|
log(it)
|
||||||
|
|
||||||
proc wrHook(line: string) {.closure.} =
|
proc wrHook(line: string) {.closure.} =
|
||||||
|
|
@ -468,7 +474,7 @@ proc mainThread(graph: ModuleGraph; cache: IdentCache) =
|
||||||
idle += 1
|
idle += 1
|
||||||
if idle == 20 and gRefresh:
|
if idle == 20 and gRefresh:
|
||||||
# we use some nimsuggest activity to enable a lazy recompile:
|
# we use some nimsuggest activity to enable a lazy recompile:
|
||||||
gIdeCmd = ideChk
|
conf.ideCmd = ideChk
|
||||||
msgs.writelnHook = proc (s: string) = discard
|
msgs.writelnHook = proc (s: string) = discard
|
||||||
cachedMsgs.setLen 0
|
cachedMsgs.setLen 0
|
||||||
msgs.structuredErrorHook = proc (info: TLineInfo; msg: string; sev: Severity) =
|
msgs.structuredErrorHook = proc (info: TLineInfo; msg: string; sev: Severity) =
|
||||||
|
|
@ -480,20 +486,21 @@ var
|
||||||
inputThread: Thread[ThreadParams]
|
inputThread: Thread[ThreadParams]
|
||||||
|
|
||||||
proc mainCommand(graph: ModuleGraph; cache: IdentCache) =
|
proc mainCommand(graph: ModuleGraph; cache: IdentCache) =
|
||||||
|
let conf = graph.config
|
||||||
clearPasses()
|
clearPasses()
|
||||||
registerPass verbosePass
|
registerPass verbosePass
|
||||||
registerPass semPass
|
registerPass semPass
|
||||||
gCmd = cmdIdeTools
|
gCmd = cmdIdeTools
|
||||||
incl gGlobalOptions, optCaasEnabled
|
incl gGlobalOptions, optCaasEnabled
|
||||||
wantMainModule()
|
wantMainModule(conf)
|
||||||
|
|
||||||
if not fileExists(gProjectFull):
|
if not fileExists(conf.projectFull):
|
||||||
quit "cannot find file: " & gProjectFull
|
quit "cannot find file: " & conf.projectFull
|
||||||
|
|
||||||
add(searchPaths, options.libpath)
|
add(conf.searchPaths, conf.libpath)
|
||||||
|
|
||||||
# do not stop after the first error:
|
# do not stop after the first error:
|
||||||
msgs.gErrorMax = high(int)
|
conf.errorMax = high(int)
|
||||||
# do not print errors, but log them
|
# do not print errors, but log them
|
||||||
msgs.writelnHook = proc (s: string) = log(s)
|
msgs.writelnHook = proc (s: string) = log(s)
|
||||||
msgs.structuredErrorHook = nil
|
msgs.structuredErrorHook = nil
|
||||||
|
|
@ -510,15 +517,15 @@ proc mainCommand(graph: ModuleGraph; cache: IdentCache) =
|
||||||
of mtcp: createThread(inputThread, replTcp, (gPort, gAddress))
|
of mtcp: createThread(inputThread, replTcp, (gPort, gAddress))
|
||||||
of mepc: createThread(inputThread, replEpc, (gPort, gAddress))
|
of mepc: createThread(inputThread, replEpc, (gPort, gAddress))
|
||||||
of mcmdsug: createThread(inputThread, replCmdline,
|
of mcmdsug: createThread(inputThread, replCmdline,
|
||||||
(gPort, "sug \"" & options.gProjectFull & "\":" & gAddress))
|
(gPort, "sug \"" & conf.projectFull & "\":" & gAddress))
|
||||||
of mcmdcon: createThread(inputThread, replCmdline,
|
of mcmdcon: createThread(inputThread, replCmdline,
|
||||||
(gPort, "con \"" & options.gProjectFull & "\":" & gAddress))
|
(gPort, "con \"" & conf.projectFull & "\":" & gAddress))
|
||||||
mainThread(graph, cache)
|
mainThread(graph, cache)
|
||||||
joinThread(inputThread)
|
joinThread(inputThread)
|
||||||
close(requests)
|
close(requests)
|
||||||
close(results)
|
close(results)
|
||||||
|
|
||||||
proc processCmdLine*(pass: TCmdLinePass, cmd: string; config: ConfigRef) =
|
proc processCmdLine*(pass: TCmdLinePass, cmd: string; conf: ConfigRef) =
|
||||||
var p = parseopt.initOptParser(cmd)
|
var p = parseopt.initOptParser(cmd)
|
||||||
while true:
|
while true:
|
||||||
parseopt.next(p)
|
parseopt.next(p)
|
||||||
|
|
@ -562,66 +569,67 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string; config: ConfigRef) =
|
||||||
gRefresh = true
|
gRefresh = true
|
||||||
of "maxresults":
|
of "maxresults":
|
||||||
suggestMaxResults = parseInt(p.val)
|
suggestMaxResults = parseInt(p.val)
|
||||||
else: processSwitch(pass, p, config)
|
else: processSwitch(pass, p, conf)
|
||||||
of cmdArgument:
|
of cmdArgument:
|
||||||
let a = unixToNativePath(p.key)
|
let a = unixToNativePath(p.key)
|
||||||
if dirExists(a) and not fileExists(a.addFileExt("nim")):
|
if dirExists(a) and not fileExists(a.addFileExt("nim")):
|
||||||
options.gProjectName = findProjectNimFile(a)
|
conf.projectName = findProjectNimFile(conf, a)
|
||||||
# don't make it worse, report the error the old way:
|
# don't make it worse, report the error the old way:
|
||||||
if options.gProjectName.len == 0: options.gProjectName = a
|
if conf.projectName.len == 0: conf.projectName = a
|
||||||
else:
|
else:
|
||||||
options.gProjectName = a
|
conf.projectName = a
|
||||||
# if processArgument(pass, p, argsCount): break
|
# if processArgument(pass, p, argsCount): break
|
||||||
|
|
||||||
proc handleCmdLine(cache: IdentCache; config: ConfigRef) =
|
proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
|
||||||
|
condsyms.initDefines(conf.symbols)
|
||||||
|
defineSymbol conf.symbols, "nimsuggest"
|
||||||
|
|
||||||
if paramCount() == 0:
|
if paramCount() == 0:
|
||||||
stdout.writeline(Usage)
|
stdout.writeline(Usage)
|
||||||
else:
|
else:
|
||||||
processCmdLine(passCmd1, "", config)
|
processCmdLine(passCmd1, "", conf)
|
||||||
if gMode != mstdin:
|
if gMode != mstdin:
|
||||||
msgs.writelnHook = proc (msg: string) = discard
|
msgs.writelnHook = proc (msg: string) = discard
|
||||||
if gProjectName != "":
|
if conf.projectName != "":
|
||||||
try:
|
try:
|
||||||
gProjectFull = canonicalizePath(gProjectName)
|
conf.projectFull = canonicalizePath(conf, conf.projectName)
|
||||||
except OSError:
|
except OSError:
|
||||||
gProjectFull = gProjectName
|
conf.projectFull = conf.projectName
|
||||||
var p = splitFile(gProjectFull)
|
var p = splitFile(conf.projectFull)
|
||||||
gProjectPath = canonicalizePath p.dir
|
conf.projectPath = canonicalizePath(conf, p.dir)
|
||||||
gProjectName = p.name
|
conf.projectName = p.name
|
||||||
else:
|
else:
|
||||||
gProjectPath = canonicalizePath getCurrentDir()
|
conf.projectPath = canonicalizePath(conf, getCurrentDir())
|
||||||
|
|
||||||
# Find Nim's prefix dir.
|
# Find Nim's prefix dir.
|
||||||
let binaryPath = findExe("nim")
|
let binaryPath = findExe("nim")
|
||||||
if binaryPath == "":
|
if binaryPath == "":
|
||||||
raise newException(IOError,
|
raise newException(IOError,
|
||||||
"Cannot find Nim standard library: Nim compiler not in PATH")
|
"Cannot find Nim standard library: Nim compiler not in PATH")
|
||||||
gPrefixDir = binaryPath.splitPath().head.parentDir()
|
conf.prefixDir = binaryPath.splitPath().head.parentDir()
|
||||||
if not dirExists(gPrefixDir / "lib"): gPrefixDir = ""
|
if not dirExists(conf.prefixDir / "lib"): conf.prefixDir = ""
|
||||||
|
|
||||||
#msgs.writelnHook = proc (line: string) = log(line)
|
#msgs.writelnHook = proc (line: string) = log(line)
|
||||||
myLog("START " & gProjectFull)
|
myLog("START " & conf.projectFull)
|
||||||
|
|
||||||
loadConfigs(DefaultConfig, cache, config) # load all config files
|
loadConfigs(DefaultConfig, cache, conf) # load all config files
|
||||||
# now process command line arguments again, because some options in the
|
# now process command line arguments again, because some options in the
|
||||||
# command line can overwite the config file's settings
|
# command line can overwite the config file's settings
|
||||||
options.command = "nimsuggest"
|
conf.command = "nimsuggest"
|
||||||
let scriptFile = gProjectFull.changeFileExt("nims")
|
let scriptFile = conf.projectFull.changeFileExt("nims")
|
||||||
if fileExists(scriptFile):
|
if fileExists(scriptFile):
|
||||||
# 'nimsuggest foo.nims' means to just auto-complete the NimScript file:
|
# 'nimsuggest foo.nims' means to just auto-complete the NimScript file:
|
||||||
if scriptFile != gProjectFull:
|
if scriptFile != conf.projectFull:
|
||||||
runNimScript(cache, scriptFile, freshDefines=false, config)
|
runNimScript(cache, scriptFile, freshDefines=false, conf)
|
||||||
elif fileExists(gProjectPath / "config.nims"):
|
elif fileExists(conf.projectPath / "config.nims"):
|
||||||
# directory wide NimScript file
|
# directory wide NimScript file
|
||||||
runNimScript(cache, gProjectPath / "config.nims", freshDefines=false, config)
|
runNimScript(cache, conf.projectPath / "config.nims", freshDefines=false, conf)
|
||||||
|
|
||||||
extccomp.initVars()
|
extccomp.initVars(conf)
|
||||||
processCmdLine(passCmd2, "", config)
|
processCmdLine(passCmd2, "", conf)
|
||||||
|
|
||||||
let graph = newModuleGraph(config)
|
let graph = newModuleGraph(conf)
|
||||||
graph.suggestMode = true
|
graph.suggestMode = true
|
||||||
mainCommand(graph, cache)
|
mainCommand(graph, cache)
|
||||||
|
|
||||||
condsyms.initDefines()
|
|
||||||
defineSymbol "nimsuggest"
|
|
||||||
handleCmdline(newIdentCache(), newConfigRef())
|
handleCmdline(newIdentCache(), newConfigRef())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue