nimsuggest chk works for EPC

This commit is contained in:
Andreas Rumpf
2017-03-03 11:59:00 +01:00
parent 50835257d6
commit 6c0304f7f5
3 changed files with 24 additions and 22 deletions

View File

@@ -828,6 +828,12 @@ proc getMessageStr(msg: TMsgKind, arg: string): string =
type
TErrorHandling = enum doNothing, doAbort, doRaise
proc log*(s: string) {.procvar.} =
var f: File
if open(f, getHomeDir() / "nimsuggest.log", fmAppend):
f.writeLine(s)
close(f)
proc quit(msg: TMsgKind) =
if defined(debug) or msg == errInternal or hintStackTrace in gNotes:
if stackTraceAvailable() and isNil(writelnHook):
@@ -838,12 +844,6 @@ proc quit(msg: TMsgKind) =
options.command & " <file>")
quit 1
proc log*(s: string) {.procvar.} =
var f: File
if open(f, getHomeDir() / "nimsuggest.log", fmAppend):
f.writeLine(s)
close(f)
proc handleError(msg: TMsgKind, eh: TErrorHandling, s: string) =
if msg >= fatalMin and msg <= fatalMax:
if gCmd == cmdIdeTools: log(s)

View File

@@ -98,15 +98,17 @@ proc sexp(s: IdeCmd|TSymKind): SexpNode = sexp($s)
proc sexp(s: Suggest): SexpNode =
# If you change the order here, make sure to change it over in
# nim-mode.el too.
let qp = if s.qualifiedPath.isNil: @[] else: s.qualifiedPath
result = convertSexp([
s.section,
s.symkind,
s.qualifiedPath.map(newSString),
qp.map(newSString),
s.filePath,
s.forth,
s.line,
s.column,
s.doc
s.doc,
s.quality
])
proc sexp(s: seq[Suggest]): SexpNode =
@@ -199,7 +201,6 @@ proc returnEpc(socket: Socket, uid: BiggestInt, s: SexpNode|string,
let response = $convertSexp([newSSymbol(return_symbol), uid, s])
socket.send(toHex(len(response), 6))
socket.send(response)
log "did send " & response
template checkSanity(client, sizeHex, size, messageBuffer: typed) =
if client.recv(sizeHex, 6) != 6:
@@ -386,12 +387,12 @@ proc execCmd(cmd: string; graph: ModuleGraph; cache: IdentCache) =
of "use": gIdeCmd = ideUse
of "dus": gIdeCmd = ideDus
of "mod": gIdeCmd = ideMod
of "chk":
gIdeCmd = ideChk
incl(gGlobalOptions, optIdeDebug)
of "chk": gIdeCmd = ideChk
of "highlight": gIdeCmd = ideHighlight
of "outline": gIdeCmd = ideOutline
of "quit": quit()
of "quit":
sentinel()
quit()
of "debug": toggle optIdeDebug
of "terse": toggle optIdeTerse
of "known": gIdeCmd = ideKnown

View File

@@ -173,7 +173,7 @@ proc sexpToAnswer(s: SexpNode): string =
#s.line,
#s.column,
#s.doc
if a.len >= 8:
if a.len >= 9:
let section = a[0].getStr
let symk = a[1].getStr
let qp = a[2]
@@ -187,10 +187,11 @@ proc sexpToAnswer(s: SexpNode): string =
result.add symk
result.add '\t'
var i = 0
for aa in qp:
if i > 0: result.add '.'
result.add aa.getStr
inc i
if qp.kind == SList:
for aa in qp:
if i > 0: result.add '.'
result.add aa.getStr
inc i
result.add '\t'
result.add typ
result.add '\t'
@@ -202,8 +203,7 @@ proc sexpToAnswer(s: SexpNode): string =
result.add '\t'
result.add doc
result.add '\t'
# for now Nim EPC does not return the quality
result.add "100"
result.add a[8].getNum
result.add '\L'
proc doReport(filename, answer, resp: string; report: var string) =
@@ -233,6 +233,7 @@ proc runEpcTest(filename: string): int =
let outp = p.outputStream
let inp = p.inputStream
var report = ""
var socket = newSocket()
try:
# read the port number:
when defined(posix):
@@ -245,7 +246,6 @@ proc runEpcTest(filename: string): int =
inc i
let a = outp.readAll().strip()
let port = parseInt(a)
var socket = newSocket()
socket.connect("localhost", Port(port))
for req, resp in items(s.script):
if not runCmd(req, s.dest):
@@ -255,6 +255,7 @@ proc runEpcTest(filename: string): int =
let answer = sexpToAnswer(sx)
doReport(filename, answer, resp, report)
finally:
socket.sendEpcStr "return arg"
close(p)
if report.len > 0:
echo "==== EPC ========================================"
@@ -299,7 +300,7 @@ proc runTest(filename: string): int =
proc main() =
var failures = 0
when true:
when false:
let x = getAppDir() / "tests/tchk1.nim"
let xx = expandFilename x
failures += runEpcTest(xx)