vim-matchup
vim-matchup copied to clipboard
Not working in embedded template files (go-templ, neovim)
Explain the issue
- Neovim with treesitter integration.
templinstalled as a treesitterensure_installedfiletype. -
go-templ file, builtin textobjects for tags, like
vitwork, but the expected highlighting and%objects don't get attached. - Highlighting and objects should be available in embedded html.
- Using
%objects in the following file instead go to the go langauge blocks delineated by{}. I compared the inner html in it's own html file, and treesitter is marking up the inner html just fine (within thecomponent_block)
If your issue is instead a feature request or anything else, please consider if minimal examples and vimrc files might still be relevant.
Minimal working example
.templ file
package page
templ navbar(currentPage string) {
<div class="navbar bg-base-100">
<div class="navbar-start">
<a class="btn btn-ghost text-xl">{ currentPage }</a>
</div>
<div class="navbar-center hidden lg:flex">
<ul class="menu menu-horizontal px-1">
<li><a>Item 1</a></li>
<li><a>Item 2</a></li>
</ul>
</div>
<div class="navbar-end">
<a class="btn">Button</a>
</div>
</div>
}
Treesitter playground identifying the embedded html:
component_declaration [2, 0] - [17, 1]
name: component_identifier [2, 6] - [2, 12]
parameter_list [2, 12] - [2, 32]
parameter_declaration [2, 13] - [2, 31]
name: identifier [2, 13] - [2, 24]
type: type_identifier [2, 25] - [2, 31]
component_block [2, 33] - [17, 1]
element [3, 0] - [16, 6]
tag_start [3, 0] - [3, 32]
name: element_identifier [3, 1] - [3, 4]
attribute [3, 5] - [3, 31]
name: attribute_name [3, 5] - [3, 10]
value: quoted_attribute_value [3, 11] - [3, 31]
attribute_value [3, 12] - [3, 30]
element [4, 4] - [6, 10]
tag_start [4, 4] - [4, 30]
name: element_identifier [4, 5] - [4, 8]
attribute [4, 9] - [4, 29]
name: attribute_name [4, 9] - [4, 14]
value: quoted_attribute_value [4, 15] - [4, 29]
attribute_value [4, 16] - [4, 28]
element [5, 8] - [5, 49]
tag_start [5, 8] - [5, 41]
name: element_identifier [5, 9] - [5, 10]
attribute [5, 11] - [5, 40]
name: attribute_name [5, 11] - [5, 16]
value: quoted_attribute_value [5, 17] - [5, 40]
attribute_value [5, 18] - [5, 39]
...
Minimal vimrc file
Please provide a minimal vimrc file that reproduces the issue. The following should often suffice:
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",
"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",
cmd = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSModuleInfo" },
dependencies = {
"nvim-treesitter/playground",
"nvim-treesitter/nvim-treesitter-textobjects",
},
config = function()
require("nvim-treesitter.configs").setup({
ensure_installed = {
"html",
"css",
"go",
"templ",
},
highlight = {
enable = true,
use_languagetree = true,
},
matchup = {
enable = true, -- required for vim-matchup
disable_virtual_text = true,
},
playground = {
enable = true,
},
})
end,
},
{
-- https://github.com/andymass/vim-matchup#tree-sitter-integration
"andymass/vim-matchup",
lazy = false,
config = function()
vim.g.matchup_matchparen_offscreen = { method = "popup" }
end,
},
}
require("lazy").setup(plugins, {
root = root .. "/plugins",
})
vim.cmd.colorscheme("tokyonight")