removed a few consts and rewired to IdeCmd
This commit is contained in:
parent
6836d45398
commit
33edba665d
2 changed files with 28 additions and 18 deletions
|
|
@ -83,11 +83,11 @@ type # please make sure we have under 32 options
|
||||||
TGCMode* = enum # the selected GC
|
TGCMode* = enum # the selected GC
|
||||||
gcNone, gcBoehm, gcMarkAndSweep, gcRefc, gcV2, gcGenerational
|
gcNone, gcBoehm, gcMarkAndSweep, gcRefc, gcV2, gcGenerational
|
||||||
|
|
||||||
TIdeCmd* = enum
|
IdeCmd* = enum
|
||||||
ideNone, ideSug, ideCon, ideDef, ideUse
|
ideNone, ideSug, ideCon, ideDef, ideUse
|
||||||
|
|
||||||
var
|
var
|
||||||
gIdeCmd*: TIdeCmd
|
gIdeCmd*: IdeCmd
|
||||||
|
|
||||||
const
|
const
|
||||||
ChecksOptions* = {optObjCheck, optFieldCheck, optRangeCheck, optNilCheck,
|
ChecksOptions* = {optObjCheck, optFieldCheck, optRangeCheck, optNilCheck,
|
||||||
|
|
@ -395,3 +395,18 @@ template cnimdbg*: expr = p.module.module.fileIdx == gProjectMainIdx
|
||||||
template pnimdbg*: expr = p.lex.fileIdx == gProjectMainIdx
|
template pnimdbg*: expr = p.lex.fileIdx == gProjectMainIdx
|
||||||
template lnimdbg*: expr = L.fileIdx == gProjectMainIdx
|
template lnimdbg*: expr = L.fileIdx == gProjectMainIdx
|
||||||
|
|
||||||
|
proc parseIdeCmd*(s: string): IdeCmd =
|
||||||
|
case s:
|
||||||
|
of "sug": ideSug
|
||||||
|
of "con": ideCon
|
||||||
|
of "def": ideDef
|
||||||
|
of "use": ideUse
|
||||||
|
else: ideNone
|
||||||
|
|
||||||
|
proc `$`*(c: IdeCmd): string =
|
||||||
|
case c:
|
||||||
|
of ideSug: "sug"
|
||||||
|
of ideCon: "con"
|
||||||
|
of ideDef: "def"
|
||||||
|
of ideUse: "use"
|
||||||
|
of ideNone: "none"
|
||||||
|
|
|
||||||
|
|
@ -16,15 +16,10 @@ import algorithm, sequtils, strutils, ast, msgs, options, renderer,
|
||||||
|
|
||||||
const
|
const
|
||||||
sep = '\t'
|
sep = '\t'
|
||||||
sectionSuggest = "sug"
|
|
||||||
sectionDef = "def"
|
|
||||||
sectionContext = "con"
|
|
||||||
sectionUsage = "use"
|
|
||||||
|
|
||||||
type
|
type
|
||||||
Section* = enum sug, def, con, use
|
|
||||||
Suggest* = object
|
Suggest* = object
|
||||||
section*: Section
|
section*: IdeCmd
|
||||||
qualifiedPath*: seq[string]
|
qualifiedPath*: seq[string]
|
||||||
filePath*: string
|
filePath*: string
|
||||||
line*: int # Starts at 1
|
line*: int # Starts at 1
|
||||||
|
|
@ -41,7 +36,7 @@ var
|
||||||
template origModuleName(m: PSym): string = m.name.s
|
template origModuleName(m: PSym): string = m.name.s
|
||||||
|
|
||||||
proc symToSuggest(s: PSym, isLocal: bool, section: string, li: TLineInfo): Suggest =
|
proc symToSuggest(s: PSym, isLocal: bool, section: string, li: TLineInfo): Suggest =
|
||||||
result.section = parseEnum[Section](section)
|
result.section = parseIdeCmd(section)
|
||||||
if optIdeTerse in gGlobalOptions:
|
if optIdeTerse in gGlobalOptions:
|
||||||
if s.kind in routineKinds:
|
if s.kind in routineKinds:
|
||||||
result.symkind = parseEnum[TSymKind](renderTree(s.ast, {renderNoBody, renderNoComments,
|
result.symkind = parseEnum[TSymKind](renderTree(s.ast, {renderNoBody, renderNoComments,
|
||||||
|
|
@ -116,7 +111,7 @@ proc fieldVisible*(c: PContext, f: PSym): bool {.inline.} =
|
||||||
|
|
||||||
proc suggestField(c: PContext, s: PSym, outputs: var int) =
|
proc suggestField(c: PContext, s: PSym, outputs: var int) =
|
||||||
if filterSym(s) and fieldVisible(c, s):
|
if filterSym(s) and fieldVisible(c, s):
|
||||||
suggestResult(symToSuggest(s, isLocal=true, sectionSuggest))
|
suggestResult(symToSuggest(s, isLocal=true, $ideSug))
|
||||||
inc outputs
|
inc outputs
|
||||||
|
|
||||||
template wholeSymTab(cond, section: expr) {.immediate.} =
|
template wholeSymTab(cond, section: expr) {.immediate.} =
|
||||||
|
|
@ -172,7 +167,7 @@ proc argsFit(c: PContext, candidate: PSym, n, nOrig: PNode): bool =
|
||||||
|
|
||||||
proc suggestCall(c: PContext, n, nOrig: PNode, outputs: var int) =
|
proc suggestCall(c: PContext, n, nOrig: PNode, outputs: var int) =
|
||||||
wholeSymTab(filterSym(it) and nameFits(c, it, n) and argsFit(c, it, n, nOrig),
|
wholeSymTab(filterSym(it) and nameFits(c, it, n) and argsFit(c, it, n, nOrig),
|
||||||
sectionContext)
|
$ideCon)
|
||||||
|
|
||||||
proc typeFits(c: PContext, s: PSym, firstArg: PType): bool {.inline.} =
|
proc typeFits(c: PContext, s: PSym, firstArg: PType): bool {.inline.} =
|
||||||
if s.typ != nil and sonsLen(s.typ) > 1 and s.typ.sons[1] != nil:
|
if s.typ != nil and sonsLen(s.typ) > 1 and s.typ.sons[1] != nil:
|
||||||
|
|
@ -189,7 +184,7 @@ proc typeFits(c: PContext, s: PSym, firstArg: PType): bool {.inline.} =
|
||||||
|
|
||||||
proc suggestOperations(c: PContext, n: PNode, typ: PType, outputs: var int) =
|
proc suggestOperations(c: PContext, n: PNode, typ: PType, outputs: var int) =
|
||||||
assert typ != nil
|
assert typ != nil
|
||||||
wholeSymTab(filterSymNoOpr(it) and typeFits(c, it, typ), sectionSuggest)
|
wholeSymTab(filterSymNoOpr(it) and typeFits(c, it, typ), $ideSug)
|
||||||
|
|
||||||
proc suggestEverything(c: PContext, n: PNode, outputs: var int) =
|
proc suggestEverything(c: PContext, n: PNode, outputs: var int) =
|
||||||
# do not produce too many symbols:
|
# do not produce too many symbols:
|
||||||
|
|
@ -198,7 +193,7 @@ proc suggestEverything(c: PContext, n: PNode, outputs: var int) =
|
||||||
if scope == c.topLevelScope: isLocal = false
|
if scope == c.topLevelScope: isLocal = false
|
||||||
for it in items(scope.symbols):
|
for it in items(scope.symbols):
|
||||||
if filterSym(it):
|
if filterSym(it):
|
||||||
suggestResult(symToSuggest(it, isLocal = isLocal, sectionSuggest))
|
suggestResult(symToSuggest(it, isLocal = isLocal, $ideSug))
|
||||||
inc outputs
|
inc outputs
|
||||||
if scope == c.topLevelScope: break
|
if scope == c.topLevelScope: break
|
||||||
|
|
||||||
|
|
@ -213,12 +208,12 @@ proc suggestFieldAccess(c: PContext, n: PNode, outputs: var int) =
|
||||||
# all symbols accessible, because we are in the current module:
|
# all symbols accessible, because we are in the current module:
|
||||||
for it in items(c.topLevelScope.symbols):
|
for it in items(c.topLevelScope.symbols):
|
||||||
if filterSym(it):
|
if filterSym(it):
|
||||||
suggestResult(symToSuggest(it, isLocal=false, sectionSuggest))
|
suggestResult(symToSuggest(it, isLocal=false, $ideSug))
|
||||||
inc outputs
|
inc outputs
|
||||||
else:
|
else:
|
||||||
for it in items(n.sym.tab):
|
for it in items(n.sym.tab):
|
||||||
if filterSym(it):
|
if filterSym(it):
|
||||||
suggestResult(symToSuggest(it, isLocal=false, sectionSuggest))
|
suggestResult(symToSuggest(it, isLocal=false, $ideSug))
|
||||||
inc outputs
|
inc outputs
|
||||||
else:
|
else:
|
||||||
# fallback:
|
# fallback:
|
||||||
|
|
@ -295,16 +290,16 @@ var
|
||||||
proc findUsages(info: TLineInfo; s: PSym) =
|
proc findUsages(info: TLineInfo; s: PSym) =
|
||||||
if usageSym == nil and isTracked(info, s.name.s.len):
|
if usageSym == nil and isTracked(info, s.name.s.len):
|
||||||
usageSym = s
|
usageSym = s
|
||||||
suggestResult(symToSuggest(s, isLocal=false, sectionUsage))
|
suggestResult(symToSuggest(s, isLocal=false, $ideUse))
|
||||||
elif s == usageSym:
|
elif s == usageSym:
|
||||||
if lastLineInfo != info:
|
if lastLineInfo != info:
|
||||||
suggestResult(symToSuggest(s, isLocal=false, sectionUsage, info))
|
suggestResult(symToSuggest(s, isLocal=false, $ideUse, info))
|
||||||
lastLineInfo = info
|
lastLineInfo = info
|
||||||
|
|
||||||
proc findDefinition(info: TLineInfo; s: PSym) =
|
proc findDefinition(info: TLineInfo; s: PSym) =
|
||||||
if s.isNil: return
|
if s.isNil: return
|
||||||
if isTracked(info, s.name.s.len):
|
if isTracked(info, s.name.s.len):
|
||||||
suggestResult(symToSuggest(s, isLocal=false, sectionDef))
|
suggestResult(symToSuggest(s, isLocal=false, $ideDef))
|
||||||
suggestQuit()
|
suggestQuit()
|
||||||
|
|
||||||
proc ensureIdx[T](x: var T, y: int) =
|
proc ensureIdx[T](x: var T, y: int) =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue