Skip to content

Invalid css comments on empty lines #71

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

Closed
numToStr opened this issue Nov 19, 2021 · 1 comment · Fixed by #72
Closed

Invalid css comments on empty lines #71

numToStr opened this issue Nov 19, 2021 · 1 comment · Fixed by #72
Labels
good first issue Good for newcomers

Comments

@numToStr
Copy link
Owner

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)

@numToStr numToStr changed the title 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. Invalid css comments on empty lines Nov 19, 2021
@numToStr numToStr added the good first issue Good for newcomers label Nov 19, 2021
@numToStr
Copy link
Owner Author

Note: This is a general problem with languages with linewise comment which have both left and right side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant