Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add folding builder #92

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

add folding builder #92

wants to merge 3 commits into from

Conversation

0xcaff
Copy link
Contributor

@0xcaff 0xcaff commented Mar 9, 2025

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
Copy link
Contributor

@JojOatXGME JojOatXGME left a comment

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
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
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? =
Copy link
Contributor

@JojOatXGME JojOatXGME Mar 10, 2025

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
Contributor

use customfoldingbuilder maybe?

What is the advantage?

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