Closed phallguy closed 1 year ago
The gf
implementation explicitly relies on Vim's syntax highlighting. I'm not sure what it would take to get it to work with Treesitter.
OK, did some more debugging...found that which-key was also complicating things. With my ftdetect hack (not even sure if thats the right approach) I also had to disable which-key intercept of the gf
trigger.
With this config, and my ftdetect hack, Treesitter doesn't seem to interfere anymore
{
"folke/which-key.nvim",
opts = {
triggers_blacklist = {
n = { "g", "gf" }
}
},
},
Not sure if there's anything to do with the vim-rails plugin to make this better for others but I've found something that works for me. Thanks again for the help and the amazing plugins!
gf
still requires Vim syntax highlighting for maximum functionality.
thanks @phallguy has inspired me to resolve it by
autocmd FileType eruby
\ if RailsDetect() | call rails#ruby_setup() | endif
Resolve what? It's already working.
Hi @tpope, the commit do not resolve the question
but if I recall rails#ruby_setup()
on this buffer, the gf
is worked now
It's normally called here. I can't think of a reason why enabling Treesitter would cause this not to load.
The key code is
if I comment this line, my workaround is not working too. and it's still working if I comment other lines inside the function except this line.
I have checked the map by echo maparg('<Plug><cfile>', 'c')
and it's seems like ErubyAtCursor
function return difference value between :TSEnable highlight
and :TSDisable highlight
after :TSEnable highlight
, echo ErubyAtCursor()
return 0.
after :TSDisable highlight
, echo ErubyAtCursor()
return 1.
if I recall rails#ruby_setup()
on this buffer, echo maparg('<Plug><cfile>', 'c')
return rails#ruby_cfile()
. it is no longer judged by ErubyAtCursor
and it's worked
Oh yeah that explains it. ErubyAtCursor()
requires Vim syntax highlighting to work. A cleaner workaround would be to put this in after/ftplugin/eruby.vim
:
function! ErubyAtCursor() abort
return 1
endfunction
The fix would be to change this function to support Treesitter.
Oddly enough, if I do this once after starting vim, almost everything works better/as expected
:TSDisable highlight
:TSEnable highlight
Totally grasping at straws and have no idea what I'm doing...but it works? 😄
@phallguy even if without your own ftdetect plugin?
thanks @tpope, Iis it possible for the workaround to become the default setting for the plugin in the future?
The point of ErubyAtCursor()
is to make gf
behave differently in the Ruby versus the non-Ruby (typically HTML) parts. The workaround breaks it so it treats the whole file as Ruby. So no, I will not be breaking the default for everybody just because it's better than nothing for Treesitter users. The minimum bar for a workaround has to be that non-Treesitter users are unaffected.
Oddly enough, if I do this once after starting vim, almost everything works better/as expected
:TSDisable highlight :TSEnable highlight
Totally grasping at straws and have no idea what I'm doing...but it works? smile
Not sure what's going on here, but if I had to guess, it leaves it in a state where both Treesitter and Vim highlighting are on at the same time? This might have other side effects but from the perspective of rails.vim it's perfect, the best of both worlds.
@tpope Yep! best of both. Feels good. Really to appreciate the help and attention.
@jiz4oh Here's what I ended up
" nvim/after/plugin/rails_detection.vim
autocmd FileType ruby
\ if RailsDetect() | call rails#ruby_setup() | endif
autocmd FileType eruby
\ if RailsDetect() | call rails#ruby_setup() | endif
-- nvim/lua/user/ruby.lua (required from init.lua)
local group = vim.api.nvim_create_augroup("RubyEx", { clear = true })
local initialized_ruby_syntax = false
vim.api.nvim_create_autocmd("FileType", {
group = group,
pattern = { "ruby", "eruby" },
callback = function()
if not initialized_ruby_syntax then
vim.cmd([[TSDisable highlight]])
vim.cmd([[TSEnable highlight]])
initialized_ruby_syntax = true
end
end,
})
@tpope Make sense, so much appreciate the help and attention.
@phallguy appreciate for your sharing
First off thanks for even making this package. I found an issue recently when trying to navigate a rails codebase and trying to get more efficient with the custom commands and keymaps that vim-rails offers. Eview/Econ and friends work great. But if I'm on a
render "path/to/partial"
line in an erb file it fails with E345: Can't fine file "path/to/partial" in path" error.After a bunch of trial and error I've narrowed the problem down to the use of Treesitter but can't explain what the interaction is that is causing the problem. I've included a minimum config that reproduces the problem in a rails app.
Here's whats fun -- if I
:TSDisable highlight
the gf keymap works as expected. If I:TSEnable highlight
again it breaks again. I'v exhausted my ability to debug further but was hoping I might provide enough info that you'd be able to see the problem pretty easily.I ended up working around the issue by adding my own ftdetect plugin
with TSEnable highlight
verb nmap gf
:scriptnames
with TSDisable highlight
verb nmap gf
:scriptnames
If it happens to be useful I am using a nightly build of neovim