nvim-treesitter / nvim-treesitter-context

Show code context
MIT License
2.5k stars 201 forks source link

Julia context queries not updated #428

Closed vsoftco closed 6 months ago

vsoftco commented 6 months ago

Describe the bug

Starting with nvim-treesitter/nvim-treesitter#6429 , I am getting this error on nvim 0.9.5 (macOS 14, Homebrew) when opening a Julia (.jl) file:

Error detected while processing BufEnter Autocommands for "*":
Unable to load context query for julia:
...im/0.9.5/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: in
valid field at position 53 for language julia
Press ENTER or type command to continue

Note that 86ac7e9274535038f8f5f5f80397f0885bea0326 and all commits before work just fine.

To Reproduce

nvim test.jl

Expected behavior

I expect no errors when loading a Julia file

Output of :checkhealth nvim-treesitter

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

Installation ~
- OK `tree-sitter` found 0.22.5 (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v21.7.3 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `clang` executable found. Selected from { "clang", "cc", "gcc", "clang", "cl", "zig" }
  Version: Homebrew clang version 17.0.6
- 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.4.0",
  sysname = "Darwin",
  version = "Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:49 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020"
} ~

Parser/Features         H L F I J
  - bash                ✓ ✓ ✓ . ✓
  - c                   ✓ ✓ ✓ ✓ ✓
  - cmake               ✓ . ✓ ✓ .
  - cpp                 ✓ ✓ ✓ ✓ ✓
  - haskell             ✓ . ✓ . ✓
  - java                ✓ ✓ ✓ ✓ ✓
  - julia               ✓ ✓ ✓ ✓ ✓
  - latex               ✓ . ✓ . ✓
  - lua                 ✓ ✓ ✓ ✓ ✓
  - luadoc              ✓ . . . .
  - markdown            ✓ . ✓ ✓ ✓
  - norg                . . . . .
  - python              ✓ ✓ ✓ ✓ ✓
  - query               ✓ ✓ ✓ ✓ ✓
  - rust                ✓ ✓ ✓ ✓ ✓
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              ✓ . . . ✓
  - yaml                ✓ ✓ ✓ ✓ ✓

  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} ~

Output of nvim --version

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1710088188

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

Run :checkhealth for more info

Additional context

No response

lucario387 commented 6 months ago

Not to mention, the query says context -> nvim-treesittet-context issue

lewis6991 commented 6 months ago

Queries for languages are community maintained, so someone who uses that language will need to fix it.

vsoftco commented 6 months ago

I can pinpoint the error to the function_definition in context.scm, see https://github.com/nvim-treesitter/nvim-treesitter-context/blob/ba05c6b753130d96b284d3e8ba8f54c28c0fb6d1/queries/julia/context.scm#L3 If I remove line 4: parameters: (_) @context.final, it works. Unfortunately, I don't know enough about how the parser works to propose a fix.

@frankebel

vsoftco commented 6 months ago

I just realized that before https://github.com/nvim-treesitter/nvim-treesitter/pull/6429, :InspectTree reveals this for a 1 argument function definition:

(function_definition)
name: (identifier)
parameters: (parameter_list)

whereas after it shows

(function_definition)
 (signature)
  (call_expression)
   (identifier)
   (argument_list)
    (identifier)

So there are no more parameters and name nodes. Hence removing https://github.com/nvim-treesitter/nvim-treesitter-context/blob/ba05c6b753130d96b284d3e8ba8f54c28c0fb6d1/queries/julia/context.scm#L4 seems a valid fix. Waiting for someone more experienced with this to confirm before opening a PR.

lucario387 commented 6 months ago

@savq

savq commented 6 months ago

If the idea is to show the whole function signature then the follow should probably work:

(function_definition
  (signature) @context.final
) @context

Also, I see some query files using @context.final and others using @context.end. The CONTRIBUTING file mentions @context.end. Should the Julia file be updated to use @context.end?

lewis6991 commented 6 months ago

Note @context.final is inclusive, whereas @context.end is exclusive. I need to adjust the docs to explain this.

frankebel commented 6 months ago

If the idea is to show the whole function signature then the follow should probably work:

(function_definition
  (signature) @context.final
) @context

Also, I see some query files using @context.final and others using @context.end. The CONTRIBUTING file mentions @context.end. Should the Julia file be updated to use @context.end?

I played around a little bit and think the suggestion by @savq is better than removing it suggested by @vsoftco. Imo showing the function signature is better and we should explicitly use @context.final, not @context.end.

lewis6991 commented 6 months ago

Closed in #429

vsoftco commented 6 months ago

Thanks!