idetools: don't suggest module names or not visible object fields
This commit is contained in:
parent
344438ce6a
commit
a7a2f464a2
2 changed files with 21 additions and 18 deletions
|
|
@ -866,10 +866,8 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
if f != nil: break
|
if f != nil: break
|
||||||
if ty.sons[0] == nil: break
|
if ty.sons[0] == nil: break
|
||||||
ty = skipTypes(ty.sons[0], {tyGenericInst})
|
ty = skipTypes(ty.sons[0], {tyGenericInst})
|
||||||
if f != nil:
|
if f != nil:
|
||||||
var fmoduleId = getModule(f).id
|
if fieldVisible(c, f):
|
||||||
if sfExported in f.flags or fmoduleId == c.module.id or
|
|
||||||
fmoduleId == c.friendModule.id:
|
|
||||||
# is the access to a public field or in the same module or in a friend?
|
# is the access to a public field or in the same module or in a friend?
|
||||||
n.sons[0] = makeDeref(n.sons[0])
|
n.sons[0] = makeDeref(n.sons[0])
|
||||||
n.sons[1] = newSymNode(f) # we now have the correct field
|
n.sons[1] = newSymNode(f) # we now have the correct field
|
||||||
|
|
|
||||||
|
|
@ -42,11 +42,16 @@ proc SymToStr(s: PSym, isLocal: bool, section: string, li: TLineInfo): string =
|
||||||
proc SymToStr(s: PSym, isLocal: bool, section: string): string =
|
proc SymToStr(s: PSym, isLocal: bool, section: string): string =
|
||||||
result = SymToStr(s, isLocal, section, s.info)
|
result = SymToStr(s, isLocal, section, s.info)
|
||||||
|
|
||||||
proc filterSym(s: PSym): bool {.inline.} =
|
proc filterSym(s: PSym): bool {.inline.} =
|
||||||
result = s.name.s[0] in lexer.SymChars
|
result = s.name.s[0] in lexer.SymChars and s.kind != skModule
|
||||||
|
|
||||||
proc suggestField(s: PSym, outputs: var int) =
|
proc fieldVisible*(c: PContext, f: PSym): bool {.inline.} =
|
||||||
if filterSym(s):
|
let fmoduleId = getModule(f).id
|
||||||
|
result = sfExported in f.flags or fmoduleId == c.module.id or
|
||||||
|
fmoduleId == c.friendModule.id
|
||||||
|
|
||||||
|
proc suggestField(c: PContext, s: PSym, outputs: var int) =
|
||||||
|
if filterSym(s) and fieldVisible(c, s):
|
||||||
OutWriteln(SymToStr(s, isLocal=true, sectionSuggest))
|
OutWriteln(SymToStr(s, isLocal=true, sectionSuggest))
|
||||||
inc outputs
|
inc outputs
|
||||||
|
|
||||||
|
|
@ -57,22 +62,22 @@ template wholeSymTab(cond, section: expr) {.immediate.} =
|
||||||
OutWriteln(SymToStr(it, isLocal = i > ModuleTablePos, section))
|
OutWriteln(SymToStr(it, isLocal = i > ModuleTablePos, section))
|
||||||
inc outputs
|
inc outputs
|
||||||
|
|
||||||
proc suggestSymList(list: PNode, outputs: var int) =
|
proc suggestSymList(c: PContext, list: PNode, outputs: var int) =
|
||||||
for i in countup(0, sonsLen(list) - 1):
|
for i in countup(0, sonsLen(list) - 1):
|
||||||
if list.sons[i].kind == nkSym:
|
if list.sons[i].kind == nkSym:
|
||||||
suggestField(list.sons[i].sym, outputs)
|
suggestField(c, list.sons[i].sym, outputs)
|
||||||
#else: InternalError(list.info, "getSymFromList")
|
#else: InternalError(list.info, "getSymFromList")
|
||||||
|
|
||||||
proc suggestObject(n: PNode, outputs: var int) =
|
proc suggestObject(c: PContext, n: PNode, outputs: var int) =
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkRecList:
|
of nkRecList:
|
||||||
for i in countup(0, sonsLen(n)-1): suggestObject(n.sons[i], outputs)
|
for i in countup(0, sonsLen(n)-1): suggestObject(c, n.sons[i], outputs)
|
||||||
of nkRecCase:
|
of nkRecCase:
|
||||||
var L = sonsLen(n)
|
var L = sonsLen(n)
|
||||||
if L > 0:
|
if L > 0:
|
||||||
suggestObject(n.sons[0], outputs)
|
suggestObject(c, n.sons[0], outputs)
|
||||||
for i in countup(1, L-1): suggestObject(lastSon(n.sons[i]), outputs)
|
for i in countup(1, L-1): suggestObject(c, lastSon(n.sons[i]), outputs)
|
||||||
of nkSym: suggestField(n.sym, outputs)
|
of nkSym: suggestField(c, n.sym, outputs)
|
||||||
else: nil
|
else: nil
|
||||||
|
|
||||||
proc nameFits(c: PContext, s: PSym, n: PNode): bool =
|
proc nameFits(c: PContext, s: PSym, n: PNode): bool =
|
||||||
|
|
@ -140,7 +145,7 @@ proc suggestFieldAccess(c: PContext, n: PNode, outputs: var int) =
|
||||||
# look up if the identifier belongs to the enum:
|
# look up if the identifier belongs to the enum:
|
||||||
var t = typ
|
var t = typ
|
||||||
while t != nil:
|
while t != nil:
|
||||||
suggestSymList(t.n, outputs)
|
suggestSymList(c, t.n, outputs)
|
||||||
t = t.sons[0]
|
t = t.sons[0]
|
||||||
suggestOperations(c, n, typ, outputs)
|
suggestOperations(c, n, typ, outputs)
|
||||||
else:
|
else:
|
||||||
|
|
@ -148,12 +153,12 @@ proc suggestFieldAccess(c: PContext, n: PNode, outputs: var int) =
|
||||||
if typ.kind == tyObject:
|
if typ.kind == tyObject:
|
||||||
var t = typ
|
var t = typ
|
||||||
while true:
|
while true:
|
||||||
suggestObject(t.n, outputs)
|
suggestObject(c, t.n, outputs)
|
||||||
if t.sons[0] == nil: break
|
if t.sons[0] == nil: break
|
||||||
t = skipTypes(t.sons[0], {tyGenericInst})
|
t = skipTypes(t.sons[0], {tyGenericInst})
|
||||||
suggestOperations(c, n, typ, outputs)
|
suggestOperations(c, n, typ, outputs)
|
||||||
elif typ.kind == tyTuple and typ.n != nil:
|
elif typ.kind == tyTuple and typ.n != nil:
|
||||||
suggestSymList(typ.n, outputs)
|
suggestSymList(c, typ.n, outputs)
|
||||||
suggestOperations(c, n, typ, outputs)
|
suggestOperations(c, n, typ, outputs)
|
||||||
else:
|
else:
|
||||||
suggestOperations(c, n, typ, outputs)
|
suggestOperations(c, n, typ, outputs)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue