proc execute / return-error handling
This commit is contained in:
parent
bf4a92784e
commit
7b7188a8ad
1 changed files with 59 additions and 49 deletions
|
|
@ -45,6 +45,9 @@ const
|
||||||
"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"
|
||||||
|
|
||||||
|
type
|
||||||
|
EUnexpectedCommand = object of Exception
|
||||||
|
|
||||||
proc parseQuoted(cmd: string; outp: var string; start: int): int =
|
proc parseQuoted(cmd: string; outp: var string; start: int): int =
|
||||||
var i = start
|
var i = start
|
||||||
i += skipWhitespace(cmd, i)
|
i += skipWhitespace(cmd, i)
|
||||||
|
|
@ -80,16 +83,38 @@ proc sexp(s: seq[Suggest]): SexpNode =
|
||||||
proc listEPC(): SexpNode =
|
proc listEPC(): SexpNode =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
proc execute(cmd: IdeCmd, file, dirtyfile: string, line, col: int) =
|
||||||
|
gIdeCmd = cmd
|
||||||
|
if cmd == ideUse:
|
||||||
|
modules.resetAllModules()
|
||||||
|
var isKnownFile = true
|
||||||
|
let dirtyIdx = file.fileInfoIdx(isKnownFile)
|
||||||
|
|
||||||
|
if dirtyfile.len != 0: msgs.setDirtyFile(dirtyIdx, dirtyfile)
|
||||||
|
else: msgs.setDirtyFile(dirtyIdx, nil)
|
||||||
|
|
||||||
|
resetModule dirtyIdx
|
||||||
|
if dirtyIdx != gProjectMainIdx:
|
||||||
|
resetModule gProjectMainIdx
|
||||||
|
|
||||||
|
gTrackPos = newLineInfo(dirtyIdx, line, col)
|
||||||
|
#echo dirtyfile, gDirtyBufferIdx, " project ", gProjectMainIdx
|
||||||
|
gErrorCounter = 0
|
||||||
|
if not isKnownFile:
|
||||||
|
compileProject(dirtyIdx)
|
||||||
|
else:
|
||||||
|
compileProject()
|
||||||
|
|
||||||
proc executeEPC(cmd: IdeCmd, args: SexpNode) =
|
proc executeEPC(cmd: IdeCmd, args: SexpNode) =
|
||||||
let
|
let
|
||||||
file = args[0].getStr
|
file = args[0].getStr
|
||||||
line = args[1].getNum
|
line = args[1].getNum
|
||||||
column = args[2].getNum
|
column = args[2].getNum
|
||||||
dirtyfile = args[3].getStr(nil)
|
dirtyfile = args[3].getStr(nil)
|
||||||
discard
|
execute(cmd, file, dirtyfile, int(line), int(column))
|
||||||
|
|
||||||
proc returnEPC(socket: var Socket, uid: string, s: SexpNode) =
|
proc returnEPC(socket: var Socket, uid: string, s: SexpNode, return_symbol = "return") =
|
||||||
let response = $convertSexp([newSSymbol("return"), [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)
|
||||||
socket.close()
|
socket.close()
|
||||||
|
|
@ -97,7 +122,7 @@ proc returnEPC(socket: var Socket, uid: string, s: SexpNode) =
|
||||||
proc findEPCPort(): int =
|
proc findEPCPort(): int =
|
||||||
98294 # guaranteed to be random
|
98294 # guaranteed to be random
|
||||||
|
|
||||||
proc action(cmd: string) =
|
proc parseCmdLine(cmd: string) =
|
||||||
template toggle(sw) =
|
template toggle(sw) =
|
||||||
if sw in gGlobalOptions:
|
if sw in gGlobalOptions:
|
||||||
excl(gGlobalOptions, sw)
|
excl(gGlobalOptions, sw)
|
||||||
|
|
@ -115,9 +140,7 @@ proc action(cmd: string) =
|
||||||
of "sug": gIdeCmd = ideSug
|
of "sug": gIdeCmd = ideSug
|
||||||
of "con": gIdeCmd = ideCon
|
of "con": gIdeCmd = ideCon
|
||||||
of "def": gIdeCmd = ideDef
|
of "def": gIdeCmd = ideDef
|
||||||
of "use":
|
of "use": gIdeCmd = ideUse
|
||||||
modules.resetAllModules()
|
|
||||||
gIdeCmd = ideUse
|
|
||||||
of "quit": quit()
|
of "quit": quit()
|
||||||
of "debug": toggle optIdeDebug
|
of "debug": toggle optIdeDebug
|
||||||
of "terse": toggle optIdeTerse
|
of "terse": toggle optIdeTerse
|
||||||
|
|
@ -133,23 +156,7 @@ proc action(cmd: string) =
|
||||||
i += skipWhile(cmd, seps, i)
|
i += skipWhile(cmd, seps, i)
|
||||||
i += parseInt(cmd, col, i)
|
i += parseInt(cmd, col, i)
|
||||||
|
|
||||||
var isKnownFile = true
|
execute(gIdeCmd, orig, dirtyfile, line, col)
|
||||||
if orig.len == 0: err()
|
|
||||||
let dirtyIdx = orig.fileInfoIdx(isKnownFile)
|
|
||||||
|
|
||||||
if dirtyfile.len != 0: msgs.setDirtyFile(dirtyIdx, dirtyfile)
|
|
||||||
else: msgs.setDirtyFile(dirtyIdx, nil)
|
|
||||||
|
|
||||||
resetModule dirtyIdx
|
|
||||||
if dirtyIdx != gProjectMainIdx:
|
|
||||||
resetModule gProjectMainIdx
|
|
||||||
gTrackPos = newLineInfo(dirtyIdx, line, col)
|
|
||||||
#echo dirtyfile, gDirtyBufferIdx, " project ", gProjectMainIdx
|
|
||||||
gErrorCounter = 0
|
|
||||||
if not isKnownFile:
|
|
||||||
compileProject(dirtyIdx)
|
|
||||||
else:
|
|
||||||
compileProject()
|
|
||||||
|
|
||||||
proc serve() =
|
proc serve() =
|
||||||
# do not stop after the first error:
|
# do not stop after the first error:
|
||||||
|
|
@ -159,7 +166,7 @@ proc serve() =
|
||||||
echo Help
|
echo Help
|
||||||
var line = ""
|
var line = ""
|
||||||
while readLineFromStdin("> ", line):
|
while readLineFromStdin("> ", line):
|
||||||
action line
|
parseCmdLine line
|
||||||
echo ""
|
echo ""
|
||||||
flushFile(stdout)
|
flushFile(stdout)
|
||||||
of mtcp:
|
of mtcp:
|
||||||
|
|
@ -176,7 +183,7 @@ proc serve() =
|
||||||
accept(server, stdoutSocket)
|
accept(server, stdoutSocket)
|
||||||
|
|
||||||
stdoutSocket.readLine(inp)
|
stdoutSocket.readLine(inp)
|
||||||
action inp.string
|
parseCmdLine inp.string
|
||||||
|
|
||||||
stdoutSocket.send("\c\L")
|
stdoutSocket.send("\c\L")
|
||||||
stdoutSocket.close()
|
stdoutSocket.close()
|
||||||
|
|
@ -189,11 +196,7 @@ proc serve() =
|
||||||
server.listen()
|
server.listen()
|
||||||
echo(port)
|
echo(port)
|
||||||
while true:
|
while true:
|
||||||
var results: seq[Suggest] = @[]
|
|
||||||
var client = newSocket()
|
var client = newSocket()
|
||||||
suggest.suggestionResultHook = proc (s: Suggest) =
|
|
||||||
results.add(s)
|
|
||||||
|
|
||||||
accept(server, client)
|
accept(server, client)
|
||||||
var sizeHex = ""
|
var sizeHex = ""
|
||||||
if client.recv(sizeHex, 6, 1000) != 6:
|
if client.recv(sizeHex, 6, 1000) != 6:
|
||||||
|
|
@ -207,25 +210,32 @@ proc serve() =
|
||||||
let message = parseSexp($messageBuffer)
|
let message = parseSexp($messageBuffer)
|
||||||
let messageType = message[0].getSymbol
|
let messageType = message[0].getSymbol
|
||||||
let body = message[1]
|
let body = message[1]
|
||||||
case messageType:
|
try:
|
||||||
of "call":
|
case messageType:
|
||||||
let
|
of "call":
|
||||||
uid = body[0].getStr
|
var results: seq[Suggest] = @[]
|
||||||
cmd = parseIdeCmd(body[1].getStr)
|
suggest.suggestionResultHook = proc (s: Suggest) =
|
||||||
args = body[2]
|
results.add(s)
|
||||||
executeEPC(cmd, args)
|
|
||||||
returnEPC(client, uid, sexp(results))
|
let
|
||||||
of "return":
|
uid = body[0].getStr
|
||||||
raise newException(ValueError, "no return expected")
|
cmd = parseIdeCmd(body[1].getStr)
|
||||||
of "return-error":
|
args = body[2]
|
||||||
raise newException(ValueError, "no return expected")
|
executeEPC(cmd, args)
|
||||||
of "epc-error":
|
returnEPC(client, uid, sexp(results))
|
||||||
stderr.writeln("recieved epc error: " & $messageBuffer)
|
of "return":
|
||||||
raise newException(ValueError, "epc error")
|
raise newException(EUnexpectedCommand, "no return expected")
|
||||||
of "methods":
|
of "return-error":
|
||||||
returnEPC(client, body[0].getStr, listEPC())
|
raise newException(EUnexpectedCommand, "no return expected")
|
||||||
else:
|
of "epc-error":
|
||||||
raise newException(ValueError, "unexpected call: " & messageType)
|
stderr.writeln("recieved epc error: " & $messageBuffer)
|
||||||
|
raise newException(IOError, "epc error")
|
||||||
|
of "methods":
|
||||||
|
returnEPC(client, body[0].getStr, listEPC())
|
||||||
|
else:
|
||||||
|
raise newException(EUnexpectedCommand, "unexpected call: " & messageType)
|
||||||
|
except:
|
||||||
|
returnEPC(client, body[0].getStr, sexp(getCurrentExceptionMsg()), "return-error")
|
||||||
|
|
||||||
proc mainCommand =
|
proc mainCommand =
|
||||||
registerPass verbosePass
|
registerPass verbosePass
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue