Auto insert of matching braces?
Is there a secret to auto insertion of matching braces?
I have implemented a `PairedBraceMatcher` (see below) which enabled matching **and** automatic insertion for `RBRACE` "}", RPAREN` ")" and `RBRACK` "]" but for the `begin`/`end` combo I am only getting matching and not auto-insert. What am I missing
The brace matcher correctly highlights the begin/end but doesn't auto insert the `end` keyword (which is what I want).
What am I missing?
Here's my code:
```
class MyBraceMatcher : PairedBraceMatcher {
override fun getPairs() = PAIRS
override fun isPairedBracesAllowedBeforeType(lbraceType: IElementType, next: IElementType?): Boolean = true
override fun getCodeConstructStart(file: PsiFile?, openingBraceOffset: Int): Int = openingBraceOffset
companion object {
private val PAIRS: Array<BracePair> = arrayOf(
BracePair(KEYWORD_BEGIN, KEYWORD_END, true),
BracePair(LBRACE, RBRACE, true),
BracePair(LPAREN, RPAREN, false),
BracePair(LBRACK, RBRACK, false)
)
}
}
```
请先登录再写评论。
I should clarify that :
KEYWORD_BEGIN = "begin"
KEYWORD_END = "end"
But I don't think it has to do with multi-character tokens?
PairedBraceMatcher only works to insert a hard-coded set of potential braces if you debug the code that calls them. Elixir doesn't have `begin` `end`, but it does have `do` `end` pair. To get `end` to insert when you type `do` in https://github.com/KronicDeth/intellij-elixir/pull/371, I declared a `TypedHandlerDelegate` (https://github.com/KronicDeth/intellij-elixir/blob/633601339f56e60c70a7a0c09383e90a309dfeab/src/META-INF/plugin.xml#L1443) that checked when I was typing the `do` token and inserted the `end` (https://github.com/KronicDeth/intellij-elixir/blob/633601339f56e60c70a7a0c09383e90a309dfeab/src/org/elixir_lang/TypedHandler.java#L54-L56). There is a slight bug in that PR in that didn't handle `do` could be used a as keyword key like `do:`, which is fixed by https://github.com/KronicDeth/intellij-elixir/pull/381
**Thank you**
I noticed PairedBraceMatcher seemed hard-coded for potential braces.To bad!
I assumed that it would grab the text from the right pair and use that for insertion. Instead it auto-insert for some hard coded list of "common" items. This bug/feature can also be seen by changing the right-hand token (i.e try to match ( with }). The editor still auto-inserts ')'. Seems clumsy! A simple option would be to take text from right-hand token and use that or have the option to specify what text you want to auto insert
The good thing is that your code seems straight forward, so I will go ahead and implement something like that in my code. Thank you!