Description
Okay so I found out some of the issues and why they happen (I think). It seems to be the case like you say that treesitter is interpreting it as another language, but I could only reproduce this if the newline is between the starting tag and the first line inside the tags.
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
name: 'test',
},
});
</script>
With the newline there, treesitter interprets that as filetype vue, and I don't think there is much we can do about that. One thing I think we can do is calculate the commentstring based on where the cursor is when doing the motion. Right now it looks like the cursor jumps to the start of the motion, and then when finding the language where the cursor is currently, the language is returned as vue. After this the cursor returns to where it was (probably has something to do with the sticky option). If one is holding the cursor over the newline and uncomment, there isn't much we can do (to my knowledge) since treesitter interprets this as vue.
However there is also a slight issue with empty lines if the commentstring surrounds the string (commentstrings like /* %s */
for example). If there is a newline inside the tag when doing gcit
for example, the newline will only get /*
inserted on the line. This will mess with the logic of checking if a line is commented or not, so therefore it will try to comment this again instead of uncommenting.
<style>
/* body { */
/* height: 100vh; */
/*
/* } */
</style>
Note that this will not be an issue with commentstrings like // %s
, and also not for those who chose to ignore the newlines in lua pattern option in the setup function. I also don't think this is related to this PR, so this could probably be fixed in another PR.
If we add the rhs of the commentstring (*/
) to the newline, after /*
the problem is fixed. Like this
<style>
/* body { */
/* height: 100vh; */
/* */
/* } */
</style>
Originally posted by @seblj in #62 (comment)