Closed itsramiel closed 1 year ago
Hey! From the nvim-treesitter
configuration, it looks like the tsx
parser isn't installed. Could you try installing it with :TSInstall tsx
(or adding it to ensure_installed
)?
Another thing to try would be to run :InspectTree
and seeing if there even is an existing Treesitter syntax tree.
Let me know how it goes!
Hey @JoosepAlviste Thank you for responding.
I added tsx
to the ensure_installed
and did :TSInstall tsx
but it still does not work.
Running :InspectTree
shows Not an editor command
error
Here is a video if you want to see what I did https://github.com/JoosepAlviste/nvim-ts-context-commentstring/assets/80689446/7f2cce36-b31f-4f35-8666-d45c391ee400
Here is the nvim version if that helps too:
NVIM v0.8.1
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by runner@Mac-1668417329633.local
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/share/nvim"
Appreciate taking the time to help
I see you're running Neovim 0.8, that might cause some problems as I'm usually running version 0.9. I recently made some changes to use some slightly newer Treesitter APIs. Maybe they don't exist in Neovim 0.8?
Is there any chance you could try version 0.9? You could also try pinning the plugin to this commit: https://github.com/JoosepAlviste/nvim-ts-context-commentstring/commit/9bff161dfece6ecf3459e6e46ca42e49f9ed939f as it should be before the changes I made (but I'm not 100% sure as I've used 0.9 for a while now).
I can try out version 0.8 this weekend to see if that's the root cause of the issue, maybe I can conditionally add back using some of the older APIs.
Hmmm, it could be because of that. My memory does not serve me well now but I can remember it working before, so that might be it.
I will also try to upgrade to neovim 0.9 this weekend hopefully. Will let you know how it goes
@JoosepAlviste Just updated to neovim 0.9.2 and it works 👍. I'll close it
Nice to hear that this fixed it! I also bumped the minimal Neovim version in the readme 😅
I am experiencing the same issue. I have the following lines in my init.lua file; though there are numerous other configs since I'm using NvChad.
require('nvim-treesitter.configs').setup {
context_commentstring = {
enable = true,
enable_autocmd = false,
},
}
require('ts_context_commentstring').setup {}
require('Comment').setup {
pre_hook = function()
require('ts_context_commentstring.integrations.comment_nvim').create_pre_hook()
print("hook2")
end,
}
Triggering comment toggle in a tsx file results in the same problem described above, and also "hook2" is printed, so the prehook function is getting called. Executing :lua print(require('ts_context_commentstring.internal').calculate_commentstring())
results in printing "{/ %s /}".
I am also running nvim 9.4 on debian 11. Any idea how I could get this working?
Hey @StoicDeveloper! I think that your issue comes from the pre_hook
not returning the value from create_pre_hook
. Try this:
require('Comment').setup {
pre_hook = require('ts_context_commentstring.integrations.comment_nvim').create_pre_hook(),
}
Or, if you need the pre_hook
to be a function with your own implementation:
require('Comment').setup {
pre_hook = function(ctx)
return require('ts_context_commentstring.integrations.comment_nvim').create_pre_hook()(ctx)
end,
}
Let me know how it goes!
Minimal reproducible full config
packer.lua
treesitter.lua
comment.lua
Description
Hi,
I am trying to make comments work in tsx files, but they end up being commented with forward slashes:
I am using Comment.nvim and its integration with nvim-ts-context-commentstring
When I run
:lua print(require('ts_context_commentstring.internal').calculate_commentstring())
I get nil:I hope you can point my issue given the config shown above
Steps to reproduce
Setup neovim with the config provided above
Expected behavior
I expect typescript files to be commented properly
Actual behavior
tsx is being commented with two forward slashes
Additional context
No response