kdl
kdl copied to clipboard
Vim syntax highlighting
I use Vim as my editor, and it'd be really nice if there were a Vim syntax file or tree-sitter highlighter.
There's prior work at this repo, but it doesn't appear to actually work (installed the parser and such and it didn't highlight anything, but I'm also not 100% on if I installed it right 😅)
I started an attempt at a regular Vim syntax, but I'm not sure if slashdash comments can be represented; with rules like
syn region kdlSlashdashComment start="^\@<!/-" end="\s"
syn region kdlSlashdashNodeComment start="/-{" end="}" contains=kdlBlock
syn region kdlSlashdashNodeComment start="^\@<=/-" end="}"
which are just translated from the vscode syntax patterns (as far as i know!), I end up with highlights like
(with all of the code - presumably up to a closing } - commented).
Tree-sitter is a neovim specific thing I believe
Tree-sitter is a neovim specific thing I believe
Neovim integrated tree-sitter bindings natively, but I don't think that means vim couldn't make use of tree-sitter through a plugin.
I started working on a tree-sitter parser. It's not complete yet (notably type annotations and /-
comments are missing right now) but it's getting there :)
I also included some installation instructions for use with nvim-treesitter in the README; I think the step of having to manually copy in the highlights.scm
file is easily missed.
@spaarmann are you interested in contributions to the tree-sitter grammar? Some/all of the caveats currently listed in your README are areas I could potentially help, and would be a great jumping off point for use cases like generating type definitions for consuming languages.
Yes, definitely! I meant to get at least slash-dash comments working but I've been super busy lately so I haven't even started on it yet; any contributions are much appreciated.
I also made this: https://github.com/imsnif/kdl.vim It's not fully-featured, but I think it's a pretty good experience all-in-all.
Hi all, I found out the neovim plugin nvim-treesitter supports kdl out of the box:
kdl (maintained by @amaanq)
It looks like it was added about a year ago, see the project's kdl related PRs here
In neovim v0.9.5 I was able to enable using the lazyvim setup using the following plugin spec:
-- ~/.config/nvim/lua/plugins/treesitter.lua
return {
{
"nvim-treesitter/nvim-treesitter",
opts = function(_, opts)
vim.list_extend(opts.ensure_installed, {
"kdl",
})
end,
},
{
"nvim-ts-context-commentstring",
opts = {},
config = {
kdl = "// %s",
},
},
}
I'm new to neovim but I think it works as I now get syntax highlighting, structural selection and am able to :InspectTree
a kdl file:
Would you welcome a PR of some sort to indicate this as a potential setup in the readme, for example?
@sp3ctum that should really be part of the plugin's readme, not this repo.
I think the specific setup doesn't fit here, but the link to nvim-treesitter
under the editor support section in the readme here seems appropriate?
Nothing else to do here. kdl.vim and tree-sitter-kdl both exist now and are linked from the README.