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

refactor(autocommand): remove class conceal #406

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions lua/custom/autocommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,41 +133,4 @@ vim.api.nvim_create_autocmd({ 'LspAttach' }, {
end,
})

local conceal_ns = vim.api.nvim_create_namespace('class_conceal')
vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'TextChanged', 'InsertLeave' }, {
desc = 'Conceal HTML class attributes. Ideal for big TailwindCSS class lists',
group = vim.api.nvim_create_augroup('class_conceal', { clear = true }),
pattern = { '*.tsx' },
callback = function(event)
local bufnr = event.buf or vim.api.nvim_get_current_buf()

---Ref: https://gist.github.com/mactep/430449fd4f6365474bfa15df5c02d27b
local language_tree = vim.treesitter.get_parser(bufnr, 'tsx')
local syntax_tree = language_tree:parse()
local root = syntax_tree[1]:root()

local ok, query = pcall(
vim.treesitter.query.parse,
'tsx',
[[
((jsx_attribute
(property_identifier) @att_name (#eq? @att_name "class")
(string (string_fragment) @class_value)))
]]
)
if not ok then
return
end

for _, captures, metadata in query:iter_matches(root, bufnr, root:start(), root:end_(), {}) do
local start_row, start_col, end_row, end_col = captures[2]:range()
vim.api.nvim_buf_set_extmark(bufnr, conceal_ns, start_row, start_col + 3, {
end_line = end_row,
end_col = end_col,
conceal = '%', -- "…",
})
end
end,
})

vim.opt.updatetime = 100
Loading