Indentation issue in YAML Sequence/Arrays
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- yaml
- Domain
- tooling
Research direction
Reproduce the issue in a YAML buffer with nvim-treesitter indentation enabled, using the sequence followed by foo: bar shown in the report. Trace the YAML indentation entry point used by nvim-treesitter and verify that inserting a new sequence item preserves the sequence indentation in both file layouts.
Written by the indexing model from the issue text.
Description
Describe the bug
When adding elements to a YAML sequence/array, typing a dash (-) causes the line to be de-indented to column 1 of the current line.
This seems to only happen if the YAML sequence/array is superceded by other content.
To Reproduce
-
Create a new YAML file:
vim /tmp/test.yaml -
Insert a sequence/array:
test: - 1 - 2 - 3 # so far so good -
Insert arbitrary content after the sequence/array:
test: - 1 - 2 - 3 # so far so good foo: bar -
Go back to add a new element to the
testarray:test: - 1 - 2 - 3 # Good! - 4 # Bad! This got de-indented to column 1 foo: bar -
Move
foo: barto the beginning of the file and add a new element to the array:foo: bar test: - 1 - 2 - 3 # Good! - 4 # Good!
Expected behavior
New elements added to YAML sequences/arrays should be indented correctly.
Output of :checkhealth nvim-treesitter
==============================================================================
nvim-treesitter: require("nvim-treesitter.health").check()
Installation ~
- OK `tree-sitter` found 0.20.8 (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v21.1.0 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
Version: Apple clang version 15.0.0 (clang-1500.0.40.1)
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.
OS Info:
{
machine = "arm64",
release = "23.1.0",
sysname = "Darwin",
version = "Darwin Kernel Version 23.1.0: Mon Oct 9 21:28:12 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T8103"
} ~
Parser/Features H L F I J
- bash ✓ ✓ ✓ . ✓
- c ✓ ✓ ✓ ✓ ✓
- comment ✓ . . . .
- csv ✓ . . . .
- diff ✓ . . . .
- dockerfile ✓ . . . ✓
- git_config ✓ . . . .
- git_rebase ✓ . . . ✓
- gitattributes ✓ . . . ✓
- gitcommit ✓ . . . ✓
- gitignore ✓ . . . .
- go ✓ ✓ ✓ ✓ ✓
- hcl ✓ . ✓ ✓ ✓
- http ✓ . . . ✓
- ini ✓ . ✓ . .
- jq ✓ . . . ✓
- json ✓ ✓ ✓ ✓ .
- jsonc ✓ ✓ ✓ ✓ ✓
- lua ✓ ✓ ✓ ✓ ✓
- make ✓ . ✓ . ✓
- markdown ✓ . ✓ ✓ ✓
- markdown_inline ✓ . . . ✓
- mermaid ✓ . . . .
- python ✓ ✓ ✓ ✓ ✓
- query ✓ ✓ ✓ ✓ ✓
- requirements ✓ . . . ✓
- rust ✓ ✓ ✓ ✓ ✓
- terraform ✓ . ✓ ✓ ✓
- toml ✓ ✓ ✓ ✓ ✓
- vhs ✓ . . . .
- vim ✓ ✓ ✓ . ✓
- vimdoc ✓ . . . ✓
- yaml ✓ ✓ ✓ ✓ ✓
Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang} ~
Output of nvim --version
$ nvim --version
NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1699524327
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.4/share/nvim"
Run :checkhealth for more info
Additional context
Workaround:
Disable nvim-treesitter indentation for YAML filetypes.
indent = {
disable = { 'yaml' }
}
- Dominant language
- Tree-sitter Query
- Stars
- 14.4k
- Forks
- 1.4k
- Avg merge
- 4h 35m
- Merged PRs (30d)
- 13
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nvim-treesitter/nvim-treesitter
-
indent
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
nvim-treesitter/nvim-treesitter#8609 ·
-
good first issue indent
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
nvim-treesitter/nvim-treesitter#2397 · 7 comments ·
-
indent
Difficulty 3/5 1-2 days Newbie friendliness 45/100
nvim-treesitter/nvim-treesitter#8555 ·
-
indent
Difficulty 3/5 1-2 days Newbie friendliness 52/100
nvim-treesitter/nvim-treesitter#8432 · 8 comments · 1 reaction ·
-
indent
Difficulty 4/5 3-5 days Newbie friendliness 25/100
nvim-treesitter/nvim-treesitter#8261 · 3 comments ·
All issues in nvim-treesitter/nvim-treesitter
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
bancolombia/sentinel#20 ·
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
chore
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
alunduil/woodland-generators#669 ·
-
area: tooling
Difficulty 2/5 1-3 hours Newbie friendliness 86/100