Skip to content

Commit 93549b8

Browse files
feat(editor): implement brace handling (#69)
Signed-off-by: Luke Gareth Ribchester <luke@luke.gr>
1 parent e14be77 commit 93549b8

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- Enhanced parenthesis, brace, and bracket handling
10+
711
## [0.3.1] - 2024-05-04
812

913
### Added

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pluginGroup = io.kadena.pact
44
pluginName = Pact
55
pluginRepositoryUrl = https://github.com/lukeribchester/pact-intellij
66
# SemVer format -> https://semver.org
7-
pluginVersion = 0.3.1
7+
pluginVersion = 0.3.2
88

99
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
1010
pluginSinceBuild = 232
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.kadena.pact.ide.editor
2+
3+
import com.intellij.lang.BracePair
4+
import com.intellij.lang.PairedBraceMatcher
5+
import com.intellij.psi.PsiFile
6+
import com.intellij.psi.tree.IElementType
7+
import io.kadena.pact.language.psi.PactTokenSets
8+
import io.kadena.pact.language.psi.PactTypes
9+
import org.jetbrains.annotations.NotNull
10+
11+
12+
private val BRACE_PAIRS = arrayOf(
13+
BracePair(PactTypes.PAREN_OPEN, PactTypes.PAREN_CLOSE, true),
14+
BracePair(PactTypes.BRACE_OPEN, PactTypes.BRACE_CLOSE, false),
15+
BracePair(PactTypes.BRACKET_OPEN, PactTypes.BRACKET_CLOSE, false)
16+
)
17+
18+
class PactBraceMatcher : PairedBraceMatcher {
19+
@NotNull
20+
override fun getPairs(): Array<BracePair> {
21+
return BRACE_PAIRS
22+
}
23+
24+
override fun isPairedBracesAllowedBeforeType(lbraceType: IElementType, contextType: IElementType?): Boolean {
25+
return contextType == null || !PactTokenSets.STRINGS.contains(contextType)
26+
}
27+
28+
override fun getCodeConstructStart(file: PsiFile?, openingBraceOffset: Int): Int {
29+
return openingBraceOffset
30+
}
31+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
<platform.lsp.serverSupportProvider
4545
implementation="io.kadena.pact.lsp.PactLspServerSupportProvider"/>
4646

47+
<!-- Brace Matcher -->
48+
<lang.braceMatcher
49+
language="Pact"
50+
implementationClass="io.kadena.pact.ide.editor.PactBraceMatcher"/>
51+
4752
<!-- Quote Handler -->
4853
<lang.quoteHandler
4954
language="Pact"

0 commit comments

Comments
 (0)