Skip to content

Add code folding support - #99

Merged
JojOatXGME merged 2 commits into
NixOS:masterfrom
Meallia:folding-support
May 1, 2026
Merged

JojOatXGME merged 2 commits into
NixOS:masterfrom
Meallia:folding-support

Conversation

@Meallia

@Meallia Meallia commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Followup to PR #92 by 0xcaff

Notes on strings

The folding test framework cannot match single quotes in folding placeholders.

I tried to replace them with \', ', ', but there is no logic to un-escape the text before the comparison is made.

I also tried defining a subclass with a different placeholder specifically for the tests, but I could not figure out how to use it during testing.

As a result, I choose to use double quotes (" ... ") as placeholder for all string types, but we could also remove the test for indented strings and use '' ... '' as placeholder.

@Meallia Meallia left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added suggestions to use single quotes for indented string.

@JojOatXGME JojOatXGME mentioned this pull request Apr 26, 2026

@JojOatXGME JojOatXGME left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great contribution. 🚀 Sorry for not responding earlier. I left some comments, but I would be happy to merge the PR as it is. Just mention your preference whether you would favor to act on some comments first.


override fun visitBindInherit(o: NixBindInherit) {
if (o.attributes.isNotEmpty()) {
val placeholderText = if (o.source == null) {" ... "} else {" (${o.source!!.node.text}) ... "}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue ⚠️ (non-blocking): This could result in a very long placeholder text, because o.source can contain an arbitrary expression.

let
  inherit
    (
      rec {
        a = b;
        b = c;
        c = 42;
      }
    )
    a;
in
a

However, I don't think this is a big issue. Nobody forces a user to fold this region, as isCollapsedByDefault returns false. Besides, having a long expression here seems rather uncommon.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did not think about that.

With your example, the IDE puts everything on a single line. It's not pretty, but it seems uncommon enough to be left as-is.

image

We could improve it by merging white-spaces.

@JojOatXGME

Copy link
Copy Markdown
Contributor

Also feel free to add a line to the CHANGELOG.md. However, if you do that, you might want to rebase this PR (or merge master) first.

@Meallia

Meallia commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review, I'll try to implement your suggestions.

@@ -0,0 +1,5 @@
<fold text='{ ... }'>{
<fold text='custom'># region custom

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

praise 🎉: I did not think about region comments. I guess using CustomFoldingBuilder is useful even without having another plugin depending on this one.

@JojOatXGME
JojOatXGME merged commit 13d7669 into NixOS:master May 1, 2026
5 checks passed
@JojOatXGME

Copy link
Copy Markdown
Contributor

Nice work. I merged your PR. I will probably create a release with your changes over the weekend.

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