fixed nim-lang/nimsuggest#82 pure enum field sug (#16676)
- previous code wasn't account for tyEnum being wrapped in tyTypeDesc - now pure enum fields are suggested
This commit is contained in:
parent
f6c2450cdb
commit
bbc96f974d
2 changed files with 29 additions and 10 deletions
|
|
@ -386,17 +386,17 @@ proc suggestFieldAccess(c: PContext, n, field: PNode, outputs: var Suggestions)
|
||||||
else:
|
else:
|
||||||
# fallback:
|
# fallback:
|
||||||
suggestEverything(c, n, field, outputs)
|
suggestEverything(c, n, field, outputs)
|
||||||
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:
|
|
||||||
suggestSymList(c, t.n, field, n.info, outputs)
|
|
||||||
t = t[0]
|
|
||||||
suggestOperations(c, n, field, typ, outputs)
|
|
||||||
else:
|
else:
|
||||||
let orig = typ # skipTypes(typ, {tyGenericInst, tyAlias, tySink})
|
let orig = typ
|
||||||
typ = skipTypes(typ, {tyGenericInst, tyVar, tyLent, tyPtr, tyRef, tyAlias, tySink, tyOwned})
|
typ = skipTypes(orig, {tyTypeDesc, tyGenericInst, tyVar, tyLent, tyPtr, tyRef, tyAlias, tySink, tyOwned})
|
||||||
if typ.kind == tyObject:
|
|
||||||
|
if 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:
|
||||||
|
suggestSymList(c, t.n, field, n.info, outputs)
|
||||||
|
t = t[0]
|
||||||
|
elif typ.kind == tyObject:
|
||||||
var t = typ
|
var t = typ
|
||||||
while true:
|
while true:
|
||||||
suggestObject(c, t.n, field, n.info, outputs)
|
suggestObject(c, t.n, field, n.info, outputs)
|
||||||
|
|
@ -404,6 +404,7 @@ proc suggestFieldAccess(c: PContext, n, field: PNode, outputs: var Suggestions)
|
||||||
t = skipTypes(t[0], skipPtrs)
|
t = skipTypes(t[0], skipPtrs)
|
||||||
elif typ.kind == tyTuple and typ.n != nil:
|
elif typ.kind == tyTuple and typ.n != nil:
|
||||||
suggestSymList(c, typ.n, field, n.info, outputs)
|
suggestSymList(c, typ.n, field, n.info, outputs)
|
||||||
|
|
||||||
suggestOperations(c, n, field, orig, outputs)
|
suggestOperations(c, n, field, orig, outputs)
|
||||||
if typ != orig:
|
if typ != orig:
|
||||||
suggestOperations(c, n, field, typ, outputs)
|
suggestOperations(c, n, field, typ, outputs)
|
||||||
|
|
|
||||||
18
nimsuggest/tests/tsug_enum.nim
Normal file
18
nimsuggest/tests/tsug_enum.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
## suggestions for enums
|
||||||
|
|
||||||
|
type
|
||||||
|
LogLevel {.pure.} = enum
|
||||||
|
debug, log, warn, error
|
||||||
|
|
||||||
|
FooBar = enum
|
||||||
|
fbFoo, fbBar
|
||||||
|
|
||||||
|
echo fbFoo, fbBar
|
||||||
|
|
||||||
|
echo LogLevel.deb#[!]#
|
||||||
|
|
||||||
|
discard """
|
||||||
|
$nimsuggest --tester $file
|
||||||
|
>sug $1
|
||||||
|
sug;;skEnumField;;debug;;LogLevel;;*nimsuggest/tests/tsug_enum.nim;;5;;4;;"";;100;;Prefix
|
||||||
|
"""
|
||||||
Loading…
Add table
Add a link
Reference in a new issue