pragmagic/vscode-nim

Incorrect indentation when pasting code

Closed this issue · 1 comments

kbd commented

I'm going through the Nim tutorial and noticed that the Nim extension causes incorrect indentation when pasting examples.

The varargs example:

proc myWriteln(f: File, a: varargs[string]) =
  for s in items(a):
    write(f, s)
  write(f, "\n")

myWriteln(stdout, "abc", "def", "xyz")
# is transformed by the compiler to:
myWriteln(stdout, ["abc", "def", "xyz"])

When I paste into Visual Studio Code, it results in the following:

proc myWriteln(f: File, a: varargs[string]) =
    for s in items(a):
      write(f, s)
    write(f, "\n")
  
  myWriteln(stdout, "abc", "def", "xyz")
  # is transformed by the compiler to:
  myWriteln(stdout, ["abc", "def", "xyz"])

The myWriteln calls below the function are indented as if they're within the body of myWriteln. The body of the myWriteln function is also indented an extra level.

When I paste into a plain text buffer, the indentation is correct, so it definitely seems to be the extension causing the indentation to be incorrect on paste.

Versions: vscode 1.37.1, Nim extension: 0.6.3

kbd commented

Here's a little more info on this, including a screen recording:

nim-extension-paste-behavior

Steps taken:

  1. In a brand new window, paste the above code. Undo the paste.
  2. Set language mode to Nim, paste. Shows reported behavior.
  3. Reload the window, select all, paste again. Doesn't show reported behavior.

It seems to mainly happen on new buffers and I'm not sure why. One more bit of info is that, when you paste into the window and it shows the incorrect formatting behavior, if you undo once it doesn't remove all the code like it does in the plain text buffer, but it un-does the formatting step. So it's clear there's an extra formatting step taking place that also leaves an action in the undo buffer.