summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2013-05-05 15:12:50 +0300
committerZahary Karadjov <zahary@gmail.com>2013-05-05 15:12:50 +0300
commitf52ea04d229b5cdf70a352efd93e0e01fa8faadf (patch)
treec636ed75f8f00380397c47ac571275ac3215c2a9 /compiler
parent5a2720e99075166d2192fd40927f695f58124028 (diff)
downloadNim-f52ea04d229b5cdf70a352efd93e0e01fa8faadf.tar.gz
support suggest after compile in caas mode
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ast.nim1
-rw-r--r--compiler/commands.nim19
-rw-r--r--compiler/main.nim7
-rw-r--r--compiler/msgs.nim14
-rw-r--r--compiler/options.nim6
-rw-r--r--compiler/service.nim4
6 files changed, 44 insertions, 7 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index aee99c833..bcfb946ca 100644
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -275,6 +275,7 @@ const
 
   sfDirty* = sfPure
     # template is not hygienic (old styled template)
+    # module, compiled from a dirty-buffer
 
   sfAnon* = sfDiscardable
     # symbol name that was generated by the compiler
diff --git a/compiler/commands.nim b/compiler/commands.nim
index de52a4062..63704b328 100644
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -207,6 +207,22 @@ proc processPath(path: string, notRelativeToProj = false): string =
     "projectname", options.gProjectName,
     "projectpath", options.gProjectPath])
 
+proc trackDirty(arg: string, info: TLineInfo) =
+  var a = arg.split(',')
+  if a.len != 4: LocalError(info, errTokenExpected,
+                            "DIRTY_BUFFER,ORIGINAL_FILE,LINE,COLUMN")
+  var line, column: int
+  if parseUtils.parseInt(a[2], line) <= 0:
+    LocalError(info, errInvalidNumber, a[1])
+  if parseUtils.parseInt(a[3], column) <= 0:
+    LocalError(info, errInvalidNumber, a[2])
+  
+  gDirtyBufferIdx = a[0].fileInfoIdx
+  gDirtyOriginalIdx = a[1].fileInfoIdx
+ 
+  optTrackPos = newLineInfo(gDirtyBufferIdx, line, column)
+  msgs.addCheckpoint(optTrackPos)
+
 proc track(arg: string, info: TLineInfo) = 
   var a = arg.split(',')
   if a.len != 3: LocalError(info, errTokenExpected, "FILE,LINE,COLUMN")
@@ -470,6 +486,9 @@ proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) =
   of "track":
     expectArg(switch, arg, pass, info)
     track(arg, info)
+  of "trackdirty":
+    expectArg(switch, arg, pass, info)
+    trackDirty(arg, info)
   of "suggest": 
     expectNoArg(switch, arg, pass, info)
     incl(gGlobalOptions, optSuggest)
diff --git a/compiler/main.nim b/compiler/main.nim
index dde18825e..c9b3967e5 100644
--- a/compiler/main.nim
+++ b/compiler/main.nim
@@ -150,7 +150,12 @@ proc newModule(fileIdx: int32): PSym =
   initStrTable(result.tab)
   StrTableAdd(result.tab, result) # a module knows itself
 
-proc compileModule(fileIdx: int32, flags: TSymFlags): PSym =
+proc compileModule(fileIdxArg: int32, flagsArg: TSymFlags): PSym =
+  let (fileIdx, flags) = if fileIdxArg == gDirtyOriginalIdx:
+                           (gDirtyBufferIdx, flagsArg + {sfDirty})
+                         else:
+                           (fileIdxArg, flagsArg)
+  
   result = getModule(fileIdx)
   if result == nil:
     growCache gMemCacheData, fileIdx
diff --git a/compiler/msgs.nim b/compiler/msgs.nim
index a1eaf23bb..b38d67b55 100644
--- a/compiler/msgs.nim
+++ b/compiler/msgs.nim
@@ -526,13 +526,17 @@ proc SuggestWriteln*(s: string) =
     else: 
       Writeln(stdout, s)
       stdoutSocket.send(s & "\c\L")
-    
+
 proc SuggestQuit*() =
-  if not isServing: quit(0)
-  elif not isNil(stdoutSocket):
-    stdoutSocket.send("\c\L")
+  if not isServing:
+    quit(0)
+  elif isWorkingWithDirtyBuffer:
+    # No need to compile the rest if we are working with a
+    # throw-away buffer. Incomplete dot expressions frequently
+    # found in dirty buffers will result in errors few steps
+    # from now anyway.
     raise newException(ESuggestDone, "suggest done")
-  
+
 # this format is understood by many text editors: it is the same that
 # Borland and Freepascal use
 const
diff --git a/compiler/options.nim b/compiler/options.nim
index a7d513dc5..3b71dca47 100644
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -106,10 +106,16 @@ var
   gLastCmdTime*: float        # when caas is enabled, we measure each command
   gListFullPaths*: bool
   isServing*: bool = false
+  gDirtyBufferIdx* = 0'i32    # indicates the fileIdx of the dirty version of
+                              # the tracked source X, saved by the CAAS client.
+  gDirtyOriginalIdx* = 0'i32  # the original source file of the dirtified buffer.
 
 proc importantComments*(): bool {.inline.} = gCmd in {cmdDoc, cmdIdeTools}
 proc usesNativeGC*(): bool {.inline.} = gSelectedGC >= gcRefc
 
+template isWorkingWithDirtyBuffer*: expr =
+  gDirtyBufferIdx != 0
+
 template compilationCachePresent*: expr =
   {optCaasEnabled, optSymbolFiles} * gGlobalOptions != {}
 
diff --git a/compiler/service.nim b/compiler/service.nim
index b3c7fbc83..6a0cfd292 100644
--- a/compiler/service.nim
+++ b/compiler/service.nim
@@ -65,7 +65,9 @@ proc serve*(action: proc (){.nimcall.}) =
     curCaasCmd = cmd
     processCmdLine(passCmd2, cmd)
     action()
-
+    gDirtyBufferIdx = 0
+    gDirtyOriginalIdx = 0
+    
   let typ = getConfigVar("server.type")
   case typ
   of "stdin":