feat(zon): Brace matching
This commit is contained in:
parent
828bd1304c
commit
211f2c8065
3 changed files with 55 additions and 0 deletions
|
@ -24,6 +24,7 @@ Changelog structure reference:
|
||||||
- Basic parser and PSI tree
|
- Basic parser and PSI tree
|
||||||
- Basic syntax highlighting
|
- Basic syntax highlighting
|
||||||
- Color settings page
|
- Color settings page
|
||||||
|
- Brace matching
|
||||||
|
|
||||||
## [0.4.0]
|
## [0.4.0]
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* 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.braces;
|
||||||
|
|
||||||
|
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 ZonBraceMatcher implements PairedBraceMatcher {
|
||||||
|
public static final BracePair PAIR = new BracePair(ZonTypes.LBRACE, ZonTypes.RBRACE, true);
|
||||||
|
private static final BracePair[] PAIRS = new BracePair[]{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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -94,6 +94,8 @@
|
||||||
|
|
||||||
<colorSettingsPage implementation="com.falsepattern.zigbrains.zon.highlight.ZonColorSettingsPage"/>
|
<colorSettingsPage implementation="com.falsepattern.zigbrains.zon.highlight.ZonColorSettingsPage"/>
|
||||||
|
|
||||||
|
<lang.braceMatcher language="Zon"
|
||||||
|
implementationClass="com.falsepattern.zigbrains.zon.braces.ZonBraceMatcher"/>
|
||||||
<!-- endregion Zon -->
|
<!-- endregion Zon -->
|
||||||
|
|
||||||
</extensions>
|
</extensions>
|
||||||
|
|
Loading…
Add table
Reference in a new issue