Skip to content

Conversation

@takeokunn
Copy link
Collaborator

Summary

Implement LSP textDocument/foldingRange support for nixd, enabling code folding in editors.

Relative Issue #150

CleanShot 2026-01-02 at 02 10 41@2x

Changes

  • Add FoldingRange.cpp implementing the folding range handler
  • Register textDocument/foldingRange method in Support.cpp
  • Advertise foldingRangeProvider: true capability in LifeTime.cpp
  • Add onFoldingRange method declaration in Controller.h
  • Update meson.build to include new source file
  • Add lit tests for folding range functionality
  • Add LSP fold configuration to nvim-lsp.nix for testing

Supported Folding Regions

  • Attribute sets ({ }, rec { })
  • Lists ([ ])
  • Lambda functions ({ args }: ..., x: ...)
  • Let expressions (let ... in ...)
  • With expressions (with ...; ...)
  • If expressions (if ... then ... else ...)
  • Multiline strings ('' ... '')

Implementation Details

  • Uses "region" kind for all folding ranges (per LSP spec)
  • Only folds constructs spanning 2+ lines
  • Includes recursion depth protection (max 256) to prevent stack overflow
  • Processes AST asynchronously via thread pool

Test Plan

  • meson test passes (all 62 lit tests)
  • Basic test validates attribute sets and lists (folding-range/basic.md)
  • Additional test validates let expressions and lambdas (folding-range/let-lambda.md)
  • Manual verification with nix develop .#nvim

- Implement onFoldingRange handler for textDocument/foldingRange LSP requests
- Recursively collect foldable regions from AST nodes including attribute sets,
  lists, lambdas, let/with/if expressions, and multiline strings
- Register folding range provider and method in controller
- Update build to include new FoldingRange implementation
…ze checks

- Add basic.md to test folding for attribute sets and lists
- Add let-lambda.md to test folding for let expressions and lambdas
- Update initialize.md and semantic-tokens/initialize.md to check foldingRangeProvider capability
- Add foldmethod, foldexpr, foldlevel, and foldenable to options
- Improve code folding experience using LSP folding capabilities
Copy link
Member

@inclyc inclyc left a comment

Choose a reason for hiding this comment

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

LGTM! The quality of this PR looks excellent. Thank you so much for your contribution; I don't think I have any further comments.

Did you use Claude Code or any other AI tools to assist with the development? The documentation for nixd is honestly not great, so I imagine it’s quite challenging for newcomers to get started.

If you are still interested in contributing to nixd, here is a list of features that users want the most:

  1. Support for Code Actions: For example, issue #466. This is the most requested feature that hasn't been implemented yet.
  2. Reducing "Noisy" Error Reporting: Some current error messages are far too intrusive. We should probably use elog for these specific cases:
  • textDocument/definition
  • textDocument/codeAction
  • textDocument/documentSymbol
  • textDocument/inlayHint
  • textDocument/documentLink
  1. Advancing PR #749: This involves adding comment parsing functionality into nixf.

LGTM! このPRは非常にクオリティが高いですね。貢献していただき、本当にありがとうございます。私からの修正要望は特にありません。

開発にあたって、Claude Codeや他のAIツールなどを使用されましたか?nixdは開発ドキュメントがあまり整っていないので、新しく参加される方にはハードルが高いのではないかと思っています。

もし引き続きnixdの開発にご興味があれば、ユーザーから特に要望の多い機能をまとめましたので、参考にしてください:

  1. Code Actions への対応: 例:issue #466。これは最もリクエストが多いものの、未実装の機能です。
  2. エラー通知の整理: 現在、一部のエラーが少し「うるさすぎる(ノイズが多い)」状態です。以下の項目については、直接 elog を使用して報告するのが適切かもしれません:
  • textDocument/definition
  • textDocument/codeAction
  • textDocument/documentSymbol
  • textDocument/inlayHint
  • textDocument/documentLink
  1. PR #749 の推進: nixf にコメント解析機能を追加する作業です。

@inclyc inclyc merged commit d3913cc into nix-community:main Jan 2, 2026
19 checks passed
@inclyc
Copy link
Member

inclyc commented Jan 2, 2026

Telegramの @inclyc、またはMatrixの @inclyc:matrix.org で私に連絡を取ることができます。

また、あなたをnixdのCollaborator として招待しようと考えています。そうすれば、自身のレポジトリを経由せずに、このレポジトリに直接ブランチをプッシュできるようになります。

@inclyc inclyc linked an issue Jan 2, 2026 that may be closed by this pull request
@takeokunn
Copy link
Collaborator Author

@inclyc
I’ve been using AI quite a bit lately—specifically, I'm calling Codex MCP from Claude Code. (Check out my workflow here: URL)

Although I’ve been an engineer for about 10 years, I don't have much experience with C++, so I made sure to test everything very carefully.

I’m planning to contribute a lot to nixd, so thanks for the collaborator invite! I’m excited to dive in and get to work!

最近AIをかなり活用していますねー
具体的にはClaude CodeのCodex MCPを呼び出しています。(ワークフローはこちら:URL

エンジニア歴は10年ほどありますが、C++の経験は浅いため、全てを入念にテストしました。

nixdへガンガンcontributionしていくつもりです!!
Collaboratorの招待ありがとうございます!! 機能追加たくさんしていきます!!

@inclyc inclyc added enhancement New feature or request nixd:controller labels Jan 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request nixd:controller

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nixd/foldingRange: support textDocument/foldingRange

2 participants