kdl icon indicating copy to clipboard operation
kdl copied to clipboard

Vim syntax highlighting

Open auctumnus opened this issue 3 years ago • 5 comments

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

auctumnus avatar Feb 08 '22 17:02 auctumnus

Tree-sitter is a neovim specific thing I believe

danini-the-panini avatar Mar 03 '22 12:03 danini-the-panini

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.

a-kenji avatar Mar 03 '22 12:03 a-kenji

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 avatar Apr 15 '22 15:04 spaarmann

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

eyelidlessness avatar Jun 09 '22 22:06 eyelidlessness

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.

spaarmann avatar Jun 10 '22 07:06 spaarmann

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.

imsnif avatar Oct 31 '22 08:10 imsnif

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?

mikavilpas avatar Jan 14 '24 10:01 mikavilpas

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

zkat avatar Jan 15 '24 18:01 zkat

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?

spaarmann avatar Jan 16 '24 18:01 spaarmann

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

zkat avatar Feb 08 '24 19:02 zkat