Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
trying around with autocomplete and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
BloodWorkXGaming committed Sep 4, 2017
1 parent 98f8c34 commit dd089b6
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,41 @@
import org.jetbrains.annotations.NotNull;

public class ZsCompletionContributor extends CompletionContributor {
private String[] keywords = {
"any",
"bool",
"byte",
"short",
"int",
"long",
"float",
"double",
"string",
"function",
"in",
"void",
"as",
"version",
"if",
"else",
"for",
"return",
"var",
"val",
"null",
"true",
"false",
"import",
};

public ZsCompletionContributor() {
extend(CompletionType.BASIC,
PlatformPatterns.psiElement(ZsTypes.IDENTIFIER).withLanguage(ZsLanguage.INSTANCE),
extend(CompletionType.BASIC, PlatformPatterns.psiElement(ZsTypes.IDENTIFIER).withLanguage(ZsLanguage.INSTANCE),
new CompletionProvider<CompletionParameters>() {
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
result.addElement(LookupElementBuilder.create("Hello"));
for (String keyword : keywords) {
result.addElement(LookupElementBuilder.create(keyword));
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public BracePair[] getPairs() {

@Override
public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType iElementType, @Nullable IElementType iElementType1) {
return false;
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ZsColorSettingsPage implements ColorSettingsPage {
private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[]{
new AttributesDescriptor("Key", ZsSyntaxHighlighter.KEYWORD),
new AttributesDescriptor("Separator", ZsSyntaxHighlighter.SEPARATOR),
new AttributesDescriptor("Value", ZsSyntaxHighlighter.VALUE),
new AttributesDescriptor("Value", ZsSyntaxHighlighter.VARIABLE),
};

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,40 @@
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
import com.intellij.openapi.editor.HighlighterColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.editor.colors.TextAttributesScheme;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase;
import com.intellij.psi.PsiElement;
import com.intellij.psi.TokenType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil;
import de.bloodworkxgaming.zenscript.plugin.zsLanguage.parsing.ZsLexerAdapter;
import de.bloodworkxgaming.zenscript.plugin.zsLanguage.psi.ZsTokenType;
import de.bloodworkxgaming.zenscript.plugin.zsLanguage.psi.ZsTypes;
import de.bloodworkxgaming.zenscript.plugin.zsLanguage.psi.ZsVariable;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;

import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey;

public class ZsSyntaxHighlighter extends SyntaxHighlighterBase {
public static final TextAttributesKey SEPARATOR = createTextAttributesKey("SIMPLE_SEPARATOR", DefaultLanguageHighlighterColors.OPERATION_SIGN);
public static final TextAttributesKey KEYWORD = createTextAttributesKey("SIMPLE_KEY", DefaultLanguageHighlighterColors.KEYWORD);
public static final TextAttributesKey VALUE = createTextAttributesKey("SIMPLE_VALUE", DefaultLanguageHighlighterColors.STRING);
public static final TextAttributesKey COMMENT = createTextAttributesKey("SIMPLE_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT);
public static final TextAttributesKey BAD_CHARACTER = createTextAttributesKey("SIMPLE_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER);

public static final TextAttributesKey NUMBER = createTextAttributesKey("NUMBER", DefaultLanguageHighlighterColors.NUMBER);
public static final TextAttributesKey SEPARATOR = createTextAttributesKey("ZS_SEPARATOR", DefaultLanguageHighlighterColors.OPERATION_SIGN);
public static final TextAttributesKey KEYWORD = createTextAttributesKey("ZS_KEY", DefaultLanguageHighlighterColors.KEYWORD);
public static final TextAttributesKey VARIABLE = createTextAttributesKey("ZS_VARIABLE", DefaultLanguageHighlighterColors.KEYWORD); //TODO: set back to right name
public static final TextAttributesKey COMMENT = createTextAttributesKey("ZS_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT);
public static final TextAttributesKey BAD_CHARACTER = createTextAttributesKey("ZS_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER);
public static final TextAttributesKey STRING = createTextAttributesKey("ZS_STRING", DefaultLanguageHighlighterColors.STRING);
public static final TextAttributesKey NUMBER = createTextAttributesKey("ZS_NUMBER", DefaultLanguageHighlighterColors.NUMBER);
public static final TextAttributesKey BRACKET_HANDLER = createTextAttributesKey("ZS_BRACKET_HANDLER", DefaultLanguageHighlighterColors.MARKUP_ATTRIBUTE);

private static final TextAttributesKey[] BAD_CHAR_KEYS = new TextAttributesKey[]{BAD_CHARACTER};
private static final TextAttributesKey[] SEPARATOR_KEYS = new TextAttributesKey[]{SEPARATOR};
private static final TextAttributesKey[] KEYWORD_KEYS = new TextAttributesKey[]{KEYWORD};
private static final TextAttributesKey[] VALUE_KEYS = new TextAttributesKey[]{VALUE};
private static final TextAttributesKey[] VARIABLE_KEYS = new TextAttributesKey[]{VARIABLE};
private static final TextAttributesKey[] COMMENT_KEYS = new TextAttributesKey[]{COMMENT};
private static final TextAttributesKey[] NUMBER_KEYS = new TextAttributesKey[]{NUMBER};
private static final TextAttributesKey[] STRING_KEYS = new TextAttributesKey[]{STRING};
private static final TextAttributesKey[] BRACKET_HANDLER_KEYS = new TextAttributesKey[]{BRACKET_HANDLER};
private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0];

@NotNull
Expand All @@ -39,21 +49,31 @@ public Lexer getHighlightingLexer() {
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
/*if (tokenType.equals(ZsTypes.SEPARATOR)) {
return SEPARATOR_KEYS;
} else*/ if (isKeyword(tokenType)) {
if (tokenType.equals(ZsTypes.VARIABLE)) {
return VARIABLE_KEYS;
} else if (isKeyword(tokenType)) {
return KEYWORD_KEYS;
} else /*if (tokenType.equals(ZsTypes.VALUE)) {
return VALUE_KEYS;
} else */if (tokenType.equals(ZsTypes.LINE_COMMENT) || tokenType.equals(ZsTypes.BLOCK_COMMENT)) {
} else if (tokenType.equals(ZsTypes.DOUBLE_QUOTED_STRING) | tokenType.equals(ZsTypes.SINGLE_QUOTED_STRING)) {
return STRING_KEYS;
} else if (tokenType.equals(ZsTypes.LINE_COMMENT) || tokenType.equals(ZsTypes.BLOCK_COMMENT)) {
return COMMENT_KEYS;
} else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
return BAD_CHAR_KEYS;
} else if (isNumber(tokenType)){
return NUMBER_KEYS;
} else {
return EMPTY_KEYS;
} else if (tokenType.equals(ZsTypes.BRACKET_HANDLER)){
return BRACKET_HANDLER_KEYS;
} else if (tokenType.equals(ZsTypes.IDENTIFIER)){
return VARIABLE_KEYS;
}

return EMPTY_KEYS;
}

private boolean isNumber (IElementType tokenType){
return tokenType.equals(ZsTypes.NUMBER) |
tokenType.equals(ZsTypes.DIGITS) |
tokenType.equals(ZsTypes.FLOATING_POINT);
}

private boolean isKeyword(IElementType tokenType){
Expand Down Expand Up @@ -82,10 +102,4 @@ private boolean isKeyword(IElementType tokenType){
tokenType.equals(ZsTypes.FALSE) |
tokenType.equals(ZsTypes.IMPORT);
}

private boolean isNumber (IElementType tokenType){
return tokenType.equals(ZsTypes.NUMBER) |
tokenType.equals(ZsTypes.DIGITS) |
tokenType.equals(ZsTypes.FLOATING_POINT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

public class ZsLexerAdapter extends FlexAdapter {
public ZsLexerAdapter() {
super(new _ZsLexer()); // TODO: switch back to other lexer if needed
super(new _ZsLexer());
}
}

0 comments on commit dd089b6

Please sign in to comment.