diff --git a/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/completion/ZsCompletionContributor.java b/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/completion/ZsCompletionContributor.java index 81dbe0e..0a5bfa0 100644 --- a/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/completion/ZsCompletionContributor.java +++ b/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/completion/ZsCompletionContributor.java @@ -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() { @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)); + } } }); } diff --git a/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/formatter/ZsBraceMatcher.java b/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/formatter/ZsBraceMatcher.java index 43e3f3a..8413e37 100644 --- a/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/formatter/ZsBraceMatcher.java +++ b/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/formatter/ZsBraceMatcher.java @@ -22,7 +22,7 @@ public BracePair[] getPairs() { @Override public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType iElementType, @Nullable IElementType iElementType1) { - return false; + return true; } @Override diff --git a/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/formatter/ZsColorSettingsPage.java b/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/formatter/ZsColorSettingsPage.java index f1a88b3..a743d86 100644 --- a/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/formatter/ZsColorSettingsPage.java +++ b/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/formatter/ZsColorSettingsPage.java @@ -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 diff --git a/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/formatter/ZsSyntaxHighlighter.java b/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/formatter/ZsSyntaxHighlighter.java index 7860a57..ae2a98b 100644 --- a/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/formatter/ZsSyntaxHighlighter.java +++ b/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/formatter/ZsSyntaxHighlighter.java @@ -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 @@ -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){ @@ -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); - } } diff --git a/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/parsing/ZsLexerAdapter.java b/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/parsing/ZsLexerAdapter.java index a60b10e..4808de6 100644 --- a/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/parsing/ZsLexerAdapter.java +++ b/src/de/bloodworkxgaming/zenscript/plugin/zsLanguage/parsing/ZsLexerAdapter.java @@ -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()); } }