Repository navigation
[mini.comment] Comments do not work in Svelte files #2565
Contributing guidelines
Module(s)mini.comment QuestionHello, I develop websites using the Svelte framework and started to use I have realised that the comments don't seem to work in the When I do try, my cursor jumps to the first non-blank char of the current line, and the following message is printed : Am I missing something in the settings that would make it work? or is it simply something not implemented yet? |
Replies: 2 comments 4 replies
AboutYou probably don't even need Treesitter helps to determine the appropriate From :h commenting:
DebugThat said, are you sure the treesitter parsers are installed correctly? Run: :InspectTree
IIt should not print: Also try Treesitter configExtracted from MiniMax: Codelocal au = vim.api.nvim_create_augroup("custom-config", { clear = true })
vim.api.nvim_create_autocmd("PackChanged", {
group = au,
desc = ":TSUpdate",
callback = function(ev)
local name, kind = ev.data.spec.name, ev.data.kind
if name ~= "nvim-treesitter" or kind ~= "update" then
return
end
if not ev.data.active then
vim.cmd.packadd("nvim-treesitter")
end
vim.cmd("TSUpdate")
end,
})
vim.pack.add({
{ src = "https://github.com/nvim-treesitter/nvim-treesitter" },
})
-- Languages which will have parsers installed and auto enabled.
-- After changing this, restart Neovim once to install necessary parsers. Wait
-- for the installation to finish before opening a file for added language(s).
local languages = {
-- Already pre-installed with Neovim. Used as an example.
"lua",
"vimdoc",
"markdown",
-- Add more languages here. To see available ones:
-- - Execute `:=require('nvim-treesitter').get_available()`
-- - Visit 'SUPPORTED_LANGUAGES.md' at
-- https://github.com/nvim-treesitter/nvim-treesitter/blob/main
"svelte",
"javascript",
"typescript",
"css",
"scss",
}
local isnt_installed = function(lang)
return #vim.api.nvim_get_runtime_file("parser/" .. lang .. ".*", false) == 0
end
local to_install = vim.tbl_filter(isnt_installed, languages)
if #to_install > 0 then
-- NOTE: Asynchronous
require("nvim-treesitter").install(to_install)
end
local filetypes = {}
for _, lang in ipairs(languages) do
for _, ft in ipairs(vim.treesitter.language.get_filetypes(lang)) do
table.insert(filetypes, ft)
end
end
vim.api.nvim_create_autocmd("FileType", {
group = au,
pattern = filetypes,
desc = "Start tree-sitter",
callback = function(ev)
vim.treesitter.start(ev.buf)
end,
}) |
About
You probably don't even need
mini.comment, since commenting is already built into Neovim, withmini.commentserving as the reference implementation. You can probably guess who actually brought it into the core.Treesitter helps to determine the appropriate
commentstringfor the cursor position, bypassingvim.bo.commentstring. Basically, you need to configure treesitter parsers forsvelteand its injected languages, such asjavascriptandcss.From :h commenting: