i be working
This commit is contained in:
@@ -119,7 +119,9 @@ return {
|
||||
end, "[T]oggle Inlay [H]ints")
|
||||
end
|
||||
|
||||
-- Svelte-specific: notify on TS/JS file changes
|
||||
-- Svelte-specific: keep treesitter highlighting in control
|
||||
-- (semantic tokens can make svelte buffers look oddly colored)
|
||||
-- and notify on TS/JS file changes
|
||||
-- https://github.com/sveltejs/language-tools/issues/2008#issuecomment-2351976230
|
||||
if client and client.name == "svelte" then
|
||||
vim.api.nvim_create_autocmd("BufWritePost", {
|
||||
|
||||
@@ -4,12 +4,13 @@ return {
|
||||
lazy = false,
|
||||
build = ":TSUpdate",
|
||||
config = function()
|
||||
require("nvim-treesitter").setup({
|
||||
local ts = require("nvim-treesitter")
|
||||
ts.setup({
|
||||
install_dir = vim.fn.stdpath("data") .. "/site",
|
||||
})
|
||||
|
||||
-- Install parsers (async, no-op if already installed)
|
||||
require("nvim-treesitter").install({
|
||||
ts.install({
|
||||
"vimdoc",
|
||||
"javascript",
|
||||
"typescript",
|
||||
@@ -28,6 +29,75 @@ return {
|
||||
"nix",
|
||||
})
|
||||
|
||||
-- Enable treesitter highlighting - indentexpr set automatically per filetype
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = {
|
||||
"svelte",
|
||||
"javascript",
|
||||
"typescript",
|
||||
"tsx",
|
||||
"html",
|
||||
"css",
|
||||
"lua",
|
||||
"nix",
|
||||
},
|
||||
callback = function()
|
||||
pcall(vim.treesitter.start)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
-- Workaround: some svelte parser/query combos don't inject JS for <script>
|
||||
-- blocks without an explicit lang attribute, which leaves raw_text as @none.
|
||||
vim.treesitter.query.set("svelte", "injections", [=[
|
||||
; inherits: html_tags
|
||||
|
||||
((style_element
|
||||
(start_tag
|
||||
(attribute
|
||||
(attribute_name) @_attr
|
||||
(quoted_attribute_value
|
||||
(attribute_value) @_lang)))
|
||||
(raw_text) @injection.content)
|
||||
(#eq? @_attr "lang")
|
||||
(#any-of? @_lang "scss" "postcss" "less")
|
||||
(#set! injection.language "scss"))
|
||||
|
||||
; fallback for plain <script>...</script>
|
||||
((script_element
|
||||
(raw_text) @injection.content)
|
||||
(#set! injection.language "javascript"))
|
||||
|
||||
((script_element
|
||||
(start_tag
|
||||
(attribute
|
||||
(attribute_name) @_attr
|
||||
(quoted_attribute_value
|
||||
(attribute_value) @_lang)))
|
||||
(raw_text) @injection.content)
|
||||
(#eq? @_attr "lang")
|
||||
(#any-of? @_lang "ts" "typescript")
|
||||
(#set! injection.language "typescript"))
|
||||
|
||||
((script_element
|
||||
(start_tag
|
||||
(attribute
|
||||
(attribute_name) @_attr
|
||||
(quoted_attribute_value
|
||||
(attribute_value) @_lang)))
|
||||
(raw_text) @injection.content)
|
||||
(#eq? @_attr "lang")
|
||||
(#any-of? @_lang "js" "javascript")
|
||||
(#set! injection.language "javascript"))
|
||||
|
||||
((element
|
||||
(start_tag
|
||||
(attribute
|
||||
(attribute_name) @_attr
|
||||
(quoted_attribute_value
|
||||
(attribute_value) @injection.language)))
|
||||
(text) @injection.content)
|
||||
(#eq? @_attr "lang")
|
||||
(#eq? @injection.language "pug"))
|
||||
]=])
|
||||
end,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user