feat(zon): Code folding

This commit is contained in:
FalsePattern 2023-08-10 15:58:40 +02:00 committed by FalsePattern
parent 85bcbc62cf
commit 8dd298554e
Signed by: falsepattern
GPG key ID: FDF7126A9E124447
3 changed files with 64 additions and 0 deletions

View file

@ -26,6 +26,7 @@ Changelog structure reference:
- Color settings page - Color settings page
- Brace and quote matching - Brace and quote matching
- Code completion - Code completion
- Code Folding
- Indentation - Indentation
## [0.4.0] ## [0.4.0]

View file

@ -0,0 +1,59 @@
/*
* Copyright 2023 FalsePattern
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.falsepattern.zigbrains.zon.folding;
import com.falsepattern.zigbrains.zon.psi.ZonStruct;
import com.falsepattern.zigbrains.zon.psi.ZonVisitor;
import com.intellij.lang.ASTNode;
import com.intellij.lang.folding.CustomFoldingBuilder;
import com.intellij.lang.folding.FoldingDescriptor;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class ZonFoldingBuilder extends CustomFoldingBuilder implements DumbAware {
@Override
protected void buildLanguageFoldRegions(@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiElement root, @NotNull Document document, boolean quick) {
root.accept(new ZonVisitor() {
@Override
public void visitElement(@NotNull PsiElement element) {
super.visitElement(element);
element.acceptChildren(this);
}
@Override
public void visitStruct(@NotNull ZonStruct o) {
super.visitStruct(o);
descriptors.add(new FoldingDescriptor(o, o.getTextRange()));
}
});
}
@Override
protected String getLanguagePlaceholderText(@NotNull ASTNode node, @NotNull TextRange range) {
return ".{...}";
}
@Override
protected boolean isRegionCollapsedByDefault(@NotNull ASTNode node) {
return false;
}
}

View file

@ -105,6 +105,10 @@
<lang.quoteHandler language="Zon" <lang.quoteHandler language="Zon"
implementationClass="com.falsepattern.zigbrains.zon.braces.ZonQuoteHandler"/> implementationClass="com.falsepattern.zigbrains.zon.braces.ZonQuoteHandler"/>
<lang.foldingBuilder language="Zon"
implementationClass="com.falsepattern.zigbrains.zon.folding.ZonFoldingBuilder"/>
<!-- endregion Zon --> <!-- endregion Zon -->
</extensions> </extensions>