Skip to content

Commit

Permalink
Move TypeHierarchy to LSP
Browse files Browse the repository at this point in the history
Signed-off-by: Shi Chen <[email protected]>
  • Loading branch information
CsCherrYY committed Mar 27, 2023
1 parent 00391c1 commit 651942d
Show file tree
Hide file tree
Showing 15 changed files with 469 additions and 1,279 deletions.
3 changes: 1 addition & 2 deletions org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ Export-Package: org.eclipse.jdt.ls.core.contentassist;x-friends:="org.eclipse.jd
org.eclipse.jdt.ls.core.internal.syntaxserver;x-friends:="org.eclipse.jdt.ls.tests.syntaxserver",
org.eclipse.jdt.ls.core.internal.text.correction;x-friends:="org.eclipse.jdt.ls.tests",
org.eclipse.jdt.ls.internal.gradle.checksums;x-friends:="org.eclipse.jdt.ls.tests",
org.eclipse.lsp4j.extended;x-friends:="org.eclipse.jdt.ls.tests",
org.eclipse.lsp4j.legacy.typeHierarchy;x-friends:="org.eclipse.jdt.ls.tests"
org.eclipse.lsp4j.extended;x-friends:="org.eclipse.jdt.ls.tests"
Bundle-ClassPath: lib/jsoup-1.14.2.jar,
lib/remark-1.2.0.jar,
.
Expand Down
6 changes: 0 additions & 6 deletions org.eclipse.jdt.ls.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,6 @@
<command
id="java.project.resolveStackTraceLocation">
</command>
<command
id="java.navigate.openTypeHierarchy">
</command>
<command
id="java.navigate.resolveTypeHierarchy">
</command>
<command
id="java.project.upgradeGradle">
</command>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
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.SourceAttachmentCommand;
import org.eclipse.jdt.ls.core.internal.commands.TypeHierarchyCommand;
import org.eclipse.jdt.ls.core.internal.framework.protobuf.ProtobufSupport;
import org.eclipse.jdt.ls.core.internal.handlers.BundleUtils;
import org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler;
Expand All @@ -42,12 +41,7 @@
import org.eclipse.jdt.ls.core.internal.handlers.ResolveSourceMappingHandler;
import org.eclipse.jdt.ls.core.internal.managers.GradleProjectImporter;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.TextDocumentPositionParams;
import org.eclipse.lsp4j.WorkspaceEdit;
import org.eclipse.lsp4j.legacy.typeHierarchy.ResolveTypeHierarchyItemParams;
import org.eclipse.lsp4j.legacy.typeHierarchy.TypeHierarchyDirection;
import org.eclipse.lsp4j.legacy.typeHierarchy.TypeHierarchyItem;
import org.eclipse.lsp4j.legacy.typeHierarchy.TypeHierarchyParams;

