Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
117 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
src/main/gen/com/justint/usdidea/lang/psi/impl/usdPrimSpecImpl.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
src/main/java/com/justint/usdidea/codeinsight/folding/USDFoldingBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.justint.usdidea.codeinsight.folding; | ||
|
||
import com.intellij.lang.ASTNode; | ||
import com.intellij.lang.folding.FoldingBuilder; | ||
import com.intellij.lang.folding.FoldingDescriptor; | ||
import com.intellij.lang.folding.NamedFoldingDescriptor; | ||
import com.intellij.openapi.editor.Document; | ||
import com.intellij.psi.tree.IElementType; | ||
import com.justint.usdidea.lang.psi.USDTypes; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class USDFoldingBuilder implements FoldingBuilder { | ||
|
||
private static final IElementType[] BRACKET_TYPES = new IElementType[] { | ||
USDTypes.BODY, | ||
USDTypes.DICT, | ||
USDTypes.TIME_SAMPLE | ||
}; | ||
|
||
@NotNull | ||
@Override | ||
public FoldingDescriptor[] buildFoldRegions(@NotNull ASTNode astNode, @NotNull Document document) { | ||
List<FoldingDescriptor> descriptors = new ArrayList<>(); | ||
collectRegionsRecursively(astNode, document, descriptors); | ||
return descriptors.toArray(FoldingDescriptor.EMPTY); | ||
} | ||
|
||
private void collectRegionsRecursively(@NotNull final ASTNode astNode, | ||
@NotNull final Document document, | ||
@NotNull List<FoldingDescriptor> descriptors) { | ||
final IElementType elementType = astNode.getElementType(); | ||
|
||
if (elementType == USDTypes.METADATA) { | ||
descriptors.add(new NamedFoldingDescriptor( | ||
astNode, | ||
astNode.getTextRange(), | ||
null, | ||
"(...)" | ||
)); | ||
} else if (Arrays.asList(BRACKET_TYPES).contains(elementType)) { | ||
descriptors.add(new NamedFoldingDescriptor( | ||
astNode, | ||
astNode.getTextRange(), | ||
null, | ||
"{...}")); | ||
} | ||
|
||
for (ASTNode child : astNode.getChildren(null)) { | ||
collectRegionsRecursively(child, document, descriptors); | ||
} | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getPlaceholderText(@NotNull ASTNode astNode) { | ||
return "..."; | ||
} | ||
|
||
@Override | ||
public boolean isCollapsedByDefault(@NotNull ASTNode astNode) { | ||
return false; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/justint/usdidea/codeinsight/highlighting/USDBraceMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.justint.usdidea.codeinsight.highlighting; | ||
|
||
import com.intellij.lang.BracePair; | ||
import com.intellij.lang.PairedBraceMatcher; | ||
import com.intellij.psi.PsiFile; | ||
import com.intellij.psi.tree.IElementType; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import static com.justint.usdidea.lang.psi.USDTypes.*; | ||
|
||
public class USDBraceMatcher implements PairedBraceMatcher { | ||
|
||
private static final BracePair[] PAIRS = new BracePair[] { | ||
new BracePair(LEFTBRACE, RIGHTBRACE, true), | ||
new BracePair(LEFTPARENS, RIGHTPARENS, true), | ||
new BracePair(LEFTBRACKET, RIGHTBRACKET, false) | ||
}; | ||
|
||
@NotNull | ||
@Override | ||
public BracePair[] getPairs() { | ||
return PAIRS; | ||
} | ||
|
||
@Override | ||
public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType lBraceType, @Nullable IElementType contextType) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public int getCodeConstructStart(PsiFile file, int openingBraceOffset) { | ||
return openingBraceOffset; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters