-
Notifications
You must be signed in to change notification settings - Fork 48
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
file content is stripped when formatting with folds closed #124
Comments
What do you get after format? |
After some debugging, I could find that vim will somehow delete text which is replacing a fold without an empty character right after it. I've managed to patch the Lines 143 to 156 in 905e830
--- a/.config/coc/extensions/node_modules/coc-prettier/lib/index.js
+++ b/.config/coc/extensions/node_modules/coc-prettier/lib/index.js
@@ -2839,9 +2839,16 @@ var PrettierEditProvider = class {
if (!document.uri.startsWith("untitled") && this._fileIsIgnored(fileName)) {
return Promise.resolve([]);
}
- const code = await format(document.getText(), document, options);
+
+ let doc = await import_coc6.workspace.document;
+ await doc.applyEdits([{
+ range: fullDocumentRange(doc.textDocument),
+ newText: doc.content + ' '
+ }]);
+
+ const code = await format(doc.content, doc.textDocument, options);
const edits = [{
- range: fullDocumentRange(document),
+ range: fullDocumentRange(doc.textDocument),
newText: code
}];
const {disableSuccessMessage} = getConfig();
@@ -2936,6 +2943,11 @@ async function activate(context) {
import_coc6.window.showMessage(`Flag prettier.onlyUseLocalVersion is set, but prettier is not installed locally. No operation will be made.`, "warning");
return;
}
+
+ await document.applyEdits([{
+ range: fullDocumentRange(document.textDocument),
+ newText: document.content + ' '
+ }]);
let edits = await format(document.content, document.textDocument, {}).then((code) => {
if (code == null)
return null;
Although, this doesn't feel like it's the best way to achieve this, so if somehow you could think on a better way to patch this, it would be really appreciated. |
Related with #102, it seems that depending on the code structure
coc-prettier
will partially remove file contents instead of formatting whenever folding is enabled.The file being test against is the following, however I had the same sort of behaviour with different structures, where the content is partially/fully stripped:
Please bear in mind this happens only with syntax folding enabled on load and running
:CocCommand prettier.formatFile
or throughcoc.preferences.formatOnSaveFiletypes
I have been able to reproduce this under a clean installation under a container with the following image:
To reproduce:
docker build . -t vim-coc-test
docker -it --rm vim-coc-test vim test.js
coc-prettier
installation and press q once done:CocCommand prettier.formatFile
The text was updated successfully, but these errors were encountered: