diff --git a/lua/base.lua b/lua/base.lua index 01a2ae9..60988b7 100644 --- a/lua/base.lua +++ b/lua/base.lua @@ -126,6 +126,7 @@ opt.mouse = "" vim.cmd([[hi CursorLine cterm=NONE ctermbg=darkgray ctermfg=white]]) vim.cmd([[au BufRead,BufNewFile .env.* set filetype=sh]]) vim.cmd([[au BufRead,BufNewFile Dockerfile.* set filetype=dockerfile]]) +vim.cmd([[au BufRead,BufNewFile *.html set filetype=html]]) -- redo folds on write vim.cmd([[au BufWrite * normal zx]]) diff --git a/lua/plugins/config.lua b/lua/plugins/config.lua index ab5d76c..92ba8ba 100644 --- a/lua/plugins/config.lua +++ b/lua/plugins/config.lua @@ -169,8 +169,7 @@ function M.lualine() lualine_c = {}, lualine_x = {}, lualine_y = {}, - lualine_z = { - }, + lualine_z = {}, }, extensions = {}, }) @@ -180,11 +179,11 @@ function M.nvim_treesitter() local highlight_disable = { typescript = true, tsx = true, - html = true, + --html = true, javascript = true, cpp = true, } - local rainbow_disable = vim.tbl_extend("force", highlight_disable, { svelte = true }) + local rainbow_disable = vim.tbl_extend("force", highlight_disable, { svelte = true, html = true }) local too_many_lines = function(bufnr) return vim.api.nvim_buf_line_count(bufnr) > 5000 @@ -215,6 +214,19 @@ function M.nvim_treesitter() vim.opt.foldmethod = "expr" vim.opt.foldexpr = "nvim_treesitter#foldexpr()" end + + local parser_config = require("nvim-treesitter.parsers").get_parser_configs() + parser_config.htmldjango = { + install_info = { + url = "~/code/treesitter/tree-sitter-htmldjango", -- local path or git repo + files = { "src/parser.c" }, + -- optional entries: + branch = "main", -- default branch in case of git repo if different from master + generate_requires_npm = false, -- if stand-alone parser without npm dependencies + requires_generate_from_grammar = false, -- if folder contains pre-generated src/parser.c + }, + filetype = "htmldjango", -- if filetype does not match the parser name + } end function M.nvim_lspconfig() @@ -325,6 +337,7 @@ function M.nvim_lsp_installer() "svelte", "tailwindcss", "zls", + "emmet_ls", } for _, s in ipairs(auto_servers) do diff --git a/lua/plugins/startup.lua b/lua/plugins/startup.lua index 6f1fbea..25b76df 100644 --- a/lua/plugins/startup.lua +++ b/lua/plugins/startup.lua @@ -41,6 +41,7 @@ require("packer").startup(function(use) run = ":TSUpdate", }) use("nvim-treesitter/nvim-treesitter-context") + use("nvim-treesitter/playground") use("neovim/nvim-lspconfig") use("williamboman/nvim-lsp-installer") use("nvim-lua/plenary.nvim") diff --git a/queries/html/highlights.scm b/queries/html/highlights.scm new file mode 100644 index 0000000..a5145a6 --- /dev/null +++ b/queries/html/highlights.scm @@ -0,0 +1,55 @@ +; inherits: html + +(attribute_name) @keyword + +[ + "<" + ">" + "" +] @punctuation.bracket + +(doctype) @comment + +((tag_name) @type (#match? @type "^(head|body)$")) + +((tag_name) @comment (#eq? @comment "html")) + +(element + (start_tag + ((tag_name) @function) + (attribute (attribute_name) @_alpine)) + (#lua-match? @_alpine "^[@:]%l+.-$")) + +(element + (start_tag + (attribute (attribute_name) @_alpine)) + (end_tag ((tag_name) @function)) + (#lua-match? @_alpine "^[@:]%l+.-$")) + +(element + (start_tag + ((tag_name) @function) + (attribute (attribute_name) @_alpine)) + (#lua-match? @_alpine "^x[-]%l+$")) + +(element + (start_tag + (attribute (attribute_name) @_alpine)) + (end_tag ((tag_name) @function)) + (#lua-match? @_alpine "^x[-]%l+$")) + +(element + (self_closing_tag + ((tag_name) @function) + (attribute (attribute_name) @_alpine)) + (#lua-match? @_alpine "^[@:]%l+.-$")) + +(element + (self_closing_tag + ((tag_name) @function) + (attribute (attribute_name) @_alpine)) + (#lua-match? @_alpine "^x[-]%l+$")) + +(element (start_tag ((tag_name) @function) (#eq? @function "template"))) +(element (end_tag ((tag_name) @function) (#eq? @function "template"))) diff --git a/queries/html/injections.scm b/queries/html/injections.scm new file mode 100644 index 0000000..6143cb3 --- /dev/null +++ b/queries/html/injections.scm @@ -0,0 +1,21 @@ +((attribute + (attribute_name) @_alpine + (quoted_attribute_value (attribute_value) @javascript)) + (#lua-match? @_alpine "^[@:]%l+.-$")) + +((attribute + (attribute_name) @_alpine + (quoted_attribute_value (attribute_value) @javascript)) + (#lua-match? @_alpine "^x[-]%l+$")) + +(script_element + (raw_text) @javascript) + +((text) @python (#lua-match? @python "^{%p%s+%l+%s+.-%s+%p}$")) + +((text) @python (#lua-match? @python "^{{%s+.-%s+}}$")) + +((attribute + (attribute_name) @_hyperscript + (quoted_attribute_value (attribute_value) @python)) + (#eq? @_hyperscript "_"))