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

Formatting screws up on second 'Format Selection' #1843

Closed
jez9999 opened this issue Sep 7, 2022 · 7 comments
Closed

Formatting screws up on second 'Format Selection' #1843

jez9999 opened this issue Sep 7, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@jez9999
Copy link
Contributor

jez9999 commented Sep 7, 2022

Given the following document saved in a .vue file:

<script setup>
import { ref } from 'vue';
import { RouterView } from 'vue-router';
import Navbar from '@/components/Navbar.vue';

    //const test1 = ref(0);
</script>

<template>
    <Navbar />
    <div class="container-fluid mt-3 border border-2 rounded" style="background-color: #e3fff9;">
        <div class="p-3">
            <RouterView />
        </div>
    </div>
</template>

<style scoped>
.aaaa {
    color: red;
}

.bbbb {
    color: red;
}
</style>

Select all, then 'Format Selection' twice in a row. The second time, the formatting screws up and the </template> tag is partially deleted.

@sevillaarvin
Copy link

sevillaarvin commented Sep 7, 2022

I think these are all duplicate issues:

#1827
#1832
#1840
#1842

EDIT: In the meantime try rolling back to 0.40.7 or maybe an older version.

@jez9999
Copy link
Contributor Author

jez9999 commented Sep 7, 2022

It's some kind of state error with the vueDocuments stored in the language server. The second time round the document identifies the wrong range for the <template> block and the vue document formatter creates an edit that deletes characters in </template>. I gave up debugging at that point because it's super complex.

@johnsoncodehk
Copy link
Member

johnsoncodehk commented Sep 7, 2022

Thanks for the report! But I can't reproduce this problem, do you have use other format plugin with volar.config.js? I will appreciate if any information about reproduce.

(I just fix an other format problem in ce2be82 but I think it's unrelated to this issue.)

@johnsoncodehk johnsoncodehk added bug Something isn't working need info labels Sep 7, 2022
@Ragura
Copy link

Ragura commented Sep 7, 2022

It's happening to me too, deleting text somewhere else in the file (not only in the template) on 'format on paste' (which uses format selection under the hood I believe). It doesn't seem to matter where or what I paste. I don't have a reproduction available at the moment, but it happens across all my Vue projects.

Not using a volar.config.js, but I do have an eslint config that does formatting for me. However, I always had that and haven't changed anything about it. Extremely dangerous problem for a code base.

@johnsoncodehk
Copy link
Member

@Ragura I can reproduce it with format on paste enabled, thank you!

@johnsoncodehk
Copy link
Member

Could you try volar-0.40.11-alpha.1.vsix.zip?

@jez9999
Copy link
Contributor Author

jez9999 commented Sep 7, 2022

Yep that fixes it for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants