summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorSimon Hafner <hafnersimon@gmail.com>2015-04-22 21:53:04 +0500
committerSimon Hafner <hafnersimon@gmail.com>2015-04-22 21:53:04 +0500
commit7d42eb2de2ef85925c2a933e71f7fad3ab411bce (patch)
tree4ec7d9d09bd561f6ef01e9e13a33be29eccf5e20 /compiler
parentf0f72613d87f5bd742eb64f61b75567c205e62e8 (diff)
downloadNim-7d42eb2de2ef85925c2a933e71f7fad3ab411bce.tar.gz
barebones in nimsuggest for EPC
Diffstat (limited to 'compiler')
-rw-r--r--compiler/nimsuggest/nimsuggest.nim84
-rw-r--r--compiler/suggest.nim23
2 files changed, 92 insertions, 15 deletions
diff --git a/compiler/nimsuggest/nimsuggest.nim b/compiler/nimsuggest/nimsuggest.nim
index caf21fbd0..d6bd01ce7 100644
--- a/compiler/nimsuggest/nimsuggest.nim
+++ b/compiler/nimsuggest/nimsuggest.nim
@@ -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)
diff --git a/compiler/suggest.nim b/compiler/suggest.nim
index 97d0b51c2..539d4bc5d 100644
--- a/compiler/suggest.nim
+++ b/compiler/suggest.nim
@@ -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.}