Skip to content

[audit] fix foldmethod: use 'expr' so treesitter foldexpr is consulted#143

Closed
stanfish06 wants to merge 1 commit into
masterfrom
audit/foldmethod-expr
Closed

[audit] fix foldmethod: use 'expr' so treesitter foldexpr is consulted#143
stanfish06 wants to merge 1 commit into
masterfrom
audit/foldmethod-expr

Conversation

@stanfish06
Copy link
Copy Markdown
Owner

What

lua/config/options.lua:100 sets foldmethod = "indent" while foldexpr is pointed at vim.treesitter.foldexpr(). These two settings contradict each other.

Where

lua/config/options.lua lines 100–101:

vim.o.foldmethod = "indent"                          -- ← wrong
vim.o.foldexpr  = "v:lua.vim.treesitter.foldexpr()"

Why it matters

Neovim only calls foldexpr when foldmethod = "expr". With foldmethod = "indent" the expression is set but never evaluated — all folding falls back to dumb indent-counting. This silently breaks every treesitter-aware fold boundary (e.g. multi-line if/match arms, docstrings, etc.).

Change

-vim.o.foldmethod = "indent"
+vim.o.foldmethod = "expr"

One character change, no behaviour regression for any other option.


Generated by Claude Code

…ulted

foldmethod='indent' silently ignores foldexpr; the treesitter fold
expression is only evaluated when foldmethod='expr'.

https://claude.ai/code/session_014eiycWG5KeoanDfLHDC825
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c4e18ac60

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lua/config/options.lua
-- folding
vim.o.foldlevel = 10
vim.o.foldmethod = "indent"
vim.o.foldmethod = "expr"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore fallback folding for non-Tree-sitter filetypes

When a buffer has no Tree-sitter parser or vim.treesitter.start() fails, this global foldmethod=expr still leaves foldexpr as vim.treesitter.foldexpr(), which returns 0 without a parser, so those files have no folds at all. The repo only installs parsers for a limited set of languages in lua/config/treesitter.lua, and its FileType fallback only enables syntax on; it does not switch folding back from expr, so opening unsupported filetypes such as YAML/JSON or any parser install failure regresses from the previous indent-based folding to no usable folds.

Useful? React with 👍 / 👎.

@stanfish06 stanfish06 closed this Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants