-
Notifications
You must be signed in to change notification settings - Fork 38.3k
Switch nvim-treesitter to the new main
branch
#1657
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
base: master
Are you sure you want to change the base?
Conversation
I realized that my test was completely wrong and so I deleted my comments. Now that I've found out how to use |
Thank you for the PR. A bit unrelated to kickstart but.. I'm a bit confused as to where all my previous options should go. Could you provide some insight? This is my current setup https://github.com/dotfrag/dotvim/blob/main/lua/plugins/treesitter.lua I can't see those in the new branch, are they removed? Also noticed a typo on line 957 (enbales). |
I finally succeeded in running Installing tree-sitter CLI was a main hurdle. I think others will have the same difficulty and so I leave a how-to-do here:
My thought: |
You are probably right 😄 . I will add that. BTW, as mentioned in their README, you can also install using cargo install --locked tree-sitter-cli or with npm install tree-sitter-cli In addition to that, in some distros, you can probably use your package manager. For example, in fedora you can install it using: sudo dnf install tree-sitter-cli |
Jeez. I was wondering how you found the right README.md in the source tree--there are so many of them. 😂 Maybe it would help if I share some of the difficulties I had while trying to get started:
💡 Not a request, just thinking out loud |
Replying to myself, I don't think this is fully ready for everyone. I've tried multiple times to get text objects to work (with main branch) and I haven't been able to. Maybe it's a skill issue on my end but it appears to do nothing. The context plugin does not have a working version. And for me the autocmd doesn't work, i.e. I get no treesitter highlighting when opening a file. This is most likely on me as it seems to work for you, so I'm still investigating. Update: Highlighting wasn't working for me, because not all parsers match filetype names. For example, for a shell script, the parser is |
I think the auto_install feature is essential for people like me that are new to neovim, i tried to make it work with the main branch but couldn't, maybe the rewrite is still too green? |
Same here, I work in the terminal all day and open all sorts of files, I can't bother manually adding them one by one.. |
I works for me. Could you possibly be affected by this breaking change? |
I do agree that the For the time being, it is probably best to leave this PR as a draft. |
Yes! Thank you. |
This is a (probably) badly optimised way to do it: vim.api.nvim_create_autocmd("FileType", {
callback = function()
local ft = vim.bo.filetype
if not parsers[ft] then
require("nvim-treesitter").install(ft)
end
end,
}) Updated version with exclude option https://github.com/dotfrag/dotvim/blob/ecdc0ab1dca98c901f1cea2a8cf6d057e596fece/lua/plugins/treesitter.lua#L39-L54. |
I wrote a plugin to fill the gaps between the You're welcome to pull any of the implementations from there or use it directly. Here's a minimal implementation of ---@param buf integer
---@param language string
---@return boolean
local function attach(buf, language)
-- check if parser exists before starting highlighter
if not vim.treesitter.language.add(language) then
return false
end
vim.treesitter.start(buf, language)
return true
end
vim.api.nvim_create_autocmd('FileType', {
callback = function(args)
local buf, filetype = args.buf, args.match
local language = vim.treesitter.language.get_lang(filetype)
if not language then
return
end
if attach(buf, language) then
return
end
-- attempt to start highlighter after installing missing language
require('nvim-treesitter').install(language):await(function()
attach(buf, language)
end)
end,
}) |
Thanks @MeanderingProgrammer, this works for the most part, except the cases mentioned above, where After using several sophisticated print statement, I see that the translation from |
I don't believe I have anything special going on that makes this associate the filetype with the correct language. What does this command |
|
It might be the case that you do have If I do
|
That wasn't my experience, and after a lot of troubleshooting I only managed to get the expected behavior after entirely resetting my setup. I deleted the following dirs and then it was fine: "${XDG_CONFIG_HOME:-${HOME}/.config}/nvim"
"${XDG_DATA_HOME:-${HOME}/.local/share}/nvim"
"${XDG_STATE_HOME:-${HOME}/.local/state}/nvim"
"${XDG_CACHE_HOME:-${HOME}/.cache}/nvim" I suspect some state/cache was stuck, because I was doing |
As described in
nvim-treesitter
's README:This is a proactive branch to switch to the new branch.
I have been using it for a couple of month and it seems pretty stable to me, though I'm not sure if this is really ready to be merged right now.
There maybe features that are not yet supported (or will never be) like incremental selection.
Does anyone else have experience with this transition, and can give feedback?
PS, I also added support for treesitter based folds, but left it commented out. Let me know if you think I should enable it in this PR.