Skip to content

Commit f20d836

Browse files
committed
Fix #18. bracket matching
1 parent 3136981 commit f20d836

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* This file is a part of IntelliJ Language 1C (BSL) Plugin.
3+
*
4+
* Copyright © 2018
5+
* Alexey Sosnoviy <labotamy@yandex.ru>, Nikita Gryzlov <nixel2007@gmail.com>
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* IntelliJ Language 1C (BSL) Plugin is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* IntelliJ Language 1C (BSL) Plugin is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with IntelliJ Language 1C (BSL) Plugin.
21+
*/
22+
package org.github._1c_syntax.intellij.bsl;
23+
24+
import com.intellij.lang.BracePair;
25+
import com.intellij.lang.PairedBraceMatcher;
26+
import com.intellij.psi.PsiFile;
27+
import com.intellij.psi.tree.IElementType;
28+
import org.antlr.jetbrains.adapter.lexer.PsiElementTypeFactory;
29+
import org.antlr.jetbrains.adapter.lexer.TokenIElementType;
30+
import org.github._1c_syntax.parser.BSLLexer;
31+
import org.jetbrains.annotations.NotNull;
32+
import org.jetbrains.annotations.Nullable;
33+
34+
import java.util.List;
35+
36+
public class BSLPairedBraceMatcher implements PairedBraceMatcher {
37+
38+
@NotNull
39+
@Override
40+
public BracePair[] getPairs() {
41+
PsiElementTypeFactory psiElementTypeFactory = BSLSyntaxHighlighter.getPsiElementTypeFactory();
42+
List<TokenIElementType> tokenIElementTypes = psiElementTypeFactory.getTokenIElementTypes();
43+
44+
TokenIElementType lParen = tokenIElementTypes.get(BSLLexer.LPAREN);
45+
TokenIElementType rParen = tokenIElementTypes.get(BSLLexer.RPAREN);
46+
47+
TokenIElementType lBracket = tokenIElementTypes.get(BSLLexer.LBRACK);
48+
TokenIElementType rBracket = tokenIElementTypes.get(BSLLexer.RBRACK);
49+
50+
return new BracePair[]{
51+
new BracePair(lParen, rParen, true),
52+
new BracePair(lBracket, rBracket, false),
53+
};
54+
}
55+
56+
@Override
57+
public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType lbraceType, @Nullable IElementType contextType) {
58+
return false;
59+
}
60+
61+
@Override
62+
public int getCodeConstructStart(PsiFile file, int openingBraceOffset) {
63+
return 0;
64+
}
65+
}

intellij-bsl/src/main/java/org/github/_1c_syntax/intellij/bsl/BSLSyntaxHighlighter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,9 @@ public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
208208
// return BAD_CHAR_KEYS;
209209
// }
210210
}
211+
212+
public static PsiElementTypeFactory getPsiElementTypeFactory() {
213+
return psiElementTypeFactory;
214+
}
215+
211216
}

intellij-bsl/src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<lang.parserDefinition language="BSL" implementationClass="org.github._1c_syntax.intellij.bsl.BSLParserDefinition"/>
5353
<lang.syntaxHighlighterFactory language="BSL" implementationClass="org.github._1c_syntax.intellij.bsl.BSLSyntaxHighlighterFactory"/>
5454
<lang.commenter language="BSL" implementationClass="org.github._1c_syntax.intellij.bsl.BSLCommenter"/>
55+
<lang.braceMatcher language="BSL" implementationClass="org.github._1c_syntax.intellij.bsl.BSLPairedBraceMatcher"/>
5556
<applicationConfigurable groupId="language" displayName="1C (BSL)" id="BSLConfigurable" instance="org.github._1c_syntax.intellij.bsl.settings.BSLConfigurable"/>
5657
<applicationService serviceImplementation="org.github._1c_syntax.intellij.bsl.settings.LanguageServerSettingsState"/>
5758
</extensions>

0 commit comments

Comments
 (0)