Skip to content

Commit

Permalink
highlight type, constructor and package
Browse files Browse the repository at this point in the history
Signed-off-by: Yan Zhang <[email protected]>
  • Loading branch information
Eskibear committed Apr 23, 2020
1 parent 1defde2 commit cb41511
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.IVariableBinding;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.ls.core.internal.handlers.JsonRpcHelpers;
import org.eclipse.jface.text.IDocument;

Expand Down Expand Up @@ -123,19 +125,21 @@ public boolean visit(SimpleName node) {
TokenType tokenType = null;
switch (binding.getKind()) {
case IBinding.VARIABLE: {
if (((IVariableBinding) binding).isField()) {
tokenType = TokenType.VARIABLE;
}
tokenType = TokenType.VARIABLE;
break;
}
case IBinding.METHOD: {
tokenType = TokenType.METHOD;
tokenType = TokenType.FUNCTION;
break;
}
case IBinding.TYPE: {
tokenType = TokenType.TYPE;
break;
}
case IBinding.PACKAGE: {
tokenType = TokenType.NAMESPACE;
break;
}
default:
break;
}
Expand All @@ -145,13 +149,15 @@ public boolean visit(SimpleName node) {
}

switch (tokenType) {
case METHOD:
case VARIABLE: {
case FUNCTION:
case VARIABLE:
case MEMBER: {
ITokenModifier[] modifiers = getModifiers(binding);
addToken(node, tokenType, modifiers);
break;
}
case TYPE:
case NAMESPACE:
addToken(node, tokenType, NO_MODIFIERS);
break;
default:
Expand All @@ -178,4 +184,14 @@ private ITokenModifier[] getModifiers(IBinding binding) {
return modifiers;
}

@Override
public boolean visit(SimpleType node) {
ASTNode parent = node.getParent();
if (parent instanceof ClassInstanceCreation) { // For ClassInstanceCreation "new E()", "E" should be highlighted as 'function' instead of 'type'
addToken(node, TokenType.FUNCTION, NO_MODIFIERS);
return false;
}
return super.visit(node);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public boolean applies(IBinding binding) {

@Override
public String toString() {
return "final";
return "readonly";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,26 @@
package org.eclipse.jdt.ls.core.internal.semantictokens;

public enum TokenType {
COMMENT("comment"),
KEYWORD("keyword"),
STRING("string"),
NUMBER("number"),
REGEXP("regexp"),
OPERATOR("operator"),
NAMESPACE("namespace"),
TYPE("type"),
STRUCT("struct"),
CLASS("class"),
INTERFACE("interface"),
ENUM("enum"),
TYPE_PARAMETER("typeParameter"),
FUNCTION("function"),
MEMBER("member"),
PROPERTY("property"),
MACRO("macro"),
VARIABLE("variable"),
METHOD("method"),
TYPE("type")
PARAMETER("parameter"),
LABEL("label")
;

private String literalString;
Expand Down

0 comments on commit cb41511

Please sign in to comment.