diff options
author | Saem Ghani <saemghani+github@gmail.com> | 2021-01-11 01:18:01 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-11 10:18:01 +0100 |
commit | bbc96f974d643b5ab4e2b9d2855e94ef30ed3ee4 (patch) | |
tree | ae263bc2abd8f15888cd7f73a431f6f031fec515 | |
parent | f6c2450cdb7e24b5dbd118494560cc8452dd3688 (diff) | |
download | Nim-bbc96f974d643b5ab4e2b9d2855e94ef30ed3ee4.tar.gz |
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
-rw-r--r-- | compiler/suggest.nim | 21 | ||||
-rw-r--r-- | nimsuggest/tests/tsug_enum.nim | 18 |
2 files changed, 29 insertions, 10 deletions
diff --git a/compiler/suggest.nim b/compiler/suggest.nim index 560d20b3f..283690080 100644 --- a/compiler/suggest.nim +++ b/compiler/suggest.nim @@ -386,17 +386,17 @@ proc suggestFieldAccess(c: PContext, n, field: PNode, outputs: var Suggestions) else: # fallback: 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: - let orig = typ # skipTypes(typ, {tyGenericInst, tyAlias, tySink}) - typ = skipTypes(typ, {tyGenericInst, tyVar, tyLent, tyPtr, tyRef, tyAlias, tySink, tyOwned}) - if typ.kind == tyObject: + let orig = typ + typ = skipTypes(orig, {tyTypeDesc, tyGenericInst, tyVar, tyLent, tyPtr, tyRef, tyAlias, tySink, tyOwned}) + + 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 while true: 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) elif typ.kind == tyTuple and typ.n != nil: suggestSymList(c, typ.n, field, n.info, outputs) + suggestOperations(c, n, field, orig, outputs) if typ != orig: suggestOperations(c, n, field, typ, outputs) diff --git a/nimsuggest/tests/tsug_enum.nim b/nimsuggest/tests/tsug_enum.nim new file mode 100644 index 000000000..97a225f16 --- /dev/null +++ b/nimsuggest/tests/tsug_enum.nim @@ -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 +""" \ No newline at end of file |