Skip to content

Commit

Permalink
Provide semantic tokens for class files
Browse files Browse the repository at this point in the history
Signed-off-by: 0dinD <[email protected]>
  • Loading branch information
0dinD authored and fbricon committed Jul 21, 2020
1 parent d2d7280 commit 68787e1
Showing 1 changed file with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.Collections;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.manipulation.CoreASTProvider;
Expand All @@ -32,35 +32,33 @@
import org.eclipse.jface.text.IDocument;

public class SemanticTokensCommand {
public static SemanticTokens provide(String uri) {
JobHelpers.waitForJobs(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, null);
return doProvide(uri);
}
public static SemanticTokens provide(String uri) {
JobHelpers.waitForJobs(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, null);
return doProvide(uri);
}

private static SemanticTokens doProvide(String uri) {
IDocument document = null;
private static SemanticTokens doProvide(String uri) {
IDocument document = null;

ICompilationUnit cu = JDTUtils.resolveCompilationUnit(uri);
if (cu != null) {
try {
document = JsonRpcHelpers.toDocument(cu.getBuffer());
} catch (JavaModelException e) {
JavaLanguageServerPlugin.logException("Failed to provide semantic tokens for " + uri, e);
}
}
if (document == null) {
return new SemanticTokens(Collections.emptyList());
}

SemanticTokensVisitor collector = new SemanticTokensVisitor(document, SemanticTokenManager.getInstance());
CompilationUnit root = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, new NullProgressMonitor());
root.accept(collector);
return collector.getSemanticTokens();
}

public static SemanticTokensLegend getLegend() {
return SemanticTokenManager.getInstance().getLegend();
}
ITypeRoot typeRoot = JDTUtils.resolveTypeRoot(uri);
if (typeRoot != null) {
try {
document = JsonRpcHelpers.toDocument(typeRoot.getBuffer());
} catch (JavaModelException e) {
JavaLanguageServerPlugin.logException("Failed to provide semantic tokens for " + uri, e);
}
}
if (document == null) {
return new SemanticTokens(Collections.emptyList());
}

SemanticTokensVisitor collector = new SemanticTokensVisitor(document, SemanticTokenManager.getInstance());
CompilationUnit root = CoreASTProvider.getInstance().getAST(typeRoot, CoreASTProvider.WAIT_YES, new NullProgressMonitor());
root.accept(collector);
return collector.getSemanticTokens();
}

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

0 comments on commit 68787e1

Please sign in to comment.