public class JDTDelegateCommandHandler implements IDelegateCommandHandler {

Expand Down Expand Up @@ -108,29 +102,6 @@ public Object executeCommand(String commandId, List<Object> arguments, IProgress
projectNames = (ArrayList<String>) arguments.get(1);
}
return ResolveSourceMappingHandler.resolveStackTraceLocation((String) arguments.get(0), projectNames);
case "java.navigate.resolveTypeHierarchy":
TypeHierarchyCommand resolveTypeHierarchyCommand = new TypeHierarchyCommand();
TypeHierarchyItem toResolve = JSONUtility.toModel(arguments.get(0), TypeHierarchyItem.class);
TypeHierarchyDirection resolveDirection = TypeHierarchyDirection.forValue(JSONUtility.toModel(arguments.get(1), Integer.class));
int resolveDepth = JSONUtility.toModel(arguments.get(2), Integer.class);
ResolveTypeHierarchyItemParams resolveParams = new ResolveTypeHierarchyItemParams();
resolveParams.setItem(toResolve);
resolveParams.setDirection(resolveDirection);
resolveParams.setResolve(resolveDepth);
TypeHierarchyItem resolvedItem = resolveTypeHierarchyCommand.resolveTypeHierarchy(resolveParams, monitor);
return resolvedItem;
case "java.navigate.openTypeHierarchy":
TypeHierarchyCommand typeHierarchyCommand = new TypeHierarchyCommand();
TypeHierarchyParams params = new TypeHierarchyParams();
TextDocumentPositionParams textParams = JSONUtility.toModel(arguments.get(0), TextDocumentPositionParams.class);
TypeHierarchyDirection direction = TypeHierarchyDirection.forValue(JSONUtility.toModel(arguments.get(1), Integer.class));
int resolve = JSONUtility.toModel(arguments.get(2), Integer.class);
params.setResolve(resolve);
params.setDirection(direction);
params.setTextDocument(textParams.getTextDocument());
params.setPosition(textParams.getPosition());
TypeHierarchyItem typeHierarchyItem = typeHierarchyCommand.typeHierarchy(params, monitor);
return typeHierarchyItem;
case "java.project.upgradeGradle":
String projectUri = (String) arguments.get(0);
String gradleVersion = arguments.size() > 1 ? (String) arguments.get(1) : null;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public void registerCapabilities(InitializeResult initializeResult) {
semanticTokensOptions.setDocumentSelector(List.of(new DocumentFilter("java", "file", null), new DocumentFilter("java", "jdt", null)));
semanticTokensOptions.setLegend(SemanticTokensHandler.legend());
capabilities.setSemanticTokensProvider(semanticTokensOptions);
capabilities.setTypeHierarchyProvider(Boolean.TRUE);

initializeResult.setCapabilities(capabilities);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.eclipse.lsp4j.TextEdit;
import org.eclipse.lsp4j.TypeDefinitionParams;
import org.eclipse.lsp4j.TypeHierarchyItem;
import org.eclipse.lsp4j.TypeHierarchyPrepareParams;
import org.eclipse.lsp4j.TypeHierarchySubtypesParams;
import org.eclipse.lsp4j.TypeHierarchySupertypesParams;
import org.eclipse.lsp4j.WillSaveTextDocumentParams;
import org.eclipse.lsp4j.WorkspaceEdit;
import org.eclipse.lsp4j.WorkspaceSymbol;
Expand Down Expand Up @@ -173,6 +177,7 @@ public class JDTLanguageServer extends BaseJDTLanguageServer implements Language
private ClasspathUpdateHandler classpathUpdateHandler;
private JVMConfigurator jvmConfigurator;
private WorkspaceExecuteCommandHandler commandHandler;
private TypeHierarchyHandler typeHierarchyHandler = new TypeHierarchyHandler();

private ProgressReporterManager progressReporterManager;
/**
Expand Down Expand Up @@ -1111,6 +1116,24 @@ public CompletableFuture<CheckExtractInterfaceResponse> checkExtractInterfaceSta
return computeAsync((monitor) -> ExtractInterfaceHandler.checkExtractInterfaceStatus(params));
}

@Override
public CompletableFuture<List<TypeHierarchyItem>> prepareTypeHierarchy(TypeHierarchyPrepareParams params) {
logInfo(">> textDocument/prepareTypeHierarchy");
return computeAsync(monitor -> typeHierarchyHandler.prepareTypeHierarchy(params, monitor));
}

@Override
public CompletableFuture<List<TypeHierarchyItem>> typeHierarchySupertypes(TypeHierarchySupertypesParams params) {
logInfo(">> typeHierarchy/supertypes");
return computeAsync(monitor -> typeHierarchyHandler.getSupertypeItems(params, monitor));
}

@Override
public CompletableFuture<List<TypeHierarchyItem>> typeHierarchySubtypes(TypeHierarchySubtypesParams params) {
logInfo(">> typeHierarchy/subtypes");
return computeAsync(monitor -> typeHierarchyHandler.getSubtypeItems(params, monitor));
}

private <R> CompletableFuture<R> computeAsyncWithClientProgress(Function<IProgressMonitor, R> code) {
return CompletableFutures.computeAsync((cc) -> {
IProgressMonitor monitor = progressReporterManager.getProgressReporter(cc);
Expand Down
Loading

0 comments on commit 651942d

Please sign in to comment.