Skip to content

Commit

Permalink
Don't provide suggestions for enum fields (nim-lang#22959)
Browse files Browse the repository at this point in the history
Currently the suggestions create a lot of noise when creating enum
fields. I don't see any way of a macro creating fields (when called
inside an enum) so it should be safe to not show suggestions

---------

Co-authored-by: Andreas Rumpf <[email protected]>
  • Loading branch information
ire4ever1190 and Araq authored Nov 20, 2023
1 parent 02be027 commit 81c0513
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/suggest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,9 @@ proc suggestDecl*(c: PContext, n: PNode; s: PSym) =
if attached: inc(c.inTypeContext)
defer:
if attached: dec(c.inTypeContext)
# If user is typing out an enum field, then don't provide suggestions
if s.kind == skEnumField and c.config.cmd == cmdIdeTools and exactEquals(c.config.m.trackPos, n.info):
suggestQuit()
suggestExpr(c, n)

proc suggestStmt*(c: PContext, n: PNode) =
Expand Down
17 changes: 17 additions & 0 deletions nimsuggest/tests/tenum_field.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
discard """
$nimsuggest --tester $file
>sug $1
>sug $2
sug;;skConst;;tenum_field.BarFoo;;int literal(1);;$file;;10;;6;;"";;100;;Prefix
"""

proc something() = discard

const BarFoo = 1

type
Foo = enum
# Test that typing the name doesn't give suggestions
somethi#[!]#
# Test that the right hand side still gets suggestions
another = BarFo#[!]#

0 comments on commit 81c0513

Please sign in to comment.