pragmagic / vscode-nim

An extension for VS Code which provides support for the Nim language.
Other
237 stars 37 forks source link

A not working feature, which would result in a bug... #39

Open RSDuck opened 7 years ago

RSDuck commented 7 years ago

I found this passage of the code very interesting:

decreaseIndentPattern: /^\s*(((return|break|continue|raise)\n)|((elif|else|except|finally)\b.*:))\s*$/

I assume the (return|break|continue|raise)\n should decrease the identation in the next line, when the user types return, break, continue or raise. But this doesn't work.

I got it to work by adding the following to the onEnterRules:

{
                beforeText: /^\s*((return|break|continue|raise))\s*$/,
                action: { indentAction: vscode.IndentAction.Outdent }
},

But this results in the following bug:

proc f() =
  if true:
    |

(| is where the cursor is) When return is typed, the next line gets outdented once after typing enter. Then when else: is typed, the else outdents once again. Now the else is too far outdented.

And that's why I'm asking if this is intended, or not?

kosz78 commented 7 years ago

It is because onEnterRules conflicts with decreaseIndentPattern in this case. I guess onEnterRules breaks inner indent counters state of VSCode, It is possible use this workaround:

   beforeText: /^\s*((return|break|continue|raise))\s*$/,
   action: { indentAction: vscode.IndentAction.None, removeText: 2 }

but it will work only for fixed tab size

RSDuck commented 7 years ago

Yes it does works. Hm I'm wondering if there's a real fix to this problem(beside just leaving it as is it/removing the ((return|break|continue|raise)\n) from the regex)...