Brace style, Auto-formatting, Code hinting

Answered

Hey there. I'm having a stab at implementing my own custom language plug-in.  It's going pretty well, although I'm finding the documentation to be severely lacking.

In particular I am having trouble figuring out the following..

1. How do I implement the "brace style" formatting option? (End of line, Next line, etc)

2. How do I auto-format a block when the user types the closing-brace like other languages do?

3. How do I implement these tooltip code-hints? https://gyazo.com/792e6ab76e4f766febc309098d3557e0

I have many more questions but currently these are the most pressing.

I'd appreciate any help anyone might be able to offer. Thanks in advance!

 

4 comments
Comment actions Permalink

Thomas, thanks for reaching out with your questions!

Brace style formatting uses the BraceStyleAccessor, BraceStyle, and AbstractJavaBlock. This is a Java-specific solution, but you can verify the sources to get an insight into how it's handled.

Auto-formatting the block of code after typing the closing brace happens automatically for all languages based on the "IDE Settings -> Editor -> Smart Keys -> Reformat block on typing '}'" option, and general language's code styles are applied.

Code hints can be handled with the documentation provider.

0
Comment actions Permalink

Thanks, but auto-formatting is not happening when I type "}" despite the option being enabled.

Do i need to implement "folding" support for this to work?

0
Comment actions Permalink

I've implemented code folding and the "}" thing is still not working.

The documentation provider works for hover tooltips, but it doesn't offer help as you type.

I think what I need is a CompletionContributor, but I don't know how to add function parameter information and have it switch between parameters as you type.

0
Comment actions Permalink

I managed to solve the auto-formatting on close brace issue

I needed to implement `PairedBraceMatcher`

package org.intellij.sdk.language;

import com.intellij.lang.BracePair;
import com.intellij.lang.PairedBraceMatcher;
import com.intellij.psi.PsiFile;
import com.intellij.psi.tree.IElementType;
import org.intellij.sdk.language.psi.MyTypes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class MyPairedBraceMatcher implements PairedBraceMatcher
{
private static final BracePair[] PAIRS = new BracePair[]{
new BracePair(MyTypes.BRACES_START, MyTypes.BRACES_END, true),
};


@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)
{
return openingBraceOffset;
}
}

Then add it to the plugin.xml:

<lang.braceMatcher language="LSL" implementationClass="org.intellij.sdk.language.MyPairedBraceMatcher"/>
0

Please sign in to leave a comment.