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

Error 32603: Document version mismatch detected #122

Closed
Nkmol opened this issue Sep 30, 2022 · 4 comments
Closed

Error 32603: Document version mismatch detected #122

Nkmol opened this issue Sep 30, 2022 · 4 comments

Comments

@Nkmol
Copy link

Nkmol commented Sep 30, 2022

I get a standard error while formatting my file since 3.14.x. Everything worked correctly in 3.13.x.

[Info - 10:22:23 AM] XO Server Starting in Node v16.14.2
[10:22:24:77] XO Library 0.52.3
Resolved in Workspace .../node
Cached for Folder .../node/providers
[10:22:24:78] XO Library 0.52.3
Resolved in Workspace .../node
Cached for Folder .../node/providers
[10:22:38:640] Document version mismatch detected
[10:22:38:640] Error: Document version mismatch detected
at .../.vscode/extensions/samverschueren.linter-xo-3.14.1/dist/server.js:62:3169
[Error - 10:22:38 AM] Request textDocument/formatting failed.
Message: Request textDocument/formatting failed with message: Document version mismatch detected
Code: -32603

The dist line it is referring to is the following:

if(l!==o.version) throw new Error("Document version mismatch detected")


Let me know if more information is needed.

@spence-s
Copy link
Collaborator

spence-s commented Sep 30, 2022

Thank you, yeah, I think there was a bug in previous versions that just applied formatting anyway even if there was a mismatch. And just to clarify, this is not happening everytime right? It is able to format for you most of the time and then recover when this happens?

I think this error mostly happens if a format request is made too quickly after the last change was processed.

To recover: make a small change by adding a space or something and just save/format again.

I will see if I can bake in recovering gracefully/retrying so these won't be popping up except in the weird circumstances where they are supposed to.

@Nkmol
Copy link
Author

Nkmol commented Oct 2, 2022

@spence-s Thanks for the comment.

This actually happened after every save. Even after restarting VSCode, clearing cache, restarting linter and reinstalling the extension.

Not sure if and how I can provide more debug info.

@spence-s
Copy link
Collaborator

spence-s commented Oct 2, 2022

Ah ok - Sorry for the inconvenience. If you still need to use the extension in the mean time, vscode allows you to install previous versions of an extension.

In recent changes (3.14 and 3.14.1) 2 major things changed. We added support for range formatting requests and we changed a code action type, to apply a fix to a specific lint problem, to "quickfix" instead of "refactor". We also solved a bug where previously a lot of fixes were not getting correctly returned in code actions.

The error you experience is this: right before we format we, 1) check the document version. 2) calculate the fixes needed 3) check the document version again and throw if it doesn't match the original (this is your error and it means your document changed in the time it took to compute fixes and they are now stale). 4) send the fixes to vscode for applying to your document.

So my best guess is that you have another setting, or another extension, that is making conflicting changes on save using either code action quick fixes OR range formatting.

I have not been able to reproduce this so it would be helpful if you could:

  1. post any relevant settings you have. Settings for xo and other extensions that may affect your files, and editor and files vscode settings.

  2. link a minimal reproduction repo (this may not be needed but could help narrow down that it is, in fact, a conflicting setting/extension local to your setup).

  3. There is a mode in vscode where you can open it with no extensions installed and only turn on this extension and see if it is still happening as well. Would be good to rule out any other conflicting extensions.

Would love to figure out what is causing this so we can prevent in the future. All of your help here is appreciated.

@Nkmol
Copy link
Author

Nkmol commented Oct 2, 2022

@spence-s Indeed I am currently using an older version. Thanks again for the comment.

After debugging some more, disabled all extensions expect VSCode, I think I found the culprit. On the older versions, I already noticed very buggy import formatting, where it sometimes would totally screw up the import code-lines. I think this is one of the scenarios you speak of, and which you actually protect against in the newer version.

The Document Format task was conflicting with the task of Organizing Imports. Both were touching the order of imports, XO for ordering for example import/order, and VSCode doing source.organizeImports.

To first let VSCode do everything, and after everything let XO run, you can use editor.codeActionsOnSave to control the order of action execution.

  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": [
    "source.fixAll",
    "source.addMissingImports",
    "source.organizeImports",
    "source.format"
  ]

However, the actions of "source.organizeImports" can most likely be completely removed, as XO does most of this anyway.


After removing this, everything seems to work in the new version :)

@Nkmol Nkmol closed this as completed Oct 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants