support suggest after compile in caas mode

This commit is contained in:
Zahary Karadjov
2013-05-05 15:12:50 +03:00
parent 5a2720e990
commit f52ea04d22
9 changed files with 72 additions and 7 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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 != {}

View File

@@ -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":

View File

@@ -0,0 +1,7 @@
main.nim
> c
SuccessX
> idetools --trackDirty:main_dirty.nim,main.nim,12,7 --suggest main.nim
skField\tx
skField\ty

14
tests/caas/main_dirty.nim Normal file
View File

@@ -0,0 +1,14 @@
import imported, strutils
type
TFoo = object
x: int
y: string
proc main =
var t1 = "text"
var t2 = t1.toUpper
var foo = TFoo(x: 10, y: "test")
foo.
echo(t1 +++ t2)

View File

@@ -0,0 +1,7 @@
main.nim
> idetools --trackDirty:main_dirty.nim,main.nim,12,7 --suggest main.nim
skField\tx
skField\ty
> c
SuccessX