-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Formatting the whole document makes a big mess #2437
Comments
@kaloyan-raev Bug confirmed. |
I did some debugging. The text edits returned by the language server are all calculated based on the document before any modification is applied. Che applies the edits to the document one by one. If the inserted text has a different length than the replaced text then the ranges of the remaining edits become invalid and they must be shifted appropriately. I am working on a PR to fix this issue. |
…it formatting A formatting request to a language server may result in a list of multiple text edits. The ranges of all these text edits are based on the yet unmodified document. Che applies the edits to the document one by one. If the inserted text has a different length than the replaced text then the ranges of the remaining edits become invalid and they must be shifted appropriately. This patch shifts the ranges as necessary. To achieve this, it first converts the ranges based on lines and characters to linear ranges, which are easier for shifting. Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com>
Pushed PR #2719 with the fix. |
…p the document (eclipse-che#2719) * Fixes eclipse-che#2437: Shift remaining ranges when applying multi-edit formatting A formatting request to a language server may result in a list of multiple text edits. The ranges of all these text edits are based on the yet unmodified document. Che applies the edits to the document one by one. If the inserted text has a different length than the replaced text then the ranges of the remaining edits become invalid and they must be shifted appropriately. This patch shifts the ranges as necessary. To achieve this, it first converts the ranges based on lines and characters to linear ranges, which are easier for shifting. Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com> * Simplify the shifting logic Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com> * Reworked: just applying the text edits backwards is enough
Formatting a JSON document of average size makes a big mess. See the animated gif.
I have a local build of Che with the latest content from the
language-server
branch.I see similar result with PHP files using a PHP language server. So, it seems to be a generic formatting issue when using language servers, i.e. related to how #1788 is implemented.
Reproduction Steps:
Expected behavior:
The JSON file is nicely formatted.
Observed behavior:
The document is completely broken.
Che version: latest content from the
language-server
branchOS and version: Fedora 24
Docker version: 1.10.3
Che install: local build, started with the
bin/che.sh
scriptAdditional information:
The text was updated successfully, but these errors were encountered: