mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-27 19:06:31 +00:00
barebones in nimsuggest for EPC
This commit is contained in:
@@ -9,9 +9,9 @@
|
||||
|
||||
## Nimsuggest is a tool that helps to give editors IDE like capabilities.
|
||||
|
||||
import strutils, os, parseopt, parseUtils
|
||||
import strutils, os, parseopt, parseutils, sequtils
|
||||
import options, commands, modules, sem, passes, passaux, msgs, nimconf,
|
||||
extccomp, condsyms, lists, net, rdstdin, sexp
|
||||
extccomp, condsyms, lists, net, rdstdin, sexp, suggest, ast
|
||||
|
||||
const Usage = """
|
||||
Nimsuggest - Tool to give every editor IDE like capabilities for Nim
|
||||
@@ -54,6 +54,35 @@ proc parseQuoted(cmd: string; outp: var string; start: int): int =
|
||||
i += parseUntil(cmd, outp, seps, i)
|
||||
result = i
|
||||
|
||||
# make sure it's in the same order as the proc below
|
||||
let order: SexpNode =
|
||||
sexp(@["section", "symkind", "qualifiedPath", "filePath", "forth", "line", "column", "doc"].map(newSSymbol))
|
||||
|
||||
proc sexp(s: Section): SexpNode = sexp($s)
|
||||
|
||||
proc sexp(s: TSymKind): SexpNode = sexp($s)
|
||||
|
||||
proc sexp(s: Suggest): SexpNode =
|
||||
result = convertSexp([
|
||||
s.section,
|
||||
s.symkind,
|
||||
s.qualifiedPath.map(newSString),
|
||||
s.filePath,
|
||||
s.forth,
|
||||
s.line,
|
||||
s.column,
|
||||
s.doc
|
||||
])
|
||||
|
||||
proc sexp(s: seq[Suggest]): SexpNode =
|
||||
result = sexp(s)
|
||||
|
||||
proc listEPC(): SexpNode =
|
||||
discard
|
||||
|
||||
proc executeEPC(body: SexpNode) =
|
||||
discard
|
||||
|
||||
proc action(cmd: string) =
|
||||
template toggle(sw) =
|
||||
if sw in gGlobalOptions:
|
||||
@@ -138,7 +167,52 @@ proc serve() =
|
||||
stdoutSocket.send("\c\L")
|
||||
stdoutSocket.close()
|
||||
of mepc:
|
||||
discard
|
||||
let port = 98294 # guaranteed to be random
|
||||
var server = newSocket()
|
||||
server.bindaddr(port.Port, "localhost")
|
||||
var inp = "".TaintedString
|
||||
server.listen()
|
||||
echo(port)
|
||||
while true:
|
||||
var results: seq[Suggest] = @[]
|
||||
var client = newSocket()
|
||||
suggest.suggestionResultHook = proc (s: Suggest) =
|
||||
results.add(s)
|
||||
|
||||
accept(server, client)
|
||||
var sizeHex = ""
|
||||
if client.recv(sizeHex, 6, 1000) != 6:
|
||||
raise newException(ValueError, "didn't get all the hexbytes")
|
||||
var size = 0
|
||||
if parseHex(sizeHex, size) == 0:
|
||||
raiseRecoverableError("invalid size hex: " & $sizeHex)
|
||||
var messageBuffer = ""
|
||||
if client.recv(messageBuffer, size, 3000) != size:
|
||||
raise newException(ValueError, "didn't get all the bytes")
|
||||
let message = parseSexp($messageBuffer)
|
||||
let messageType = message[0].getSymbol
|
||||
let body = message[1]
|
||||
case messageType:
|
||||
of "call":
|
||||
executeEPC(body)
|
||||
let response = $sexp(results)
|
||||
client.send(toHex(len(response), 6))
|
||||
client.send(response)
|
||||
client.close()
|
||||
of "return":
|
||||
raise newException(ValueError, "no return expected")
|
||||
of "return-error":
|
||||
raise newException(ValueError, "no return expected")
|
||||
of "epc-error":
|
||||
stderr.writeln("recieved epc error: " & $messageBuffer)
|
||||
raise newException(ValueError, "epc error")
|
||||
of "methods":
|
||||
let response = $listEPC()
|
||||
client.send(toHex(len(response), 6))
|
||||
client.send(response)
|
||||
client.close()
|
||||
else:
|
||||
raise newException(ValueError, "unexpected call: " & messageType)
|
||||
|
||||
proc mainCommand =
|
||||
registerPass verbosePass
|
||||
@@ -169,7 +243,9 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string) =
|
||||
gAddress = p.val
|
||||
gMode = mtcp
|
||||
of "stdin": gMode = mstdin
|
||||
of "epc": gMode = mepc
|
||||
of "epc":
|
||||
gMode = mepc
|
||||
gVerbosity = 0 # Port number gotta be first.
|
||||
else: processSwitch(pass, p)
|
||||
of cmdArgument:
|
||||
options.gProjectName = unixToNativePath(p.key)
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
|
||||
# included from sigmatch.nim
|
||||
|
||||
import algorithm, sequtils, strutils
|
||||
import algorithm, sequtils, strutils, ast, msgs, options, renderer,
|
||||
types, docgen, lexer, semdata, astalgo, idents, sigmatch, lookups
|
||||
|
||||
const
|
||||
sep = '\t'
|
||||
@@ -21,16 +22,16 @@ const
|
||||
sectionUsage = "use"
|
||||
|
||||
type
|
||||
Section = enum sug, def, con, use
|
||||
Suggest = object
|
||||
section: Section
|
||||
qualifiedPath: seq[string]
|
||||
filePath: string
|
||||
line: int # Starts at 1
|
||||
column: int # Starts at 0
|
||||
doc: string # Not escaped (yet)
|
||||
symkind: TSymKind
|
||||
forth: string # XXX TODO object on symkind
|
||||
Section* = enum sug, def, con, use
|
||||
Suggest* = object
|
||||
section*: Section
|
||||
qualifiedPath*: seq[string]
|
||||
filePath*: string
|
||||
line*: int # Starts at 1
|
||||
column*: int # Starts at 0
|
||||
doc*: string # Not escaped (yet)
|
||||
symkind*: TSymKind
|
||||
forth*: string # XXX TODO object on symkind
|
||||
|
||||
var
|
||||
suggestionResultHook*: proc (result: Suggest) {.closure.}
|
||||
|
||||
Reference in New Issue
Block a user