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,9 +48,9 @@ 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)
|
||||||
.addLabeledComponent(new JBLabel("ZLS message trace: "), messageTraceCheckBox, 1,
|
.addLabeledComponent(new JBLabel("ZLS message trace: "), messageTraceCheckBox, 1,
|
||||||
|
|
|
@ -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,16 +38,17 @@ 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()
|
||||||
.withParent(PlatformPatterns.psiElement(ZonTypes.PROPERTY_PLACEHOLDER))
|
.withParent(PlatformPatterns.psiElement(ZonTypes.PROPERTY_PLACEHOLDER))
|
||||||
.withSuperParent(3, PlatformPatterns.psiElement(ZonFile.class)),
|
.withSuperParent(3, PlatformPatterns.psiElement(ZonFile.class)),
|
||||||
new CompletionProvider<>() {
|
new CompletionProvider<>() {
|
||||||
@Override
|
@Override
|
||||||
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) {
|
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) {
|
||||||
var placeholder = ZonPsiImplUtil.parent(parameters.getPosition(), ZonPropertyPlaceholder.class);
|
var placeholder = ZonPsiImplUtil.parent(parameters.getPosition(), ZonPropertyPlaceholder.class);
|
||||||
assert placeholder != null;
|
assert placeholder != null;
|
||||||
|
|
||||||
var zonStruct = ZonPsiImplUtil.parent(placeholder, ZonStruct.class);
|
var zonStruct = ZonPsiImplUtil.parent(placeholder, ZonStruct.class);
|
||||||
assert zonStruct != null;
|
assert zonStruct != null;
|
||||||
|
@ -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);
|
||||||
|
@ -59,27 +56,27 @@ public class ZonColorSettingsPage implements ColorSettingsPage {
|
||||||
@Override
|
@Override
|
||||||
public @NonNls @NotNull String getDemoText() {
|
public @NonNls @NotNull String getDemoText() {
|
||||||
return """
|
return """
|
||||||
.{
|
.{
|
||||||
//This is an example file with some random data
|
//This is an example file with some random data
|
||||||
.name = "zls",
|
.name = "zls",
|
||||||
.version = "0.11.0",
|
.version = "0.11.0",
|
||||||
|
|
||||||
.dependencies = .{
|
.dependencies = .{
|
||||||
.known_folders = .{
|
.known_folders = .{
|
||||||
.url = "https://github.com/ziglibs/known-folders/archive/fa75e1bc672952efa0cf06160bbd942b47f6d59b.tar.gz",
|
.url = "https://github.com/ziglibs/known-folders/archive/fa75e1bc672952efa0cf06160bbd942b47f6d59b.tar.gz",
|
||||||
.hash = "122048992ca58a78318b6eba4f65c692564be5af3b30fbef50cd4abeda981b2e7fa5",
|
.hash = "122048992ca58a78318b6eba4f65c692564be5af3b30fbef50cd4abeda981b2e7fa5",
|
||||||
},
|
},
|
||||||
.diffz = .{
|
.diffz = .{
|
||||||
.url = "https://github.com/ziglibs/diffz/archive/90353d401c59e2ca5ed0abe5444c29ad3d7489aa.tar.gz",
|
.url = "https://github.com/ziglibs/diffz/archive/90353d401c59e2ca5ed0abe5444c29ad3d7489aa.tar.gz",
|
||||||
.hash = "122089a8247a693cad53beb161bde6c30f71376cd4298798d45b32740c3581405864",
|
.hash = "122089a8247a693cad53beb161bde6c30f71376cd4298798d45b32740c3581405864",
|
||||||
},
|
},
|
||||||
.binned_allocator = .{
|
.binned_allocator = .{
|
||||||
.url = "https://gist.github.com/antlilja/8372900fcc09e38d7b0b6bbaddad3904/archive/6c3321e0969ff2463f8335da5601986cf2108690.tar.gz",
|
.url = "https://gist.github.com/antlilja/8372900fcc09e38d7b0b6bbaddad3904/archive/6c3321e0969ff2463f8335da5601986cf2108690.tar.gz",
|
||||||
.hash = "1220363c7e27b2d3f39de6ff6e90f9537a0634199860fea237a55ddb1e1717f5d6a5",
|
.hash = "1220363c7e27b2d3f39de6ff6e90f9537a0634199860fea237a55ddb1e1717f5d6a5",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
""";
|
""";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -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