mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-07 21:43:33 +00:00
nimpretty: fixes #9505 [bugfix]
This commit is contained in:
@@ -113,6 +113,10 @@ const
|
||||
openPars = {tkParLe, tkParDotLe,
|
||||
tkBracketLe, tkBracketLeColon, tkCurlyDotLe,
|
||||
tkCurlyLe}
|
||||
closedPars = {tkParRi, tkParDotRi,
|
||||
tkBracketRi, tkCurlyDotRi,
|
||||
tkCurlyRi}
|
||||
|
||||
splitters = openPars + {tkComma, tkSemicolon}
|
||||
oprSet = {tkOpr, tkDiv, tkMod, tkShl, tkShr, tkIn, tkNotin, tkIs,
|
||||
tkIsnot, tkNot, tkOf, tkAs, tkDotDot, tkAnd, tkOr, tkXor}
|
||||
@@ -196,8 +200,12 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
|
||||
em.fixedUntil = em.content.high
|
||||
|
||||
elif tok.indent >= 0:
|
||||
if em.lastTok in (splitters + oprSet) or em.keepIndents > 0:
|
||||
if em.keepIndents > 0:
|
||||
em.indentLevel = tok.indent
|
||||
elif (em.lastTok in (splitters + oprSet) and tok.tokType notin closedPars):
|
||||
# aka: we are in an expression context:
|
||||
let alignment = tok.indent - em.indentStack[^1]
|
||||
em.indentLevel = alignment + em.indentStack.high * em.indWidth
|
||||
else:
|
||||
if tok.indent > em.indentStack[^1]:
|
||||
em.indentStack.add tok.indent
|
||||
|
||||
24
nimpretty/tests/expected/wrong_ind.nim
Normal file
24
nimpretty/tests/expected/wrong_ind.nim
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
# bug #9505
|
||||
|
||||
import std/[
|
||||
strutils, ospaths, os
|
||||
]
|
||||
import pkg/[
|
||||
regex
|
||||
]
|
||||
|
||||
proc fun() =
|
||||
let a = [
|
||||
1,
|
||||
2,
|
||||
]
|
||||
discard
|
||||
|
||||
proc funB() =
|
||||
let a = [
|
||||
1,
|
||||
2,
|
||||
3
|
||||
]
|
||||
discard
|
||||
24
nimpretty/tests/wrong_ind.nim
Normal file
24
nimpretty/tests/wrong_ind.nim
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
# bug #9505
|
||||
|
||||
import std/[
|
||||
strutils, ospaths, os
|
||||
]
|
||||
import pkg/[
|
||||
regex
|
||||
]
|
||||
|
||||
proc fun() =
|
||||
let a = [
|
||||
1,
|
||||
2,
|
||||
]
|
||||
discard
|
||||
|
||||
proc funB() =
|
||||
let a = [
|
||||
1,
|
||||
2,
|
||||
3
|
||||
]
|
||||
discard
|
||||
Reference in New Issue
Block a user