Skip to content

Commit

Permalink
feat(editor): implement brace handling (#69)
Browse files Browse the repository at this point in the history
Signed-off-by: Luke Gareth Ribchester <luke@luke.gr>
  • Loading branch information
lukeribchester authored May 6, 2024
1 parent e14be77 commit 93549b8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## [Unreleased]

### Added

- Enhanced parenthesis, brace, and bracket handling

## [0.3.1] - 2024-05-04

### Added
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginGroup = io.kadena.pact
pluginName = Pact
pluginRepositoryUrl = https://github.com/lukeribchester/pact-intellij
# SemVer format -> https://semver.org
pluginVersion = 0.3.1
pluginVersion = 0.3.2

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 232
Expand Down
31 changes: 31 additions & 0 deletions src/main/kotlin/io/kadena/pact/ide/editor/PactBraceMatcher.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.kadena.pact.ide.editor

import com.intellij.lang.BracePair
import com.intellij.lang.PairedBraceMatcher
import com.intellij.psi.PsiFile
import com.intellij.psi.tree.IElementType
import io.kadena.pact.language.psi.PactTokenSets
import io.kadena.pact.language.psi.PactTypes
import org.jetbrains.annotations.NotNull


private val BRACE_PAIRS = arrayOf(
BracePair(PactTypes.PAREN_OPEN, PactTypes.PAREN_CLOSE, true),
BracePair(PactTypes.BRACE_OPEN, PactTypes.BRACE_CLOSE, false),
BracePair(PactTypes.BRACKET_OPEN, PactTypes.BRACKET_CLOSE, false)
)

class PactBraceMatcher : PairedBraceMatcher {
@NotNull
override fun getPairs(): Array<BracePair> {
return BRACE_PAIRS
}

override fun isPairedBracesAllowedBeforeType(lbraceType: IElementType, contextType: IElementType?): Boolean {
return contextType == null || !PactTokenSets.STRINGS.contains(contextType)
}

override fun getCodeConstructStart(file: PsiFile?, openingBraceOffset: Int): Int {
return openingBraceOffset
}
}
5 changes: 5 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<platform.lsp.serverSupportProvider
implementation="io.kadena.pact.lsp.PactLspServerSupportProvider"/>

<!-- Brace Matcher -->
<lang.braceMatcher
language="Pact"
implementationClass="io.kadena.pact.ide.editor.PactBraceMatcher"/>

<!-- Quote Handler -->
<lang.quoteHandler
language="Pact"
Expand Down

0 comments on commit 93549b8

Please sign in to comment.