Skip to content

Commit

Permalink
highlight QualifiedName together in packages
Browse files Browse the repository at this point in the history
Signed-off-by: Yan Zhang <[email protected]>
  • Loading branch information
Eskibear authored and fbricon committed May 6, 2020
1 parent f5d4616 commit 0d3561a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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.QualifiedName;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.ls.core.internal.handlers.JsonRpcHelpers;
Expand Down Expand Up @@ -115,6 +116,16 @@ private void addToken(ASTNode node, TokenType tokenType, ITokenModifier[] modifi
tokens.add(token);
}

@Override
public boolean visit(QualifiedName node) {
IBinding binding = node.resolveBinding();
if (binding != null && binding.getKind() == IBinding.PACKAGE) {
addToken(node, TokenType.NAMESPACE, NO_MODIFIERS);
return false;
}
return super.visit(node);
}

@Override
public boolean visit(SimpleName node) {
IBinding binding = node.resolveBinding();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ public void testSemanticTokens_types() throws JavaModelException {
assertToken(decodedTokens, legend, 4, 11, 6, "type", Arrays.asList());
}

@Test
public void testSemanticTokens_packages() throws JavaModelException {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("import java.util.List;\n");
buf.append("import java.nio.*;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
SemanticTokensLegend legend = SemanticTokensCommand.getLegend();
SemanticTokens tokens = SemanticTokensCommand.provide(JDTUtils.toURI(cu));
Map<Integer, Map<Integer, int[]>> decodedTokens = decode(tokens);
assertToken(decodedTokens, legend, 1, 7, 9, "namespace", Arrays.asList());
assertToken(decodedTokens, legend, 2, 7, 8, "namespace", Arrays.asList());
}

private void assertModifiers(List<String> tokenModifiers, int encodedModifiers, List<String> modifierStrings) {
int cnt = 0;
for (int i=0; i<tokenModifiers.size(); i++) {
Expand Down Expand Up @@ -178,7 +196,7 @@ private Map<Integer, Map<Integer, int[]>> decode(SemanticTokens tokens) {
int total = data.size() / 5;
Map<Integer, Map<Integer, int[]>> decodedTokens = new HashMap<>();
int currentLine = 0;
int currentColumn = 0;
int currentColumn = 0;
for(int i = 0; i<total; i++) {
int offset = 5 * i;
int deltaLine = data.get(offset).intValue();
Expand Down

0 comments on commit 0d3561a

Please sign in to comment.