Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deletes code if previous line has trailing spaces/tabs #101

Open
melusc opened this issue Oct 16, 2021 · 6 comments
Open

Deletes code if previous line has trailing spaces/tabs #101

melusc opened this issue Oct 16, 2021 · 6 comments
Labels

Comments

@melusc
Copy link

melusc commented Oct 16, 2021

If you have something like this (note the trailing tabs on the first line):

				
veryLongFunction();

and you format it using the extension it removes the trailing tabs and cuts off a bit of the next line. The result is something like this:

ryLongFunction();

If you use xo from the cli it doesn't cut off anything, and if you use [email protected] it doesn't either.

I tried v3.3.1 and v3.3.2 and both behaved like this. v3.3.0 crashes for me because I use Windows but I'd guess the bug snuck in there.

I have created a repo with a minimal reproducible example: https://github.com/melusc/vscode-xo-indent-bug.

@melusc
Copy link
Author

melusc commented Oct 16, 2021

This only happens if you have files.trimFinalNewlines set to true.

@spence-s
Copy link
Collaborator

@melusc thank you for the detailed bug report. Unfortunately I couldn't repro this behavior, even in the linked repro and tested after toggling all the final new line options and trying to make changes and apply fixes very quickly.

question 1 - what command do you use to format? Do you use "xo: fix all fixable problems" or do you use "format document" with xo enabled as the default formatter?

I added a debounce to the linting in 3.3+ which helps performance, but may be causing some random regressions. I am going to be releasing another update today which makes that configurable. Perhaps turning that off will fix this for you (and this may be a broader windows problem).

In the meantime, let me know if you can narrow it down any further!

@melusc
Copy link
Author

melusc commented Oct 16, 2021

question 1 - what command do you use to format? Do you use "xo: fix all fixable problems" or do you use "format document" with xo enabled as the default formatter?

If I use "xo: fix all fixable problems" or "format document" it works perfectly, the issue occurs when I save, because I have format on save enabled and xo is the default formatter. That means that it must be running "trim trailing whitespace" and xo at the same time which must be causing issues.

I also noticed that I copied the wrong setting-name in my previous comment, the conflict only occurs with "files.trimTrailingWhitespace" enabled.

@melusc
Copy link
Author

melusc commented Oct 16, 2021

I tried removing all the settings that didn't change this behaviour and I ended up with

{
  "[javascript]": {
    "editor.defaultFormatter": "samverschueren.linter-xo"
  },
  "editor.formatOnSave": true,
  "xo.format.enable": true,
  "files.trimTrailingWhitespace": true
}

@spence-s
Copy link
Collaborator

Thank you - I can reproduce this now. And confirmed it is indeed the debounce that causes this - although I am not quite sure why. It may be a VSCode bug for this race condition to be possible. I am going to be releasing a new version later today with the debounce off by default and configurable for large file performance and this will solve this. I will let you know when I do.

@spence-s
Copy link
Collaborator

@melusc - I just published 3.4.0 which defaults the debounce to 0 and fixes this issue. I recommend in the docs that you don't use these options together anymore. I'm going to leave this open as there may still be an issue on our side that can resolve this even with debounce turned on. Thanks!

@fregante fregante added the bug label Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants