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

bug: User-defined treesitter queries are overridden after startup #226

Closed
3 tasks done
scheatkode opened this issue Dec 29, 2022 · 3 comments · Fixed by #197
Closed
3 tasks done

bug: User-defined treesitter queries are overridden after startup #226

scheatkode opened this issue Dec 29, 2022 · 3 comments · Fixed by #197
Labels
bug Something isn't working

Comments

@scheatkode
Copy link

scheatkode commented Dec 29, 2022

Did you check docs and existing issues?

  • I have read all the lazy docs
  • I have searched the existing issues of lazy
  • I have searched the exsiting issues of the plugin I have a problem with

Neovim version (nvim -v)

0.8.1

Operating system/version

Linux 6.1.1-arch1-1

Describe the bug

Neovim allows for custom queries to be defined in the runtimepath under queries/ and after/queries/. These are loaded fine when Neovim starts but are overridden when lazy.nvim takes over.

Steps To Reproduce

The reproduction is scripted in the minimal init.lua.

Expected Behavior

The usual loading priority assumption applies, e.g.: builtin < plugin < custom

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify('./.repro', ':p')

-- set stdpaths to use .repro
for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do
	vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. name
end

-- bootstrap lazy
local lazypath = root .. '/plugins/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		'git',
		'clone',
		'--filter=blob:none',
		'--single-branch',
		'https://github.com/folke/lazy.nvim.git',
		lazypath,
	})
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	'folke/tokyonight.nvim',
	-- add any other plugins here

	{
		'nvim-treesitter/nvim-treesitter',

		dependencies = {
			'nvim-treesitter/nvim-treesitter-textobjects',
		},

		build = function()
			require('nvim-treesitter.install').update({ with_sync = true })
		end,
	},
}

-- write dummy query files
local queries = string.format('%s/queries/lua', vim.fn.stdpath('config'))
local queries_after =
	string.format('%s/after/queries/lua', vim.fn.stdpath('config'))
os.execute(string.format('mkdir -p %s %s', queries, queries_after))

-- for some reason `io.open` doesn't work when first starting neovim
os.execute(
	string.format(
		"echo '(arguments  (_) @a_dummy_capture)' > %s/textobjects.scm",
		queries
	)
)
os.execute(
	string.format(
		"echo '(arguments  (_) @a_dummy_capture)' > %s/textobjects.scm",
		queries_after
	)
)

-- store query files found by neovim before setting up lazy.nvim
local before = vim.treesitter.get_query_files('lua', 'textobjects')

require('lazy').setup(plugins, {
	root = root .. '/plugins',
})

vim.cmd.colorscheme('tokyonight')
-- add anything else here
vim.api.nvim_create_autocmd('User', {
	once = true,
	pattern = { 'LazyDone', 'LazyVimStarted' },
	callback = function()
		local after = vim.treesitter.get_query_files('lua', 'textobjects')

		print('query files before loading plugin')
		vim.pretty_print(before)
		print('query files after loading plugin')
		vim.pretty_print(after)

		vim.defer_fn(function()
			vim.api.nvim_feedkeys(
				vim.api.nvim_replace_termcodes(':5messages<CR>', true, true, true),
				't',
				false
			)
		end, 2000)
	end,
})

Edit: Thank you for this amazing plugin !

@scheatkode scheatkode added the bug Something isn't working label Dec 29, 2022
@folke folke closed this as completed in 4e3a973 Dec 29, 2022
@folke
Copy link
Owner

folke commented Dec 29, 2022

Should be fixed now

@folke
Copy link
Owner

folke commented Dec 29, 2022

My fix breaks other plugins. Need to look into this further

@folke
Copy link
Owner

folke commented Dec 29, 2022

I've reverted my change for now. Need to look into this further to see how to properly solve this.

@folke folke closed this as completed in 3a1a10c Dec 29, 2022
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

Successfully merging a pull request may close this issue.

2 participants