larsks
larsks

Reputation: 312078

YAML indenting with neovim and treesitter?

I've recently upgraded to neovim 0.5.0, and I've been experimenting at replacing older syntax and indenting plugins with treesitter. I'm having some problems getting things to work correctly when editing YAML files.

I have the following in my init.lua file:

local ts = require 'nvim-treesitter.configs'
ts.setup {ensure_installed = 'maintained',
    highlight = {
        enable = true,
        additional_vim_regex_highlighting = false,
    },
    indent = {
        enable = true,
        disable = {"python", }
    },
}

Running :checkhealth reports

health#nvim_treesitter#check
========================================================================
[...]
## Parser/Features H L F I J
[...]
  - yaml           ✓ ✓ ✓ ✓ ✓ 

But when I create a YAML file, for example...

- hosts: foo<RETURN>

...then the cursor ends up at column 0 on the following line, rather than indented as required. This behaviors persists for the rest of the file: regardless of the YAML syntax, the cursor always goes to column 0 on return

I know that treesitter indent support is considered "experimental". Is this just broken right now, or do I have something misconfigured?

Upvotes: 4

Views: 3925

Answers (1)

user10706046
user10706046

Reputation:

Looks like the YAML parser's indentations are pretty rudimentary: https://github.com/nvim-treesitter/nvim-treesitter/blob/master/queries/yaml/indents.scm

You may have a better development experience by just disabling tree-sitter indentation for just yaml and using the default Vim regex indentation instead.

In your nvim-treesitter config

require('nvim-treesitter.configs').setup {
  indent = {
    enable = true,
    disable = { 'yaml' }
  }
}

Upvotes: 3

Related Questions