nimsuggest chk works for EPC

This commit is contained in:
Andreas Rumpf 2017-03-03 11:59:00 +01:00
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 type
TErrorHandling = enum doNothing, doAbort, doRaise 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) = proc quit(msg: TMsgKind) =
if defined(debug) or msg == errInternal or hintStackTrace in gNotes: if defined(debug) or msg == errInternal or hintStackTrace in gNotes:
if stackTraceAvailable() and isNil(writelnHook): if stackTraceAvailable() and isNil(writelnHook):
@ -838,12 +844,6 @@ proc quit(msg: TMsgKind) =
options.command & " <file>") options.command & " <file>")
quit 1 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) = proc handleError(msg: TMsgKind, eh: TErrorHandling, s: string) =
if msg >= fatalMin and msg <= fatalMax: if msg >= fatalMin and msg <= fatalMax:
if gCmd == cmdIdeTools: log(s) if gCmd == cmdIdeTools: log(s)

View file

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

View file

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