mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
support suggest after compile in caas mode
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 != {}
|
||||
|
||||
|
||||
@@ -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":
|
||||
|
||||
7
tests/caas/compile-suggest.txt
Normal file
7
tests/caas/compile-suggest.txt
Normal 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
14
tests/caas/main_dirty.nim
Normal 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)
|
||||
|
||||
7
tests/caas/suggest-compile.txt
Normal file
7
tests/caas/suggest-compile.txt
Normal 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
|
||||
|
||||
Reference in New Issue
Block a user