nimsuggest: special rule for 'of' completion in case statements
This commit is contained in:
parent
c5566f7c37
commit
2430fc7d82
3 changed files with 28 additions and 1 deletions
|
|
@ -205,7 +205,8 @@ proc semCase(c: PContext, n: PNode): PNode =
|
||||||
var typ = commonTypeBegin
|
var typ = commonTypeBegin
|
||||||
var hasElse = false
|
var hasElse = false
|
||||||
var notOrdinal = 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:
|
of tyInt..tyInt64, tyChar, tyEnum, tyUInt..tyUInt32, tyBool:
|
||||||
chckCovered = true
|
chckCovered = true
|
||||||
of tyFloat..tyFloat128, tyString, tyError:
|
of tyFloat..tyFloat128, tyString, tyError:
|
||||||
|
|
@ -215,6 +216,9 @@ proc semCase(c: PContext, n: PNode): PNode =
|
||||||
return
|
return
|
||||||
for i in countup(1, sonsLen(n) - 1):
|
for i in countup(1, sonsLen(n) - 1):
|
||||||
var x = n.sons[i]
|
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
|
case x.kind
|
||||||
of nkOfBranch:
|
of nkOfBranch:
|
||||||
checkMinSonsLen(x, 2)
|
checkMinSonsLen(x, 2)
|
||||||
|
|
|
||||||
|
|
@ -555,6 +555,12 @@ proc suggestDecl*(c: PContext, n: PNode; s: PSym) =
|
||||||
proc suggestStmt*(c: PContext, n: PNode) =
|
proc suggestStmt*(c: PContext, n: PNode) =
|
||||||
suggestExpr(c, n)
|
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) =
|
proc suggestSentinel*(c: PContext) =
|
||||||
if gIdeCmd != ideSug or c.module.position != gTrackPos.fileIndex: return
|
if gIdeCmd != ideSug or c.module.position != gTrackPos.fileIndex: return
|
||||||
if c.compilesContextId > 0: return
|
if c.compilesContextId > 0: return
|
||||||
|
|
|
||||||
17
nimsuggest/tests/tcase.nim
Normal file
17
nimsuggest/tests/tcase.nim
Normal file
|
|
@ -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
|
||||||
|
"""
|
||||||
Loading…
Add table
Add a link
Reference in a new issue