feat(zig): Brace matching
This commit is contained in:
parent
e82ac50830
commit
fe94d3cec4
4 changed files with 44 additions and 0 deletions
|
@ -28,6 +28,7 @@ Changelog structure reference:
|
||||||
- Go to usages now works properly
|
- Go to usages now works properly
|
||||||
- Color scheme preview now works properly
|
- Color scheme preview now works properly
|
||||||
- Better "smart" syntax highlighting when LSP is connected
|
- Better "smart" syntax highlighting when LSP is connected
|
||||||
|
- Brace/Parenthesis/Bracket matching
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ Go to `Settings` -> `Languages & Frameworks` -> `Zig` -> `ZLS path` -> select yo
|
||||||
- Rename symbol
|
- Rename symbol
|
||||||
- Hover documentation
|
- Hover documentation
|
||||||
- Go to implementations / find usages
|
- Go to implementations / find usages
|
||||||
|
- Brace/Parenthesis/Bracket matching
|
||||||
- TODO:
|
- TODO:
|
||||||
- Workspace Symbols
|
- Workspace Symbols
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.falsepattern.zigbrains.zig.pairing;
|
||||||
|
|
||||||
|
import com.falsepattern.zigbrains.zig.psi.ZigTypes;
|
||||||
|
import com.falsepattern.zigbrains.zon.psi.ZonTypes;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class ZigBraceMatcher implements PairedBraceMatcher {
|
||||||
|
public static final BracePair BRACE_PAIR = new BracePair(ZigTypes.LBRACE, ZigTypes.RBRACE, true);
|
||||||
|
public static final BracePair PAREN_PAIR = new BracePair(ZigTypes.LPAREN, ZigTypes.RPAREN, false);
|
||||||
|
public static final BracePair BRACKET_PAIR = new BracePair(ZigTypes.LBRACKET, ZigTypes.RBRACKET, false);
|
||||||
|
private static final BracePair[] PAIRS = new BracePair[]{BRACE_PAIR, PAREN_PAIR, BRACKET_PAIR};
|
||||||
|
@Override
|
||||||
|
public BracePair @NotNull [] getPairs() {
|
||||||
|
return PAIRS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType lbraceType, @Nullable IElementType contextType) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCodeConstructStart(PsiFile file, int openingBraceOffset) {
|
||||||
|
var theBrace = file.findElementAt(openingBraceOffset);
|
||||||
|
if (theBrace == null) {
|
||||||
|
return openingBraceOffset;
|
||||||
|
}
|
||||||
|
var parent = theBrace.getParent();
|
||||||
|
if (parent == null) {
|
||||||
|
return openingBraceOffset;
|
||||||
|
}
|
||||||
|
return parent.getTextOffset();
|
||||||
|
}
|
||||||
|
}
|
|
@ -74,6 +74,9 @@
|
||||||
<lang.syntaxHighlighterFactory language="Zig"
|
<lang.syntaxHighlighterFactory language="Zig"
|
||||||
implementationClass="com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighterFactory"/>
|
implementationClass="com.falsepattern.zigbrains.zig.highlighter.ZigSyntaxHighlighterFactory"/>
|
||||||
|
|
||||||
|
<lang.braceMatcher language="Zig"
|
||||||
|
implementationClass="com.falsepattern.zigbrains.zig.pairing.ZigBraceMatcher"/>
|
||||||
|
|
||||||
<applicationConfigurable parentId="language"
|
<applicationConfigurable parentId="language"
|
||||||
instance="com.falsepattern.zigbrains.zig.settings.AppSettingsConfigurable"
|
instance="com.falsepattern.zigbrains.zig.settings.AppSettingsConfigurable"
|
||||||
id="com.falsepattern.zigbrains.zig.settings.AppSettingsConfigurable"
|
id="com.falsepattern.zigbrains.zig.settings.AppSettingsConfigurable"
|
||||||
|
|
Loading…
Add table
Reference in a new issue