chore: Cleanup code
This commit is contained in:
parent
9438d8052f
commit
a6e3703616
11 changed files with 55 additions and 54 deletions
|
@ -65,7 +65,9 @@ public class HighlightingUtil {
|
||||||
if (editor.isDisposed()) {
|
if (editor.isDisposed()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (highlightRanges.size() == 1 && highlightRanges.get(0).start() == 0 && highlightRanges.get(0).remove() == -1) {
|
if (highlightRanges.size() == 1 &&
|
||||||
|
highlightRanges.get(0).start() == 0 &&
|
||||||
|
highlightRanges.get(0).remove() == -1) {
|
||||||
markup.removeAllHighlighters();
|
markup.removeAllHighlighters();
|
||||||
}
|
}
|
||||||
var documentLength = editor.getDocument().getTextLength();
|
var documentLength = editor.getDocument().getTextLength();
|
||||||
|
|
|
@ -48,8 +48,8 @@ public class AppSettingsComponent {
|
||||||
.addLabeledComponent(new JBLabel("Asynchronous code folding ranges: "),
|
.addLabeledComponent(new JBLabel("Asynchronous code folding ranges: "),
|
||||||
asyncFoldingCheckBox, 1, false)
|
asyncFoldingCheckBox, 1, false)
|
||||||
.addSeparator()
|
.addSeparator()
|
||||||
.addComponent(new JBLabel("Developer settings" +
|
.addComponent(new JBLabel(
|
||||||
" (only usable when the IDE was launched with " +
|
"Developer settings (only usable when the IDE was launched with " +
|
||||||
"the runIDE gradle task in ZigBrains!)"))
|
"the runIDE gradle task in ZigBrains!)"))
|
||||||
.addVerticalGap(10)
|
.addVerticalGap(10)
|
||||||
.addLabeledComponent(new JBLabel("ZLS debug log: "), debugCheckBox, 1, false)
|
.addLabeledComponent(new JBLabel("ZLS debug log: "), debugCheckBox, 1, false)
|
||||||
|
|
|
@ -20,6 +20,7 @@ import com.intellij.lang.Language;
|
||||||
|
|
||||||
public class ZonLanguage extends Language {
|
public class ZonLanguage extends Language {
|
||||||
public static final ZonLanguage INSTANCE = new ZonLanguage();
|
public static final ZonLanguage INSTANCE = new ZonLanguage();
|
||||||
|
|
||||||
private ZonLanguage() {
|
private ZonLanguage() {
|
||||||
super("Zon");
|
super("Zon");
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ import java.util.Set;
|
||||||
public class ZonCompletionContributor extends CompletionContributor {
|
public class ZonCompletionContributor extends CompletionContributor {
|
||||||
private static final List<String> ZON_ROOT_KEYS = List.of("name", "version", "dependencies");
|
private static final List<String> ZON_ROOT_KEYS = List.of("name", "version", "dependencies");
|
||||||
private static final List<String> ZON_DEP_KEYS = List.of("url", "hash");
|
private static final List<String> ZON_DEP_KEYS = List.of("url", "hash");
|
||||||
|
|
||||||
public ZonCompletionContributor() {
|
public ZonCompletionContributor() {
|
||||||
extend(CompletionType.BASIC,
|
extend(CompletionType.BASIC,
|
||||||
PlatformPatterns.psiElement()
|
PlatformPatterns.psiElement()
|
||||||
|
@ -79,8 +80,9 @@ public class ZonCompletionContributor extends CompletionContributor {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void doAddCompletions(boolean hasDot, Set<String> current, List<String> expected, CompletionResultSet result) {
|
private static void doAddCompletions(boolean hasDot, Set<String> current, List<String> expected, CompletionResultSet result) {
|
||||||
for (var key: expected) {
|
for (var key : expected) {
|
||||||
if (current.contains(key)) {
|
if (current.contains(key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,7 @@ import java.util.List;
|
||||||
public class ZonBlock extends AbstractBlock {
|
public class ZonBlock extends AbstractBlock {
|
||||||
private final SpacingBuilder spacingBuilder;
|
private final SpacingBuilder spacingBuilder;
|
||||||
|
|
||||||
protected ZonBlock(@NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment,
|
protected ZonBlock(@NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment, SpacingBuilder spacingBuilder) {
|
||||||
SpacingBuilder spacingBuilder) {
|
|
||||||
super(node, wrap, alignment);
|
super(node, wrap, alignment);
|
||||||
this.spacingBuilder = spacingBuilder;
|
this.spacingBuilder = spacingBuilder;
|
||||||
}
|
}
|
||||||
|
@ -46,9 +45,8 @@ public class ZonBlock extends AbstractBlock {
|
||||||
var blocks = new ArrayList<Block>();
|
var blocks = new ArrayList<Block>();
|
||||||
var child = myNode.getFirstChildNode();
|
var child = myNode.getFirstChildNode();
|
||||||
while (child != null) {
|
while (child != null) {
|
||||||
if ( child.getElementType() != TokenType.WHITE_SPACE) {
|
if (child.getElementType() != TokenType.WHITE_SPACE) {
|
||||||
var block = new ZonBlock(child, null, null,
|
var block = new ZonBlock(child, null, null, spacingBuilder);
|
||||||
spacingBuilder);
|
|
||||||
blocks.add(block);
|
blocks.add(block);
|
||||||
}
|
}
|
||||||
child = child.getTreeNext();
|
child = child.getTreeNext();
|
||||||
|
@ -66,8 +64,6 @@ public class ZonBlock extends AbstractBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) {
|
public @Nullable Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -29,6 +29,7 @@ public class ZonFormattingModelBuilder implements FormattingModelBuilder {
|
||||||
private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
|
private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
|
||||||
return new SpacingBuilder(settings, ZonLanguage.INSTANCE);
|
return new SpacingBuilder(settings, ZonLanguage.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull FormattingModel createModel(@NotNull FormattingContext formattingContext) {
|
public @NotNull FormattingModel createModel(@NotNull FormattingContext formattingContext) {
|
||||||
final var codeStyleSettings = formattingContext.getCodeStyleSettings();
|
final var codeStyleSettings = formattingContext.getCodeStyleSettings();
|
||||||
|
|
|
@ -22,7 +22,6 @@ import com.intellij.openapi.fileTypes.SyntaxHighlighter;
|
||||||
import com.intellij.openapi.options.colors.AttributesDescriptor;
|
import com.intellij.openapi.options.colors.AttributesDescriptor;
|
||||||
import com.intellij.openapi.options.colors.ColorDescriptor;
|
import com.intellij.openapi.options.colors.ColorDescriptor;
|
||||||
import com.intellij.openapi.options.colors.ColorSettingsPage;
|
import com.intellij.openapi.options.colors.ColorSettingsPage;
|
||||||
import com.intellij.openapi.util.NlsContexts;
|
|
||||||
import org.jetbrains.annotations.NonNls;
|
import org.jetbrains.annotations.NonNls;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
@ -31,16 +30,14 @@ import javax.swing.Icon;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ZonColorSettingsPage implements ColorSettingsPage {
|
public class ZonColorSettingsPage implements ColorSettingsPage {
|
||||||
private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[] {
|
private static final AttributesDescriptor[] DESCRIPTORS =
|
||||||
desc("Equals", ZonSyntaxHighlighter.EQ),
|
new AttributesDescriptor[]{desc("Equals", ZonSyntaxHighlighter.EQ),
|
||||||
desc("Identifier", ZonSyntaxHighlighter.ID),
|
desc("Identifier", ZonSyntaxHighlighter.ID),
|
||||||
desc("Comment", ZonSyntaxHighlighter.COMMENT),
|
desc("Comment", ZonSyntaxHighlighter.COMMENT),
|
||||||
desc("Bad Value", ZonSyntaxHighlighter.BAD_CHAR),
|
desc("Bad Value", ZonSyntaxHighlighter.BAD_CHAR),
|
||||||
desc("String", ZonSyntaxHighlighter.STRING),
|
desc("String", ZonSyntaxHighlighter.STRING),
|
||||||
desc("Comma", ZonSyntaxHighlighter.COMMA),
|
desc("Comma", ZonSyntaxHighlighter.COMMA), desc("Dot", ZonSyntaxHighlighter.DOT),
|
||||||
desc("Dot", ZonSyntaxHighlighter.DOT),
|
desc("Braces", ZonSyntaxHighlighter.BRACE)};
|
||||||
desc("Braces", ZonSyntaxHighlighter.BRACE)
|
|
||||||
};
|
|
||||||
|
|
||||||
private static AttributesDescriptor desc(String name, TextAttributesKey key) {
|
private static AttributesDescriptor desc(String name, TextAttributesKey key) {
|
||||||
return new AttributesDescriptor(name, key);
|
return new AttributesDescriptor(name, key);
|
||||||
|
|
|
@ -31,7 +31,7 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ZonSyntaxHighlighter extends SyntaxHighlighterBase {
|
public class ZonSyntaxHighlighter extends SyntaxHighlighterBase {
|
||||||
// @formatter: off
|
// @formatter:off
|
||||||
public static final TextAttributesKey
|
public static final TextAttributesKey
|
||||||
EQ = createKey("EQ" , DefaultLanguageHighlighterColors.OPERATION_SIGN),
|
EQ = createKey("EQ" , DefaultLanguageHighlighterColors.OPERATION_SIGN),
|
||||||
ID = createKey("ID" , DefaultLanguageHighlighterColors.INSTANCE_FIELD),
|
ID = createKey("ID" , DefaultLanguageHighlighterColors.INSTANCE_FIELD),
|
||||||
|
@ -41,13 +41,13 @@ public class ZonSyntaxHighlighter extends SyntaxHighlighterBase {
|
||||||
COMMA = createKey("COMMA" , DefaultLanguageHighlighterColors.COMMA ),
|
COMMA = createKey("COMMA" , DefaultLanguageHighlighterColors.COMMA ),
|
||||||
DOT = createKey("DOT" , DefaultLanguageHighlighterColors.DOT ),
|
DOT = createKey("DOT" , DefaultLanguageHighlighterColors.DOT ),
|
||||||
BRACE = createKey("BRACE" , DefaultLanguageHighlighterColors.BRACES );
|
BRACE = createKey("BRACE" , DefaultLanguageHighlighterColors.BRACES );
|
||||||
// @formatter: on
|
// @formatter:on
|
||||||
|
|
||||||
private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0];
|
private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0];
|
||||||
private static final Map<IElementType, TextAttributesKey[]> KEYMAP = new HashMap<>();
|
private static final Map<IElementType, TextAttributesKey[]> KEYMAP = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// @formatter: off
|
// @formatter:off
|
||||||
addMapping(DOT , ZonTypes.DOT);
|
addMapping(DOT , ZonTypes.DOT);
|
||||||
addMapping(COMMA , ZonTypes.COMMA);
|
addMapping(COMMA , ZonTypes.COMMA);
|
||||||
addMapping(BRACE , ZonTypes.LBRACE);
|
addMapping(BRACE , ZonTypes.LBRACE);
|
||||||
|
@ -57,11 +57,11 @@ public class ZonSyntaxHighlighter extends SyntaxHighlighterBase {
|
||||||
addMapping(COMMENT , ZonTypes.COMMENT);
|
addMapping(COMMENT , ZonTypes.COMMENT);
|
||||||
addMapping(ID , ZonTypes.ID);
|
addMapping(ID , ZonTypes.ID);
|
||||||
addMapping(EQ , ZonTypes.EQ);
|
addMapping(EQ , ZonTypes.EQ);
|
||||||
// @formatter: on
|
// @formatter:on
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addMapping(TextAttributesKey key, IElementType... types) {
|
private static void addMapping(TextAttributesKey key, IElementType... types) {
|
||||||
for (var type: types) {
|
for (var type : types) {
|
||||||
KEYMAP.put(type, new TextAttributesKey[]{key});
|
KEYMAP.put(type, new TextAttributesKey[]{key});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
public class ZonBraceMatcher implements PairedBraceMatcher {
|
public class ZonBraceMatcher implements PairedBraceMatcher {
|
||||||
public static final BracePair PAIR = new BracePair(ZonTypes.LBRACE, ZonTypes.RBRACE, true);
|
public static final BracePair PAIR = new BracePair(ZonTypes.LBRACE, ZonTypes.RBRACE, true);
|
||||||
private static final BracePair[] PAIRS = new BracePair[]{PAIR};
|
private static final BracePair[] PAIRS = new BracePair[]{PAIR};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BracePair @NotNull [] getPairs() {
|
public BracePair @NotNull [] getPairs() {
|
||||||
return PAIRS;
|
return PAIRS;
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ZonParserDefinition implements ParserDefinition {
|
public class ZonParserDefinition implements ParserDefinition {
|
||||||
public static final IFileElementType FILE = new IFileElementType(ZonLanguage.INSTANCE);
|
public static final IFileElementType FILE = new IFileElementType(ZonLanguage.INSTANCE);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Lexer createLexer(Project project) {
|
public @NotNull Lexer createLexer(Project project) {
|
||||||
return new ZonLexerAdapter();
|
return new ZonLexerAdapter();
|
||||||
|
|
|
@ -26,7 +26,7 @@ import java.util.Set;
|
||||||
public class ZonPsiImplUtil {
|
public class ZonPsiImplUtil {
|
||||||
public static Set<String> getKeys(ZonStruct struct) {
|
public static Set<String> getKeys(ZonStruct struct) {
|
||||||
var result = new HashSet<String>();
|
var result = new HashSet<String>();
|
||||||
for (var property: struct.getPropertyList()) {
|
for (var property : struct.getPropertyList()) {
|
||||||
result.add(getText(property.getIdentifier()));
|
result.add(getText(property.getIdentifier()));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Add table
Reference in a new issue