Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

highlight QualifiedName together in packages #1435

Merged
merged 1 commit into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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