Skip to content

Commit

Permalink
Improve semantic token modifiers
Browse files Browse the repository at this point in the history
Signed-off-by: 0dinD <[email protected]>
  • Loading branch information
0dinD committed Sep 30, 2020
1 parent e69383c commit 64965f3
Show file tree
Hide file tree
Showing 14 changed files with 535 additions and 367 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
import org.eclipse.jdt.ls.core.internal.commands.DiagnosticsCommand;
import org.eclipse.jdt.ls.core.internal.commands.OrganizeImportsCommand;
import org.eclipse.jdt.ls.core.internal.commands.ProjectCommand;
import org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathOptions;
import org.eclipse.jdt.ls.core.internal.commands.SemanticTokensCommand;
import org.eclipse.jdt.ls.core.internal.commands.SourceAttachmentCommand;
import org.eclipse.jdt.ls.core.internal.commands.ProjectCommand.ClasspathOptions;
import org.eclipse.jdt.ls.core.internal.semantictokens.SemanticTokensLegend;
import org.eclipse.lsp4j.WorkspaceEdit;

public class JDTDelegateCommandHandler implements IDelegateCommandHandler {
Expand Down Expand Up @@ -74,7 +75,7 @@ public Object executeCommand(String commandId, List<Object> arguments, IProgress
case "java.project.provideSemanticTokens":
return SemanticTokensCommand.provide((String) arguments.get(0));
case "java.project.getSemanticTokensLegend":
return SemanticTokensCommand.getLegend();
return new SemanticTokensLegend();
case "java.project.import":
ProjectCommand.importProject(monitor);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@

package org.eclipse.jdt.ls.core.internal.commands;

import java.util.Collections;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.manipulation.CoreASTProvider;
import org.eclipse.jdt.ls.core.internal.JDTUtils;
import org.eclipse.jdt.ls.core.internal.JobHelpers;
import org.eclipse.jdt.ls.core.internal.handlers.DocumentLifeCycleHandler;
import org.eclipse.jdt.ls.core.internal.semantictokens.SemanticTokenManager;
import org.eclipse.jdt.ls.core.internal.semantictokens.SemanticTokens;
import org.eclipse.jdt.ls.core.internal.semantictokens.SemanticTokensLegend;
import org.eclipse.jdt.ls.core.internal.semantictokens.SemanticTokensVisitor;

public class SemanticTokensCommand {
Expand All @@ -36,20 +32,16 @@ public static SemanticTokens provide(String uri) {
private static SemanticTokens doProvide(String uri) {
ITypeRoot typeRoot = JDTUtils.resolveTypeRoot(uri);
if (typeRoot == null) {
return new SemanticTokens(Collections.emptyList());
return new SemanticTokens(new int[0]);
}

CompilationUnit root = CoreASTProvider.getInstance().getAST(typeRoot, CoreASTProvider.WAIT_YES, new NullProgressMonitor());
if (root == null) {
return new SemanticTokens(Collections.emptyList());
return new SemanticTokens(new int[0]);
}

SemanticTokensVisitor collector = new SemanticTokensVisitor(root, SemanticTokenManager.getInstance());
SemanticTokensVisitor collector = new SemanticTokensVisitor(root);
root.accept(collector);
return collector.getSemanticTokens();
}

public static SemanticTokensLegend getLegend() {
return SemanticTokenManager.getInstance().getLegend();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*******************************************************************************/
package org.eclipse.jdt.ls.core.internal.semantictokens;

import java.util.List;

import org.eclipse.lsp4j.util.Preconditions;

public class SemanticTokens {
Expand Down Expand Up @@ -74,7 +72,7 @@ public class SemanticTokens {
* [ 2,5,3,0,3, 0,5,4,1,0, 3,2,7,2,0 ]
* ```
*/
private final List<Integer> data;
private final int[] data;

/**
* The result id of the tokens (optional).
Expand All @@ -83,20 +81,20 @@ public class SemanticTokens {
*/
private final String resultId;

public SemanticTokens(List<Integer> data) {
public SemanticTokens(int[] data) {
this(data, null);
}

public SemanticTokens(List<Integer> data, String resultId) {
this.data = Preconditions.<List<Integer>>checkNotNull(data, "data");
public SemanticTokens(int[] data, String resultId) {
this.data = Preconditions.<int[]>checkNotNull(data, "data");
this.resultId = resultId;
}

public String getResultId() {
return resultId;
}

public List<Integer> getData() {
public int[] getData() {
return data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,26 @@
*******************************************************************************/
package org.eclipse.jdt.ls.core.internal.semantictokens;

import java.util.List;
import java.util.Arrays;

public class SemanticTokensLegend {
private final List<String> tokenTypes;
private final List<String> tokenModifiers;
public final class SemanticTokensLegend {
private final String[] tokenTypes;
private final String[] tokenModifiers;

public SemanticTokensLegend(List<String> tokenTypes, List<String> tokenModifiers){
this.tokenTypes = tokenTypes;
this.tokenModifiers = tokenModifiers;
};
public SemanticTokensLegend() {
tokenTypes = Arrays.stream(TokenType.values())
.map(TokenType::toString)
.toArray(String[]::new);
tokenModifiers = Arrays.stream(TokenModifier.values())
.map(TokenModifier::toString)
.toArray(String[]::new);
}

public List<String> getTokenTypes() {
return this.tokenTypes;
public String[] getTokenTypes() {
return tokenTypes;
}

public List<String> getTokenModifiers() {
return this.tokenModifiers;
public String[] getTokenModifiers() {
return tokenModifiers;
}
}
Loading

0 comments on commit 64965f3

Please sign in to comment.