diff options
Diffstat (limited to 'compiler/suggest.nim')
-rw-r--r-- | compiler/suggest.nim | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/compiler/suggest.nim b/compiler/suggest.nim index 659f1fa16..c15a56c54 100644 --- a/compiler/suggest.nim +++ b/compiler/suggest.nim @@ -34,7 +34,7 @@ var 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 = parseIdeCmd(section) if optIdeTerse in gGlobalOptions: result.symkind = s.kind @@ -52,7 +52,7 @@ proc symToSuggest(s: PSym, isLocal: bool, section: string, li: TLineInfo): Sugge result.qualifiedPath.add(ow.origModuleName) result.qualifiedPath.add(s.name.s) - if s.typ != nil: + if s.typ != nil: result.forth = typeToString(s.typ) else: result.forth = "" @@ -62,7 +62,7 @@ proc symToSuggest(s: PSym, isLocal: bool, section: string, li: TLineInfo): Sugge when not defined(noDocgen): result.doc = s.extractDocComment -proc `$`(suggest: Suggest): string = +proc `$`(suggest: Suggest): string = result = $suggest.section result.add(sep) result.add($suggest.symkind) @@ -80,7 +80,7 @@ proc `$`(suggest: Suggest): string = when not defined(noDocgen): result.add(suggest.doc.escape) -proc symToSuggest(s: PSym, isLocal: bool, section: string): Suggest = +proc symToSuggest(s: PSym, isLocal: bool, section: string): Suggest = result = symToSuggest(s, isLocal, section, s.info) proc suggestResult(s: Suggest) = @@ -104,7 +104,7 @@ proc fieldVisible*(c: PContext, f: PSym): bool {.inline.} = result = true break -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): suggestResult(symToSuggest(s, isLocal=true, $ideSug)) inc outputs @@ -122,17 +122,17 @@ template wholeSymTab(cond, section: expr) {.immediate.} = suggestResult(symToSuggest(it, isLocal = isLocal, section)) inc outputs -proc suggestSymList(c: PContext, list: PNode, outputs: var int) = - for i in countup(0, sonsLen(list) - 1): +proc suggestSymList(c: PContext, list: PNode, outputs: var int) = + for i in countup(0, sonsLen(list) - 1): if list.sons[i].kind == nkSym: suggestField(c, list.sons[i].sym, outputs) #else: InternalError(list.info, "getSymFromList") -proc suggestObject(c: PContext, n: PNode, outputs: var int) = +proc suggestObject(c: PContext, n: PNode, outputs: var int) = case n.kind - of nkRecList: + of nkRecList: for i in countup(0, sonsLen(n)-1): suggestObject(c, n.sons[i], outputs) - of nkRecCase: + of nkRecCase: var L = sonsLen(n) if L > 0: suggestObject(c, n.sons[0], outputs) @@ -140,7 +140,7 @@ proc suggestObject(c: PContext, n: PNode, outputs: var int) = of nkSym: suggestField(c, n.sym, outputs) else: discard -proc nameFits(c: PContext, s: PSym, n: PNode): bool = +proc nameFits(c: PContext, s: PSym, n: PNode): bool = var op = n.sons[0] if op.kind in {nkOpenSymChoice, nkClosedSymChoice}: op = op.sons[0] var opr: PIdent @@ -150,8 +150,8 @@ proc nameFits(c: PContext, s: PSym, n: PNode): bool = else: return false result = opr.id == s.name.id -proc argsFit(c: PContext, candidate: PSym, n, nOrig: PNode): bool = - case candidate.kind +proc argsFit(c: PContext, candidate: PSym, n, nOrig: PNode): bool = + case candidate.kind of OverloadableSyms: var m: TCandidate initCandidate(c, m, candidate, nil) @@ -160,11 +160,11 @@ proc argsFit(c: PContext, candidate: PSym, n, nOrig: PNode): bool = else: result = false -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), $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: # special rule: if system and some weird generic match via 'tyExpr' # or 'tyGenericParam' we won't list it either to reduce the noise (nobody @@ -198,48 +198,48 @@ proc suggestFieldAccess(c: PContext, n: PNode, outputs: var int) = var typ = n.typ if typ == nil: # a module symbol has no type for example: - if n.kind == nkSym and n.sym.kind == skModule: - if n.sym == c.module: + if n.kind == nkSym and n.sym.kind == skModule: + if n.sym == c.module: # all symbols accessible, because we are in the current module: for it in items(c.topLevelScope.symbols): - if filterSym(it): + if filterSym(it): suggestResult(symToSuggest(it, isLocal=false, $ideSug)) inc outputs - else: - for it in items(n.sym.tab): - if filterSym(it): + else: + for it in items(n.sym.tab): + if filterSym(it): suggestResult(symToSuggest(it, isLocal=false, $ideSug)) inc outputs else: # fallback: suggestEverything(c, n, outputs) - elif typ.kind == tyEnum and n.kind == nkSym and n.sym.kind == skType: + elif typ.kind == tyEnum and n.kind == nkSym and n.sym.kind == skType: # look up if the identifier belongs to the enum: var t = typ - while t != nil: + while t != nil: suggestSymList(c, t.n, outputs) t = t.sons[0] suggestOperations(c, n, typ, outputs) else: typ = skipTypes(typ, {tyGenericInst, tyVar, tyPtr, tyRef}) - if typ.kind == tyObject: + if typ.kind == tyObject: var t = typ - while true: + while true: suggestObject(c, t.n, outputs) - if t.sons[0] == nil: break + if t.sons[0] == nil: break t = skipTypes(t.sons[0], {tyGenericInst}) suggestOperations(c, n, typ, outputs) - elif typ.kind == tyTuple and typ.n != nil: + elif typ.kind == tyTuple and typ.n != nil: suggestSymList(c, typ.n, outputs) suggestOperations(c, n, typ, outputs) else: suggestOperations(c, n, typ, outputs) type - TCheckPointResult = enum + TCheckPointResult = enum cpNone, cpFuzzy, cpExact -proc inCheckpoint(current: TLineInfo): TCheckPointResult = +proc inCheckpoint(current: TLineInfo): TCheckPointResult = if current.fileIndex == gTrackPos.fileIndex: if current.line == gTrackPos.line and abs(current.col-gTrackPos.col) < 4: @@ -255,8 +255,8 @@ proc findClosestDot(n: PNode): PNode = result = findClosestDot(n.sons[i]) if result != nil: return -proc findClosestCall(n: PNode): PNode = - if n.kind in nkCallKinds and inCheckpoint(n.info) == cpExact: +proc findClosestCall(n: PNode): PNode = + if n.kind in nkCallKinds and inCheckpoint(n.info) == cpExact: result = n else: for i in 0.. <safeLen(n): @@ -270,8 +270,8 @@ proc isTracked(current: TLineInfo, tokenLen: int): bool = if col >= current.col and col <= current.col+tokenLen-1: return true -proc findClosestSym(n: PNode): PNode = - if n.kind == nkSym and inCheckpoint(n.info) == cpExact: +proc findClosestSym(n: PNode): PNode = + if n.kind == nkSym and inCheckpoint(n.info) == cpExact: result = n elif n.kind notin {nkNone..nkNilLit}: for i in 0.. <sonsLen(n): @@ -328,7 +328,7 @@ proc safeSemExpr*(c: PContext, n: PNode): PNode = except ERecoverableError: result = ast.emptyNode -proc suggestExpr*(c: PContext, node: PNode) = +proc suggestExpr*(c: PContext, node: PNode) = if nfIsCursor notin node.flags: if gTrackPos.line < 0: return var cp = inCheckpoint(node.info) @@ -349,7 +349,7 @@ proc suggestExpr*(c: PContext, node: PNode) = #writeStackTrace() else: suggestEverything(c, n, outputs) - + elif gIdeCmd == ideCon: var n = if nfIsCursor in node.flags: node else: findClosestCall(node) if n == nil: n = node @@ -364,9 +364,9 @@ proc suggestExpr*(c: PContext, node: PNode) = if x.kind == nkEmpty or x.typ == nil: break addSon(a, x) suggestCall(c, a, n, outputs) - + dec(c.inCompilesContext) if outputs > 0 and gIdeCmd != ideUse: suggestQuit() -proc suggestStmt*(c: PContext, n: PNode) = +proc suggestStmt*(c: PContext, n: PNode) = suggestExpr(c, n) |