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

Support comments in nested (injected) code blocks #137

Closed
numToStr opened this issue Apr 1, 2022 · 2 comments · Fixed by #138
Closed

Support comments in nested (injected) code blocks #137

numToStr opened this issue Apr 1, 2022 · 2 comments · Fixed by #138
Labels
feature New feature

Comments

@numToStr
Copy link
Owner

numToStr commented Apr 1, 2022

Let's say in markdown if you have a code block like Lua (w/ vim) or vue (w/ CSS and JS) which can also have multiple child languages then only the commentstring from the parent lang will be used instead of using the commentstring of child language.

Suppose you have this code block inside markdown and if you try to comment echo 1234 you'll get -- instead of "

\```lua
use {
    'numToStr/Comment.nvim',
    config = function()
        require('Comment').setup()
        vim.cmd[[
            -- echo 1243
            norm! ggG
        ]]
    end
}
\```

And same with vue, commenting color: red; uses <!-- --> instead of /* */

\```vue
<style>
body {
  <!-- color: red; -->
}
</style>
\```
@numToStr numToStr added the feature New feature label Apr 1, 2022
numToStr added a commit that referenced this issue Apr 3, 2022
This PR fixes commenting in nested (injected) code blocks. Like in markdown you can have multiple code blocks and those code blocks can also have injected languages for example `markdown -> vue -> css/js`

### Before

```vue
<style>
body {
    <!-- color: red; -->
}
</style>

<script>
while (true) {
    <!-- console.log("neovim is awesome!"); -->
}
</script>
```

### After

```vue
<style>
body {
    /* color: red; */
}
</style>

<script>
while (true) {
    // console.log("neovim is awesome!");
}
</script>
```

---

Closes #137
@kuntau
Copy link

kuntau commented Apr 8, 2022

@numToStr Does this mean we don't need nvim-ts-context-commentstring anymore?

@numToStr
Copy link
Owner Author

numToStr commented Apr 8, 2022

Does this mean we don't need nvim-ts-context-commentstring anymore?

You already don't need it as treesitter is natively supported and the related PR just extends language detection to nested blocks.

Although you do need nvim-ts-context-commentstring if you want jsx support but that could also change soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants