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

File lookup bug when highlight = { enable = true } #6187

Closed
thewatts opened this issue Feb 24, 2024 · 3 comments
Closed

File lookup bug when highlight = { enable = true } #6187

thewatts opened this issue Feb 24, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@thewatts
Copy link

thewatts commented Feb 24, 2024

Describe the bug

Hi there 👋

Thanks for all the amazing work ya'll do!

I use the vim-rails plugin for traversing between files. One of the things that it does is add Rails application paths to the path value if using vim/nvim in a Rails project.

I noticed, after installing/configuring Treesitter, that the gf command broke.

Instead of jumping to the expected file, it will raise an E345 error.

I've created a repo with a bare-bones init.lua and example Rails application so it's easy to reproduce.

You can find it here: https://github.com/thewatts/treesitter-bug, with information on how to reproduce (I'll still add details below).

To Reproduce

In reference to this repo: https://github.com/thewatts/treesitter-bug

  1. Startup NVIM, using the provided bare-bones init.lua.
  2. cd into the included rails application, and open app/views/posts/_post.html.erb
  3. Move your cursor to be over the word "another_partial"
  4. In normal mode, hit gf

Expected behavior

The file, app/views/posts/_another_partial.html.erb will be opened.

Output of :checkhealth nvim-treesitter

nvim-treesitter: require("nvim-treesitter.health").check()

Installation
- OK tree-sitter found 0.20.8 (parser generator, only needed for :TSInstallFromGrammar)
- OK node found v18.19.0 (only needed for :TSInstallFromGrammar)
- OK git executable found.
- OK cc executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
  Version: Apple clang version 15.0.0 (clang-1500.1.0.2.5)
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

OS Info:
{
  machine = "arm64",
  release = "23.2.0",
  sysname = "Darwin",
  version = "Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000"
}

Parser/Features         H L F I J
  - c                   ✓ ✓ ✓ ✓ ✓
  - embedded_template   ✓ . . . ✓
  - lua                 ✓ ✓ ✓ ✓ x
  - query               ✓ ✓ ✓ ✓ ✓
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              x . . . ✓

  Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang}

The following errors have been detected:
- ERROR lua(injections): ...im/0.9.5/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid structure at position 3158 for language lua
  lua(injections) is concatenated from the following files:
  | [ERROR]:"/Users/watts/.local/share/nvim.tree/lazy/nvim-treesitter/queries/lua/injections.scm", failed to load: ...im/0.9.5/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query:      invalid structure at position 3158 for language lua
- ERROR vimdoc(highlights): ...im/0.9.5/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid node type at position 746 for language vimdoc
  vimdoc(highlights) is concatenated from the following files:
  | [ERROR]:"/Users/watts/.local/share/nvim.tree/lazy/nvim-treesitter/queries/vimdoc/highlights.scm", failed to load: ...im/0.9.5/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query:   invalid node type at position 746 for language vimdoc

Output of nvim --version

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1703358377

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.5/share/nvim"

Additional context

Actual Behavior

You get the error: E345: Cannot find file "another_parial" in path


If you change the config in init.lua to set highlight to enable = false - it works as expected.

@thewatts thewatts added the bug Something isn't working label Feb 24, 2024
@lucario387
Copy link
Member

lucario387 commented Feb 24, 2024

I suspect this is because of gf relying on syntax.

Edit: I also can't access your reproduce files. The rails folder is inaccessible

Please add

  highlight = {
    enable = true,
    -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
    -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
    -- Using this option may slow down your editor, and you may see some duplicate highlights.
    -- Instead of true it can also be a list of languages
    additional_vim_regex_highlighting = true,
  },

Ending note: Please don't just download/install the repo through a plugin, please also read README.md if possible

@thewatts
Copy link
Author

Thank you for your quick response!

I can confirm - that does indeed fix the issue 🎉


I suspect this is because of gf relying on syntax.

May I ask, where can I find out more information on this? I had checked the help docs for the gf command, but it doesn't mention syntax at all.

I think given that information (that gf relies on syntax), the documentation in the README would have made more sense as to why I had this issue.

I'd love to be able to dig into that more, if you happen to know offhand where to find the information.

(If not, that's okay, too).


Please don't just download/install the repo through a plugin, please also read README.md if possible

I completely understand and appreciate your patience. For context - if I remember correctly - I had used this section as a reference for my initial setup of treesitter.


Thank you again for your help!

@lucario387
Copy link
Member

May I ask, where can I find out more information on this? I had checked the help docs for the gf command, but it doesn't mention syntax at all.

I just skimmed through rails.vim in vim-rails, and see a syntax file, and a gf keymap that seems to be calling a script inside rails.vim. So I suspect that's the cause

@lucario387 lucario387 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 24, 2024
thewatts added a commit to thewatts/newdots that referenced this issue Feb 24, 2024
thewatts added a commit to thewatts/dotfiles that referenced this issue Feb 25, 2024
Note: If using with `vim-rails`, and having `highlight` enabled - it can
cause some issues, without the `additional_vim_regex_highlighting`
enabled.

Reference: nvim-treesitter/nvim-treesitter#6187
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants