nvim-treesitter / nvim-treesitter-context

Show code context
MIT License
2.44k stars 195 forks source link

Feature Request: Allow override specific language queries with user provided ones #490

Closed ecerulm closed 2 days ago

ecerulm commented 2 days ago

Description

In case I want to have my custom version of https://github.com/nvim-treesitter/nvim-treesitter-context/blob/master/queries/java/context.scm

Neovim version

NVIM v0.11.0-dev-492+g0cdeb06db

Expected behavior

proposal:

require('mvim-treesitter-context').setup({language_overrides_dir="~/config/nvim/treesitter-context-extras/"})

Actual behavior

There is no way to provide my own queries as far as I know

Minimal config

N/A , It's not a bug report

Steps to reproduce

N/A , It's not a bug report

lewis6991 commented 2 days ago

This is already possible with custom queries.

ecerulm commented 2 days ago

I didn't find any mention of the word "custom" or "quer" on the README or doc/nvim-treesitter-context.txt.

So can we you provide an example on how this can be achieve today? I can create a PR to update README and doc/nvim-treesitter-context.txt.

ecerulm commented 2 days ago

I guess what it means is that I can put a file queries/java/context.scm in runtimepath and that will override the one included in Nvim-treesitter-context.

I did create ~/.config/nvim/queries/java/context.scm and it does in fact takes precedence, since ~/.config/nvim is the first thin on my runtimepath

set rtp
 runtimepath=~/.config/nvim,~/.local/share/nvim/lazy/lazy.nvim,~/.local/share/nvim/lazy/lsp-progress.nvim,~/.local/share/nvim/lazy/lualine.nvim,...
lewis6991 commented 2 days ago

Queries are searched in the runtime path (see :help rtp), in the queries directory of each entry. This applies for any treesitter query, and any runtime path directory: ftdetect, plugin, parser, after, etc. Look at my dotfiles for an example.