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 Apr 18, 2022
1 parent 346d6fa commit 40f66f6
Show file tree
Hide file tree
Showing 14 changed files with 500 additions and 250 deletions.
3 changes: 2 additions & 1 deletion org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Export-Package: org.eclipse.jdt.ls.core.internal;x-friends:="org.eclipse.jdt.ls.
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.jdt.ls.core.internal.filesystem;x-friends:="org.eclipse.jdt.ls.tests",
org.eclipse.lsp4j.proposed;x-friends:="org.eclipse.jdt.ls.tests"
org.eclipse.lsp4j.proposed;x-friends:="org.eclipse.jdt.ls.tests",
org.eclipse.jdt.ls.core.internal.typeHierarchy;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 @@ -94,12 +94,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 @@ -24,16 +24,10 @@
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.handlers.FormatterHandler;
import org.eclipse.jdt.ls.core.internal.handlers.ResolveSourceMappingHandler;
import org.eclipse.jdt.ls.core.internal.managers.GradleProjectImporter;
import org.eclipse.lsp4j.ResolveTypeHierarchyItemParams;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.TextDocumentPositionParams;
import org.eclipse.lsp4j.TypeHierarchyDirection;
import org.eclipse.lsp4j.TypeHierarchyItem;
import org.eclipse.lsp4j.TypeHierarchyParams;
import org.eclipse.lsp4j.WorkspaceEdit;

public class JDTDelegateCommandHandler implements IDelegateCommandHandler {
Expand Down Expand Up @@ -93,29 +87,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);
return GradleProjectImporter.upgradeGradleVersion(projectUri, monitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ public void registerCapabilities(InitializeResult initializeResult) {
));
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 @@ -68,10 +68,16 @@
import org.eclipse.jdt.ls.core.internal.handlers.OverrideMethodsHandler.OverridableMethodsResponse;
import org.eclipse.jdt.ls.core.internal.handlers.WorkspaceSymbolHandler.SearchSymbolParams;
import org.eclipse.jdt.ls.core.internal.lsp.JavaProtocolExtensions;
import org.eclipse.jdt.ls.core.internal.lsp.TextDocumentProtocolExtensions;
import org.eclipse.jdt.ls.core.internal.lsp.TypeHierarchyProtocolExtensions;
import org.eclipse.jdt.ls.core.internal.managers.ContentProviderManager;
import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager;
import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager;
import org.eclipse.jdt.ls.core.internal.preferences.Preferences;
import org.eclipse.jdt.ls.core.internal.typeHierarchy.TypeHierarchyItem;
import org.eclipse.jdt.ls.core.internal.typeHierarchy.TypeHierarchyPrepareParams;
import org.eclipse.jdt.ls.core.internal.typeHierarchy.TypeHierarchySubtypesParams;
import org.eclipse.jdt.ls.core.internal.typeHierarchy.TypeHierarchySupertypesParams;
import org.eclipse.lsp4j.CallHierarchyIncomingCall;
import org.eclipse.lsp4j.CallHierarchyIncomingCallsParams;
import org.eclipse.lsp4j.CallHierarchyItem;
Expand Down Expand Up @@ -151,7 +157,7 @@
*
*/
public class JDTLanguageServer extends BaseJDTLanguageServer implements LanguageServer, TextDocumentService, WorkspaceService,
JavaProtocolExtensions, InlayHintProvider {
JavaProtocolExtensions, InlayHintProvider, TextDocumentProtocolExtensions, TypeHierarchyProtocolExtensions {

public static final String JAVA_LSP_JOIN_ON_COMPLETION = "java.lsp.joinOnCompletion";
public static final String JAVA_LSP_INITIALIZE_WORKSPACE = "java.lsp.initializeWorkspace";
Expand All @@ -167,6 +173,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 @@ -1034,6 +1041,23 @@ public CompletableFuture<List<InlayHint>> inlayHint(InlayHintParams params) {
return computeAsync(monitor -> new InlayHintsHandler(preferenceManager).inlayHint(params, monitor));
}

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

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

@Override
public CompletableFuture<List<TypeHierarchyItem>> subtypes(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 40f66f6

Please sign in to comment.