summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semstmts.nim6
-rw-r--r--compiler/suggest.nim6
-rw-r--r--nimsuggest/tests/tcase.nim17
3 files changed, 28 insertions, 1 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 7c6e3af6d..6d0190257 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -205,7 +205,8 @@ proc semCase(c: PContext, n: PNode): PNode =
   var typ = commonTypeBegin
   var hasElse = false
   var notOrdinal = false
-  case skipTypes(n.sons[0].typ, abstractVarRange-{tyTypeDesc}).kind
+  let caseTyp = skipTypes(n.sons[0].typ, abstractVarRange-{tyTypeDesc})
+  case caseTyp.kind
   of tyInt..tyInt64, tyChar, tyEnum, tyUInt..tyUInt32, tyBool:
     chckCovered = true
   of tyFloat..tyFloat128, tyString, tyError:
@@ -215,6 +216,9 @@ proc semCase(c: PContext, n: PNode): PNode =
     return
   for i in countup(1, sonsLen(n) - 1):
     var x = n.sons[i]
+    when defined(nimsuggest):
+      if gIdeCmd == ideSug and exactEquals(gTrackPos, x.info) and caseTyp.kind == tyEnum:
+        suggestEnum(c, x, caseTyp)
     case x.kind
     of nkOfBranch:
       checkMinSonsLen(x, 2)
diff --git a/compiler/suggest.nim b/compiler/suggest.nim
index 04f5baac4..63f769c7c 100644
--- a/compiler/suggest.nim
+++ b/compiler/suggest.nim
@@ -555,6 +555,12 @@ proc suggestDecl*(c: PContext, n: PNode; s: PSym) =
 proc suggestStmt*(c: PContext, n: PNode) =
   suggestExpr(c, n)
 
+proc suggestEnum*(c: PContext; n: PNode; t: PType) =
+  var outputs: Suggestions = @[]
+  suggestSymList(c, t.n, nil, n.info, outputs)
+  produceOutput(outputs)
+  if outputs.len > 0: suggestQuit()
+
 proc suggestSentinel*(c: PContext) =
   if gIdeCmd != ideSug or c.module.position != gTrackPos.fileIndex: return
   if c.compilesContextId > 0: return
diff --git a/nimsuggest/tests/tcase.nim b/nimsuggest/tests/tcase.nim
new file mode 100644
index 000000000..8e3fc5548
--- /dev/null
+++ b/nimsuggest/tests/tcase.nim
@@ -0,0 +1,17 @@
+
+type
+  MyEnum = enum
+    nkIf, nkElse, nkElif
+
+proc test(a: MyEnum) =
+  case a
+  of nkElse: discard
+  of #[!]#
+
+discard """
+$nimsuggest --tester $file
+>sug $1
+sug;;skEnumField;;nkElse;;MyEnum;;$file;;4;;10;;"";;100;;None
+sug;;skEnumField;;nkElif;;MyEnum;;$file;;4;;18;;"";;100;;None
+sug;;skEnumField;;nkIf;;MyEnum;;$file;;4;;4;;"";;100;;None
+"""