Skip to content

add folding builder - #92

Closed
0xcaff wants to merge 3 commits into
NixOS:masterfrom
0xcaff:martin/folding
Closed

0xcaff wants to merge 3 commits into
NixOS:masterfrom
0xcaff:martin/folding

Conversation

@0xcaff

@0xcaff 0xcaff commented Mar 9, 2025

Copy link
Copy Markdown
Contributor

this adds folding. makes it much easier to read large blocks of nix code.

todo:

  • use customfoldingbuilder maybe?

this adds folding. makes it much easier to read large blocks of nix code.

todo:
* use customfoldingbuilder maybe?
# Conflicts:
#	src/main/resources/META-INF/plugin.xml

@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.

Thanks for your contribution. Here is my review so far. I haven't tried whether it actually works, but it looks simple enough. Of course, tests would always be nice, but doesn't seem necessary in this case. Not sure if there is anything which could be tested reasonably, besides verifying that we don't throw any runtime exception.

}

override fun visitFile(file: PsiFile) {
super.visitFile(file)

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.

question (non-blocking): Why are you calling the super-method here, and only here? The super method doesn't seem to do anything important.

}

override fun visitExprIf(o: NixExprIf) {
o.acceptChildren(this)

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.

suggestion: You could override visitElement(PsiElement) with o.acceptChildren(this). Then you can remove all the other methods that do nothing but delegating to the children.

There are also various method which only delegate to children using element-specific code. Like visitExprWith, which just calls o.exprList.forEach { it.accept(this) }. Is there a good reason for that? Otherwise, you could just remove them after overriding visitElement.

return descriptors.toArray(FoldingDescriptor.EMPTY_ARRAY)
}

override fun getPlaceholderText(node: ASTNode): String? =

@JojOatXGME JojOatXGME Mar 10, 2025 •

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.

thought: Looks like you could provide the placeholder text and whether the region is collapsed by default to the constructor of FoldingDescriptor. It looks like in this case, getPlaceholderText and isCollapsedByDefault could just throw an UnsupportedOperationException or trigger an assertion.

@JojOatXGME

Copy link
Copy Markdown
Contributor

use customfoldingbuilder maybe?

What is the advantage?

@Silver-Golden

Silver-Golden commented Apr 4, 2026 •

Copy link
Copy Markdown
Member

@0xcaff are ye still working on this?
(came here looking to see if I could fork and add it and this PR popped up)

Edit: just compiled and installed yer changes and holy fuck, that makes such a difference, especially on really long files

@0xcaff

0xcaff commented Apr 6, 2026

Copy link
Copy Markdown
Contributor Author

No have my forked version setup with folding tbh forgot to upstream. Please someone take over

@Silver-Golden

Copy link
Copy Markdown
Member

I might, but I havent worked with kotlin before (or jetbrains plugins)
Best I could do now would be to see about any of the changes @JojOatXGME suggested, but I do lack the base knledge to know why to do the changes :/

@Meallia Meallia mentioned this pull request Apr 21, 2026
@JojOatXGME

Copy link
Copy Markdown
Contributor

I close the PR in favor of #99. Thanks again. Although this PR wasn't merged, I am sure this PR helped to kickstart the work on #99.

@JojOatXGME JojOatXGME closed this Apr 26, 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.

3 participants