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()) {
|
||||
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();
|
||||
}
|
||||
var documentLength = editor.getDocument().getTextLength();
|
||||
|
|
|
@ -48,9 +48,9 @@ public class AppSettingsComponent {
|
|||
.addLabeledComponent(new JBLabel("Asynchronous code folding ranges: "),
|
||||
asyncFoldingCheckBox, 1, false)
|
||||
.addSeparator()
|
||||
.addComponent(new JBLabel("Developer settings" +
|
||||
" (only usable when the IDE was launched with " +
|
||||
"the runIDE gradle task in ZigBrains!)"))
|
||||
.addComponent(new JBLabel(
|
||||
"Developer settings (only usable when the IDE was launched with " +
|
||||
"the runIDE gradle task in ZigBrains!)"))
|
||||
.addVerticalGap(10)
|
||||
.addLabeledComponent(new JBLabel("ZLS debug log: "), debugCheckBox, 1, false)
|
||||
.addLabeledComponent(new JBLabel("ZLS message trace: "), messageTraceCheckBox, 1,
|
||||
|
|
|
@ -20,6 +20,7 @@ import com.intellij.lang.Language;
|
|||
|
||||
public class ZonLanguage extends Language {
|
||||
public static final ZonLanguage INSTANCE = new ZonLanguage();
|
||||
|
||||
private ZonLanguage() {
|
||||
super("Zon");
|
||||
}
|
||||
|
|
|
@ -38,16 +38,17 @@ import java.util.Set;
|
|||
public class ZonCompletionContributor extends CompletionContributor {
|
||||
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");
|
||||
|
||||
public ZonCompletionContributor() {
|
||||
extend(CompletionType.BASIC,
|
||||
PlatformPatterns.psiElement()
|
||||
.withParent(PlatformPatterns.psiElement(ZonTypes.PROPERTY_PLACEHOLDER))
|
||||
.withSuperParent(3, PlatformPatterns.psiElement(ZonFile.class)),
|
||||
new CompletionProvider<>() {
|
||||
@Override
|
||||
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) {
|
||||
var placeholder = ZonPsiImplUtil.parent(parameters.getPosition(), ZonPropertyPlaceholder.class);
|
||||
assert placeholder != null;
|
||||
@Override
|
||||
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) {
|
||||
var placeholder = ZonPsiImplUtil.parent(parameters.getPosition(), ZonPropertyPlaceholder.class);
|
||||
assert placeholder != null;
|
||||
|
||||
var zonStruct = ZonPsiImplUtil.parent(placeholder, ZonStruct.class);
|
||||
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) {
|
||||
for (var key: expected) {
|
||||
for (var key : expected) {
|
||||
if (current.contains(key)) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -35,8 +35,7 @@ import java.util.List;
|
|||
public class ZonBlock extends AbstractBlock {
|
||||
private final SpacingBuilder spacingBuilder;
|
||||
|
||||
protected ZonBlock(@NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment,
|
||||
SpacingBuilder spacingBuilder) {
|
||||
protected ZonBlock(@NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment, SpacingBuilder spacingBuilder) {
|
||||
super(node, wrap, alignment);
|
||||
this.spacingBuilder = spacingBuilder;
|
||||
}
|
||||
|
@ -46,9 +45,8 @@ public class ZonBlock extends AbstractBlock {
|
|||
var blocks = new ArrayList<Block>();
|
||||
var child = myNode.getFirstChildNode();
|
||||
while (child != null) {
|
||||
if ( child.getElementType() != TokenType.WHITE_SPACE) {
|
||||
var block = new ZonBlock(child, null, null,
|
||||
spacingBuilder);
|
||||
if (child.getElementType() != TokenType.WHITE_SPACE) {
|
||||
var block = new ZonBlock(child, null, null, spacingBuilder);
|
||||
blocks.add(block);
|
||||
}
|
||||
child = child.getTreeNext();
|
||||
|
@ -66,8 +64,6 @@ public class ZonBlock extends AbstractBlock {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public @Nullable Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) {
|
||||
return null;
|
||||
|
|
|
@ -29,6 +29,7 @@ public class ZonFormattingModelBuilder implements FormattingModelBuilder {
|
|||
private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
|
||||
return new SpacingBuilder(settings, ZonLanguage.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull FormattingModel createModel(@NotNull FormattingContext formattingContext) {
|
||||
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.ColorDescriptor;
|
||||
import com.intellij.openapi.options.colors.ColorSettingsPage;
|
||||
import com.intellij.openapi.util.NlsContexts;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -31,16 +30,14 @@ import javax.swing.Icon;
|
|||
import java.util.Map;
|
||||
|
||||
public class ZonColorSettingsPage implements ColorSettingsPage {
|
||||
private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[] {
|
||||
desc("Equals", ZonSyntaxHighlighter.EQ),
|
||||
desc("Identifier", ZonSyntaxHighlighter.ID),
|
||||
desc("Comment", ZonSyntaxHighlighter.COMMENT),
|
||||
desc("Bad Value", ZonSyntaxHighlighter.BAD_CHAR),
|
||||
desc("String", ZonSyntaxHighlighter.STRING),
|
||||
desc("Comma", ZonSyntaxHighlighter.COMMA),
|
||||
desc("Dot", ZonSyntaxHighlighter.DOT),
|
||||
desc("Braces", ZonSyntaxHighlighter.BRACE)
|
||||
};
|
||||
private static final AttributesDescriptor[] DESCRIPTORS =
|
||||
new AttributesDescriptor[]{desc("Equals", ZonSyntaxHighlighter.EQ),
|
||||
desc("Identifier", ZonSyntaxHighlighter.ID),
|
||||
desc("Comment", ZonSyntaxHighlighter.COMMENT),
|
||||
desc("Bad Value", ZonSyntaxHighlighter.BAD_CHAR),
|
||||
desc("String", ZonSyntaxHighlighter.STRING),
|
||||
desc("Comma", ZonSyntaxHighlighter.COMMA), desc("Dot", ZonSyntaxHighlighter.DOT),
|
||||
desc("Braces", ZonSyntaxHighlighter.BRACE)};
|
||||
|
||||
private static AttributesDescriptor desc(String name, TextAttributesKey key) {
|
||||
return new AttributesDescriptor(name, key);
|
||||
|
@ -59,27 +56,27 @@ public class ZonColorSettingsPage implements ColorSettingsPage {
|
|||
@Override
|
||||
public @NonNls @NotNull String getDemoText() {
|
||||
return """
|
||||
.{
|
||||
//This is an example file with some random data
|
||||
.name = "zls",
|
||||
.version = "0.11.0",
|
||||
|
||||
.dependencies = .{
|
||||
.known_folders = .{
|
||||
.url = "https://github.com/ziglibs/known-folders/archive/fa75e1bc672952efa0cf06160bbd942b47f6d59b.tar.gz",
|
||||
.hash = "122048992ca58a78318b6eba4f65c692564be5af3b30fbef50cd4abeda981b2e7fa5",
|
||||
},
|
||||
.diffz = .{
|
||||
.url = "https://github.com/ziglibs/diffz/archive/90353d401c59e2ca5ed0abe5444c29ad3d7489aa.tar.gz",
|
||||
.hash = "122089a8247a693cad53beb161bde6c30f71376cd4298798d45b32740c3581405864",
|
||||
},
|
||||
.binned_allocator = .{
|
||||
.url = "https://gist.github.com/antlilja/8372900fcc09e38d7b0b6bbaddad3904/archive/6c3321e0969ff2463f8335da5601986cf2108690.tar.gz",
|
||||
.hash = "1220363c7e27b2d3f39de6ff6e90f9537a0634199860fea237a55ddb1e1717f5d6a5",
|
||||
},
|
||||
},
|
||||
}
|
||||
""";
|
||||
.{
|
||||
//This is an example file with some random data
|
||||
.name = "zls",
|
||||
.version = "0.11.0",
|
||||
|
||||
.dependencies = .{
|
||||
.known_folders = .{
|
||||
.url = "https://github.com/ziglibs/known-folders/archive/fa75e1bc672952efa0cf06160bbd942b47f6d59b.tar.gz",
|
||||
.hash = "122048992ca58a78318b6eba4f65c692564be5af3b30fbef50cd4abeda981b2e7fa5",
|
||||
},
|
||||
.diffz = .{
|
||||
.url = "https://github.com/ziglibs/diffz/archive/90353d401c59e2ca5ed0abe5444c29ad3d7489aa.tar.gz",
|
||||
.hash = "122089a8247a693cad53beb161bde6c30f71376cd4298798d45b32740c3581405864",
|
||||
},
|
||||
.binned_allocator = .{
|
||||
.url = "https://gist.github.com/antlilja/8372900fcc09e38d7b0b6bbaddad3904/archive/6c3321e0969ff2463f8335da5601986cf2108690.tar.gz",
|
||||
.hash = "1220363c7e27b2d3f39de6ff6e90f9537a0634199860fea237a55ddb1e1717f5d6a5",
|
||||
},
|
||||
},
|
||||
}
|
||||
""";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,7 +31,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
public class ZonSyntaxHighlighter extends SyntaxHighlighterBase {
|
||||
// @formatter: off
|
||||
// @formatter:off
|
||||
public static final TextAttributesKey
|
||||
EQ = createKey("EQ" , DefaultLanguageHighlighterColors.OPERATION_SIGN),
|
||||
ID = createKey("ID" , DefaultLanguageHighlighterColors.INSTANCE_FIELD),
|
||||
|
@ -41,13 +41,13 @@ public class ZonSyntaxHighlighter extends SyntaxHighlighterBase {
|
|||
COMMA = createKey("COMMA" , DefaultLanguageHighlighterColors.COMMA ),
|
||||
DOT = createKey("DOT" , DefaultLanguageHighlighterColors.DOT ),
|
||||
BRACE = createKey("BRACE" , DefaultLanguageHighlighterColors.BRACES );
|
||||
// @formatter: on
|
||||
// @formatter:on
|
||||
|
||||
private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0];
|
||||
private static final Map<IElementType, TextAttributesKey[]> KEYMAP = new HashMap<>();
|
||||
|
||||
static {
|
||||
// @formatter: off
|
||||
// @formatter:off
|
||||
addMapping(DOT , ZonTypes.DOT);
|
||||
addMapping(COMMA , ZonTypes.COMMA);
|
||||
addMapping(BRACE , ZonTypes.LBRACE);
|
||||
|
@ -57,11 +57,11 @@ public class ZonSyntaxHighlighter extends SyntaxHighlighterBase {
|
|||
addMapping(COMMENT , ZonTypes.COMMENT);
|
||||
addMapping(ID , ZonTypes.ID);
|
||||
addMapping(EQ , ZonTypes.EQ);
|
||||
// @formatter: on
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
private static void addMapping(TextAttributesKey key, IElementType... types) {
|
||||
for (var type: types) {
|
||||
for (var type : types) {
|
||||
KEYMAP.put(type, new TextAttributesKey[]{key});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
public class ZonBraceMatcher implements PairedBraceMatcher {
|
||||
public static final BracePair PAIR = new BracePair(ZonTypes.LBRACE, ZonTypes.RBRACE, true);
|
||||
private static final BracePair[] PAIRS = new BracePair[]{PAIR};
|
||||
|
||||
@Override
|
||||
public BracePair @NotNull [] getPairs() {
|
||||
return PAIRS;
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
|
||||
public class ZonParserDefinition implements ParserDefinition {
|
||||
public static final IFileElementType FILE = new IFileElementType(ZonLanguage.INSTANCE);
|
||||
|
||||
@Override
|
||||
public @NotNull Lexer createLexer(Project project) {
|
||||
return new ZonLexerAdapter();
|
||||
|
|
|
@ -26,7 +26,7 @@ import java.util.Set;
|
|||
public class ZonPsiImplUtil {
|
||||
public static Set<String> getKeys(ZonStruct struct) {
|
||||
var result = new HashSet<String>();
|
||||
for (var property: struct.getPropertyList()) {
|
||||
for (var property : struct.getPropertyList()) {
|
||||
result.add(getText(property.getIdentifier()));
|
||||
}
|
||||
return result;
|
||||
|
|
Loading…
Add table
Reference in a new issue