kdl-org / kdl

the kdl document language specifications
https://kdl.dev
Other
1.1k stars 61 forks source link

Vim syntax highlighting #258

Closed auctumnus closed 7 months ago

auctumnus commented 2 years ago

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 image (with all of the code - presumably up to a closing } - commented).

danini-the-panini commented 2 years ago

Tree-sitter is a neovim specific thing I believe

a-kenji commented 2 years ago

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.

spaarmann commented 2 years ago

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.

eyelidlessness commented 2 years ago

@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.

spaarmann commented 2 years ago

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.

imsnif commented 1 year ago

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.

mikavilpas commented 8 months ago

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:

image

Would you welcome a PR of some sort to indicate this as a potential setup in the readme, for example?

zkat commented 8 months ago

@sp3ctum that should really be part of the plugin's readme, not this repo.

spaarmann commented 7 months ago

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?

zkat commented 7 months ago

Nothing else to do here. kdl.vim and tree-sitter-kdl both exist now and are linked from the README.