fix #14401, trailing comma confuses nimpretty (#14867)

This commit is contained in:
Miran 2020-07-01 11:40:13 +02:00 • committed by GitHub
commit 1edb9a6178
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 1 deletions

View file

@ -452,6 +452,9 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
if tok.tokType in openPars and tok.indent > em.indentStack[^1]: if tok.tokType in openPars and tok.indent > em.indentStack[^1]:
while em.indentStack[^1] < tok.indent: while em.indentStack[^1] < tok.indent:
em.indentStack.add(em.indentStack[^1] + em.indWidth) em.indentStack.add(em.indentStack[^1] + em.indWidth)
while em.indentStack[^1] > tok.indent:
discard em.indentStack.pop()
# aka: we are in an expression context: # aka: we are in an expression context:
let alignment = max(tok.indent - em.indentStack[^1], 0) let alignment = max(tok.indent - em.indentStack[^1], 0)
em.indentLevel = alignment + em.indentStack.high * em.indWidth em.indentLevel = alignment + em.indentStack.high * em.indWidth

View file

@ -822,3 +822,24 @@ proc f =
# doesn't break the code, but leaving indentation as is would be nice. # doesn't break the code, but leaving indentation as is would be nice.
let x = if true: callingProcWhatever() let x = if true: callingProcWhatever()
else: callingADifferentProc() else: callingADifferentProc()
type
EventKind = enum
Stop, StopSuccess, StopError,
SymbolChange, TextChange,
SpinnyEvent = tuple
kind: EventKind
payload: string
type
EventKind2 = enum
Stop2, StopSuccess2, StopError2,
SymbolChange2, TextChange2,
type
SpinnyEvent2 = tuple
kind: EventKind
payload: string

View file

@ -812,7 +812,7 @@ let foo = if cond:
let a = let a =
[[aaadsfas, bbb], [[aaadsfas, bbb],
[ccc, ddd]] [ccc, ddd]]
let b = [ let b = [
[aaa, bbb], [aaa, bbb],
@ -835,3 +835,24 @@ proc f =
# doesn't break the code, but leaving indentation as is would be nice. # doesn't break the code, but leaving indentation as is would be nice.
let x = if true: callingProcWhatever() let x = if true: callingProcWhatever()
else: callingADifferentProc() else: callingADifferentProc()
type
EventKind = enum
Stop, StopSuccess, StopError,
SymbolChange, TextChange,
SpinnyEvent = tuple
kind: EventKind
payload: string
type
EventKind2 = enum
Stop2, StopSuccess2, StopError2,
SymbolChange2, TextChange2,
type
SpinnyEvent2 = tuple
kind: EventKind
payload: string