From 13b6268ff76fa0535db5916f36ad207060a4a99e Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Fri, 25 Nov 2022 14:08:00 +0100 Subject: [PATCH] Use LSP4J 0.19.0 * Bump versions & adopt new APIs (eg remap globPatterns to String) * Remove custom text hierarchy commands; use LSP standards * Remove custom inlayHints, use standard * Declare null notebook service --- org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF | 5 +- .../internal/JDTDelegateCommandHandler.java | 29 ---- .../core/internal/JavaClientConnection.java | 8 - .../internal/handlers/InlayHintVisitor.java | 2 +- .../internal/handlers/InlayHintsHandler.java | 4 +- .../internal/handlers/JDTLanguageServer.java | 45 +++++- .../handlers/PrepareRenameHandler.java | 9 +- .../TypeHierarchyHandler.java} | 150 +++++++----------- .../managers/StandardProjectsManager.java | 6 +- .../preferences/ClientPreferences.java | 5 - .../syntaxserver/SyntaxProjectsManager.java | 9 +- .../org/eclipse/lsp4j/proposed/InlayHint.java | 84 ---------- .../eclipse/lsp4j/proposed/InlayHintKind.java | 44 ----- .../lsp4j/proposed/InlayHintLabelPart.java | 17 -- .../lsp4j/proposed/InlayHintParams.java | 110 ------------- .../lsp4j/proposed/InlayHintProvider.java | 28 ---- .../org.eclipse.jdt.ls.tp.target | 6 +- .../META-INF/MANIFEST.MF | 4 +- org.eclipse.jdt.ls.tests/META-INF/MANIFEST.MF | 5 +- .../commands/TypeHierarchyCommandTest.java | 83 ++++------ .../internal/handlers/InitHandlerTest.java | 50 +++--- .../handlers/InlayHintHandlerTest.java | 4 +- .../handlers/PrepareRenameHandlerTest.java | 2 +- .../managers/EclipseProjectImporterTest.java | 4 +- .../InvisibleProjectImporterTest.java | 16 +- 25 files changed, 182 insertions(+), 547 deletions(-) rename org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/{commands/TypeHierarchyCommand.java => handlers/TypeHierarchyHandler.java} (50%) delete mode 100644 org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHint.java delete mode 100644 org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHintKind.java delete mode 100644 org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHintLabelPart.java delete mode 100644 org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHintParams.java delete mode 100644 org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHintProvider.java diff --git a/org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF b/org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF index 47118a8d46..eb944e5b26 100644 --- a/org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF @@ -25,8 +25,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.12.0", org.eclipse.jdt.core.manipulation;bundle-version="1.8.0", com.google.gson;bundle-version="2.7.0", org.apache.commons.lang3;bundle-version="3.1.0", - org.eclipse.lsp4j;bundle-version="[0.12.0,0.13.0)", - org.eclipse.lsp4j.jsonrpc;bundle-version="[0.12.0,0.13.0)", + org.eclipse.lsp4j;bundle-version="0.15.0", + org.eclipse.lsp4j.jsonrpc;bundle-version="0.15.0", org.eclipse.xtend.lib, org.eclipse.xtext.xbase.lib, org.eclipse.core.filesystem;bundle-version="1.7.0", @@ -59,7 +59,6 @@ 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.core.contentassist;x-friends:="org.eclipse.jdt.ls.tests", org.eclipse.jdt.ls.internal.gradle.checksums;x-friends:="org.eclipse.jdt.ls.tests", - org.eclipse.lsp4j.proposed;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, diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JDTDelegateCommandHandler.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JDTDelegateCommandHandler.java index 6ac1af8d23..95af4c0be0 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JDTDelegateCommandHandler.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JDTDelegateCommandHandler.java @@ -26,7 +26,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; @@ -36,12 +35,7 @@ import org.eclipse.jdt.ls.core.internal.handlers.PasteEventHandler.PasteEventParams; 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 { @@ -103,29 +97,6 @@ public Object executeCommand(String commandId, List arguments, IProgress projectNames = (ArrayList) 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; diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JavaClientConnection.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JavaClientConnection.java index 10544e1e0d..bee0981169 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JavaClientConnection.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JavaClientConnection.java @@ -20,7 +20,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin; import org.eclipse.jdt.ls.core.internal.handlers.LogHandler; import org.eclipse.jdt.ls.core.internal.lsp.ExecuteCommandProposedClient; import org.eclipse.lsp4j.ApplyWorkspaceEditParams; @@ -37,7 +36,6 @@ import org.eclipse.lsp4j.UnregistrationParams; import org.eclipse.lsp4j.WorkspaceEdit; import org.eclipse.lsp4j.jsonrpc.services.JsonNotification; -import org.eclipse.lsp4j.jsonrpc.services.JsonRequest; import org.eclipse.lsp4j.services.LanguageClient; import com.google.common.collect.ImmutableList; @@ -76,12 +74,6 @@ public interface JavaLanguageClient extends LanguageClient, ExecuteCommandPropos @JsonNotification("language/progressReport") void sendProgressReport(ProgressReport report); - // TODO : remove this method when LSP4J will provide InlayHint support. See - // https://github.com/eclipse/lsp4j/issues/570 - @JsonRequest("workspace/inlayHint/refresh") - default CompletableFuture refreshInlayHints() { - throw new UnsupportedOperationException(); - } } private final LogHandler logHandler; diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/InlayHintVisitor.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/InlayHintVisitor.java index 7d4c0f2b66..9f425bfd2e 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/InlayHintVisitor.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/InlayHintVisitor.java @@ -40,9 +40,9 @@ import org.eclipse.jdt.core.dom.TypeLiteral; import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin; import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager; +import org.eclipse.lsp4j.InlayHint; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.jsonrpc.messages.Either; -import org.eclipse.lsp4j.proposed.InlayHint; import com.google.common.base.Objects; diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/InlayHintsHandler.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/InlayHintsHandler.java index 32f768ae42..c8e2178ac1 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/InlayHintsHandler.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/InlayHintsHandler.java @@ -26,8 +26,8 @@ import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin; import org.eclipse.jdt.ls.core.internal.JobHelpers; import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager; -import org.eclipse.lsp4j.proposed.InlayHint; -import org.eclipse.lsp4j.proposed.InlayHintParams; +import org.eclipse.lsp4j.InlayHint; +import org.eclipse.lsp4j.InlayHintParams; public class InlayHintsHandler { diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/JDTLanguageServer.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/JDTLanguageServer.java index bc274b8bdc..1e8ae4c9e4 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/JDTLanguageServer.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/JDTLanguageServer.java @@ -117,8 +117,11 @@ import org.eclipse.lsp4j.InitializeParams; import org.eclipse.lsp4j.InitializeResult; import org.eclipse.lsp4j.InitializedParams; +import org.eclipse.lsp4j.InlayHint; +import org.eclipse.lsp4j.InlayHintParams; import org.eclipse.lsp4j.Location; import org.eclipse.lsp4j.LocationLink; +import org.eclipse.lsp4j.PrepareRenameDefaultBehavior; import org.eclipse.lsp4j.PrepareRenameParams; import org.eclipse.lsp4j.PrepareRenameResult; import org.eclipse.lsp4j.Range; @@ -135,18 +138,22 @@ 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; import org.eclipse.lsp4j.WorkspaceSymbolParams; import org.eclipse.lsp4j.extended.ProjectBuildParams; import org.eclipse.lsp4j.extended.ProjectConfigurationsUpdateParam; import org.eclipse.lsp4j.jsonrpc.CompletableFutures; import org.eclipse.lsp4j.jsonrpc.messages.Either; +import org.eclipse.lsp4j.jsonrpc.messages.Either3; import org.eclipse.lsp4j.jsonrpc.services.JsonDelegate; -import org.eclipse.lsp4j.proposed.InlayHint; -import org.eclipse.lsp4j.proposed.InlayHintParams; -import org.eclipse.lsp4j.proposed.InlayHintProvider; import org.eclipse.lsp4j.services.LanguageServer; +import org.eclipse.lsp4j.services.NotebookDocumentService; import org.eclipse.lsp4j.services.TextDocumentService; import org.eclipse.lsp4j.services.WorkspaceService; @@ -155,7 +162,7 @@ * */ public class JDTLanguageServer extends BaseJDTLanguageServer implements LanguageServer, TextDocumentService, WorkspaceService, - JavaProtocolExtensions, InlayHintProvider { + JavaProtocolExtensions { public static final String JAVA_LSP_JOIN_ON_COMPLETION = "java.lsp.joinOnCompletion"; public static final String JAVA_LSP_INITIALIZE_WORKSPACE = "java.lsp.initializeWorkspace"; @@ -480,10 +487,10 @@ public JavaProtocolExtensions getJavaExtensions() { * @see org.eclipse.lsp4j.services.WorkspaceService#symbol(org.eclipse.lsp4j.WorkspaceSymbolParams) */ @Override - public CompletableFuture> symbol(WorkspaceSymbolParams params) { + public CompletableFuture, List>> symbol(WorkspaceSymbolParams params) { logInfo(">> workspace/symbol"); return computeAsync((monitor) -> { - return WorkspaceSymbolHandler.search(params.getQuery(), monitor); + return Either.forLeft(WorkspaceSymbolHandler.search(params.getQuery(), monitor)); }); } @@ -792,12 +799,12 @@ public CompletableFuture> onTypeFormatting(DocumentOnTy * @see org.eclipse.lsp4j.services.TextDocumentService#prepareRename(org.eclipse.lsp4j.PrepareRenameParams) */ @Override - public CompletableFuture> prepareRename(PrepareRenameParams params) { + public CompletableFuture> prepareRename(PrepareRenameParams params) { logInfo(">> document/prepareRename"); PrepareRenameHandler handler = new PrepareRenameHandler(preferenceManager); return computeAsync((monitor) -> { waitForLifecycleJobs(monitor); - return handler.prepareRename(params, monitor); + return Either3.forLeft3(handler.prepareRename(params, monitor)); }); } @@ -1110,4 +1117,26 @@ private void waitForLifecycleJobs(IProgressMonitor monitor) { JobHelpers.waitForJobs(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, monitor); } + /* (non-Javadoc) + * @see org.eclipse.lsp4j.services.LanguageServer#getNotebookDocumentService() + */ + @Override + public NotebookDocumentService getNotebookDocumentService() { + return null; + } + + @Override + public CompletableFuture> prepareTypeHierarchy(TypeHierarchyPrepareParams params) { + return computeAsyncWithClientProgress(monitor -> new TypeHierarchyHandler().prepareTypeHierarchy(params, monitor)); + } + + @Override + public CompletableFuture> typeHierarchySubtypes(TypeHierarchySubtypesParams params) { + return computeAsyncWithClientProgress(monitor -> new TypeHierarchyHandler().callHierarchySubtypes(params, monitor)); + } + + @Override + public CompletableFuture> typeHierarchySupertypes(TypeHierarchySupertypesParams params) { + return computeAsyncWithClientProgress(monitor -> new TypeHierarchyHandler().callHierarchySupertypes(params, monitor)); + } } diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/PrepareRenameHandler.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/PrepareRenameHandler.java index 7d95496588..8f27b98d77 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/PrepareRenameHandler.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/PrepareRenameHandler.java @@ -30,11 +30,9 @@ import org.eclipse.jdt.ls.core.internal.corext.refactoring.RefactoringAvailabilityTester; import org.eclipse.jdt.ls.core.internal.corrections.InnovationContext; import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager; -import org.eclipse.lsp4j.PrepareRenameResult; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.TextDocumentPositionParams; import org.eclipse.lsp4j.jsonrpc.ResponseErrorException; -import org.eclipse.lsp4j.jsonrpc.messages.Either; import org.eclipse.lsp4j.jsonrpc.messages.ResponseError; import org.eclipse.lsp4j.jsonrpc.messages.ResponseErrorCode; @@ -46,8 +44,7 @@ public PrepareRenameHandler(PreferenceManager preferenceManager) { this.preferenceManager = preferenceManager; } - public Either prepareRename(TextDocumentPositionParams params, IProgressMonitor monitor) { - + public Range prepareRename(TextDocumentPositionParams params, IProgressMonitor monitor) { final ICompilationUnit unit = JDTUtils.resolveCompilationUnit(params.getTextDocument().getUri()); if (unit != null) { try { @@ -62,7 +59,7 @@ public Either prepareRename(TextDocumentPositionPara if (occurrences != null) { for (OccurrenceLocation loc : occurrences) { if (monitor.isCanceled()) { - return Either.forLeft(new Range()); + return new Range(); } if (loc.getOffset() <= offset && loc.getOffset() + loc.getLength() >= offset) { // https://github.com/redhat-developer/vscode-java/issues/2805 @@ -80,7 +77,7 @@ public Either prepareRename(TextDocumentPositionPara ASTNode node = context.getCoveredNode(); // Rename package is not fully supported yet. if (!isBinaryOrPackage(node)) { - return Either.forLeft(JDTUtils.toRange(unit, loc.getOffset(), loc.getLength())); + return JDTUtils.toRange(unit, loc.getOffset(), loc.getLength()); } } } diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/commands/TypeHierarchyCommand.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/TypeHierarchyHandler.java similarity index 50% rename from org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/commands/TypeHierarchyCommand.java rename to org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/TypeHierarchyHandler.java index 85edb928bb..9aac33fd54 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/commands/TypeHierarchyCommand.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/TypeHierarchyHandler.java @@ -10,10 +10,11 @@ * Contributors: * Microsoft Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.jdt.ls.core.internal.commands; +package org.eclipse.jdt.ls.core.internal.handlers; -import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Objects; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jdt.core.ICompilationUnit; @@ -32,81 +33,45 @@ import org.eclipse.jdt.ls.core.internal.JDTUtils.LocationType; import org.eclipse.jdt.ls.core.internal.JSONUtility; import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin; -import org.eclipse.jdt.ls.core.internal.handlers.DocumentSymbolHandler; import org.eclipse.lsp4j.Location; import org.eclipse.lsp4j.Position; -import org.eclipse.lsp4j.Range; -import org.eclipse.lsp4j.ResolveTypeHierarchyItemParams; -import org.eclipse.lsp4j.TextDocumentIdentifier; -import org.eclipse.lsp4j.TypeHierarchyDirection; import org.eclipse.lsp4j.TypeHierarchyItem; -import org.eclipse.lsp4j.TypeHierarchyParams; +import org.eclipse.lsp4j.TypeHierarchyPrepareParams; +import org.eclipse.lsp4j.TypeHierarchySubtypesParams; +import org.eclipse.lsp4j.TypeHierarchySupertypesParams; -public class TypeHierarchyCommand { +public class TypeHierarchyHandler { - public TypeHierarchyItem typeHierarchy(TypeHierarchyParams params, IProgressMonitor monitor) { - if (params == null) { - return null; - } - TextDocumentIdentifier textDocument = params.getTextDocument(); - if (textDocument == null) { - return null; - } - Position position = params.getPosition(); - String uri = textDocument.getUri(); - TypeHierarchyDirection direction = params.getDirection(); - int resolve = params.getResolve(); - return getTypeHierarchy(uri, position, direction, resolve, null, monitor); + private static enum TypeHierarchyDirection { + Parents, Children } - public TypeHierarchyItem resolveTypeHierarchy(ResolveTypeHierarchyItemParams params, IProgressMonitor monitor) { - if (params == null) { - return null; - } - TypeHierarchyItem item = params.getItem(); - if (item == null) { - return null; - } - Range range = item.getRange(); - if (range == null) { + public List callHierarchySubtypes(TypeHierarchySubtypesParams params, IProgressMonitor monitor) { + try { + return resolve(params.getItem(), TypeHierarchyDirection.Children, monitor); + } catch (JavaModelException e) { return null; } - Position position = range.getStart(); - String uri = item.getUri(); - TypeHierarchyDirection direction = params.getDirection(); - int resolve = params.getResolve(); - return getTypeHierarchy(uri, position, direction, resolve, item, monitor); } - private TypeHierarchyItem getTypeHierarchy(String uri, Position position, TypeHierarchyDirection direction, int resolve, TypeHierarchyItem itemInput, IProgressMonitor monitor) { - if (uri == null || position == null || direction == null) { - return null; - } + public List callHierarchySupertypes(TypeHierarchySupertypesParams params, IProgressMonitor monitor) { try { - IType type = null; - if (itemInput == null) { - type = getType(uri, position, monitor); - } else { - String handleIdentifier = JSONUtility.toModel(itemInput.getData(), String.class); - IJavaElement element = JavaCore.create(handleIdentifier); - if (element instanceof IType theType) { - type = theType; - } else if (element instanceof IOrdinaryClassFile classFile) { - type = classFile.getType(); - } else { - return null; - } - } - TypeHierarchyItem item = TypeHierarchyCommand.toTypeHierarchyItem(type); - if (item == null) { - return null; - } - resolve(item, type, direction, resolve, monitor); - return item; + return resolve(params.getItem(), TypeHierarchyDirection.Parents, monitor); } catch (JavaModelException e) { return null; } } + private IType getType(TypeHierarchyItem item) { + String handleIdentifier = JSONUtility.toModel(item.getData(), String.class); + IJavaElement element = JavaCore.create(handleIdentifier); + if (element instanceof IType theType) { + return theType; + } else if (element instanceof IOrdinaryClassFile classFile) { + return classFile.getType(); + } else { + return null; + } + } private IType getType(String uri, Position position, IProgressMonitor monitor) throws JavaModelException { IJavaElement typeElement = findTypeElement(JDTUtils.resolveTypeRoot(uri), position, monitor); @@ -143,25 +108,23 @@ private static TypeHierarchyItem toTypeHierarchyItem(IType type) throws JavaMode if (location == null || selectLocation == null) { return null; } - TypeHierarchyItem item = new TypeHierarchyItem(); - item.setRange(location.getRange()); - item.setUri(location.getUri()); - item.setSelectionRange(selectLocation.getRange()); + String name; + String details = null; String fullyQualifiedName = type.getFullyQualifiedName(); int index = fullyQualifiedName.lastIndexOf('.'); if (index >= 1 && index < fullyQualifiedName.length() - 1 && !type.isAnonymous()) { - item.setName(fullyQualifiedName.substring(index + 1)); - item.setDetail(fullyQualifiedName.substring(0, index)); + name = fullyQualifiedName.substring(index + 1); + details = fullyQualifiedName.substring(0, index); } else { - item.setName(JDTUtils.getName(type)); + name = JDTUtils.getName(type); IPackageFragment packageFragment = type.getPackageFragment(); if (packageFragment != null) { - item.setDetail(packageFragment.getElementName()); + details = packageFragment.getElementName(); } } - item.setKind(DocumentSymbolHandler.mapKind(type)); - item.setDeprecated(JDTUtils.isDeprecated(type)); + TypeHierarchyItem item = new TypeHierarchyItem(name, DocumentSymbolHandler.mapKind(type), location.getUri(), location.getRange(), selectLocation.getRange()); item.setData(type.getHandleIdentifier()); + item.setDetail(details); return item; } @@ -173,10 +136,11 @@ private static Location getLocation(IType type, LocationType locationType) throw return location; } - private void resolve(TypeHierarchyItem item, IType type, TypeHierarchyDirection direction, int resolve, IProgressMonitor monitor) throws JavaModelException { - if (monitor.isCanceled() || resolve <= 0) { - return; + private List resolve(TypeHierarchyItem item, TypeHierarchyDirection direction, IProgressMonitor monitor) throws JavaModelException { + if (monitor.isCanceled()) { + return null; } + IType type = getType(item); ITypeHierarchy typeHierarchy; if (direction == TypeHierarchyDirection.Parents) { typeHierarchy = type.newSupertypeHierarchy(DefaultWorkingCopyOwner.PRIMARY, monitor); @@ -184,31 +148,23 @@ private void resolve(TypeHierarchyItem item, IType type, TypeHierarchyDirection ICompilationUnit[] workingCopies = JavaModelManager.getJavaModelManager().getWorkingCopies(DefaultWorkingCopyOwner.PRIMARY, true); typeHierarchy = type.newTypeHierarchy(workingCopies, monitor); } - if (direction == TypeHierarchyDirection.Children || direction == TypeHierarchyDirection.Both) { - List childrenItems = new ArrayList<>(); - IType[] children = typeHierarchy.getSubtypes(type); - for (IType childType : children) { - TypeHierarchyItem childItem = TypeHierarchyCommand.toTypeHierarchyItem(childType); - if (childItem == null) { - continue; - } - resolve(childItem, childType, direction, resolve - 1, monitor); - childrenItems.add(childItem); + return Arrays.stream(direction == TypeHierarchyDirection.Children ? typeHierarchy.getSubtypes(type) : typeHierarchy.getSupertypes(type)).map(t -> { + try { + return toTypeHierarchyItem(t); + } catch (JavaModelException e) { + return null; } - item.setChildren(childrenItems); + }).filter(Objects::nonNull).toList(); + } + + public List prepareTypeHierarchy(TypeHierarchyPrepareParams params, IProgressMonitor monitor) { + if (params.getTextDocument().getUri() == null || params.getPosition() == null) { + return null; } - if (direction == TypeHierarchyDirection.Parents || direction == TypeHierarchyDirection.Both) { - List parentsItems = new ArrayList<>(); - IType[] parents = typeHierarchy.getSupertypes(type); - for (IType parentType : parents) { - TypeHierarchyItem parentItem = TypeHierarchyCommand.toTypeHierarchyItem(parentType); - if (parentItem == null) { - continue; - } - resolve(parentItem, parentType, direction, resolve - 1, monitor); - parentsItems.add(parentItem); - } - item.setParents(parentsItems); + try { + return List.of(TypeHierarchyHandler.toTypeHierarchyItem(getType(params.getTextDocument().getUri(), params.getPosition(), monitor))); + } catch (JavaModelException e) { + return null; } } } diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/StandardProjectsManager.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/StandardProjectsManager.java index 1a935b1748..95c0cb94d2 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/StandardProjectsManager.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/StandardProjectsManager.java @@ -92,6 +92,7 @@ import org.eclipse.lsp4j.MessageType; import org.eclipse.lsp4j.TextDocumentIdentifier; import org.eclipse.lsp4j.WatchKind; +import org.eclipse.lsp4j.jsonrpc.messages.Either; import org.xml.sax.InputSource; public class StandardProjectsManager extends ProjectsManager { @@ -507,14 +508,13 @@ public List registerWatchers() { } patterns.addAll(sources.stream().map(p -> ResourceUtils.toGlobPattern(p, false)).collect(Collectors.toList())); for (String pattern : patterns) { - FileSystemWatcher watcher = new FileSystemWatcher(pattern); + FileSystemWatcher watcher = new FileSystemWatcher(Either.forLeft(pattern)); fileWatchers.add(watcher); } // Watch on project root folders. for (IProject project : projects) { if (ProjectUtils.isVisibleProject(project) && project.exists()) { - FileSystemWatcher watcher = new FileSystemWatcher( - ResourceUtils.toGlobPattern(project.getLocation(), false), WatchKind.Delete); + FileSystemWatcher watcher = new FileSystemWatcher(Either.forLeft(ResourceUtils.toGlobPattern(project.getLocation(), false)), WatchKind.Delete); fileWatchers.add(watcher); } } diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/ClientPreferences.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/ClientPreferences.java index 5c0fdbe173..3de748e9c6 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/ClientPreferences.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/ClientPreferences.java @@ -283,11 +283,6 @@ public boolean isSupportsCompletionDocumentationMarkdown() { //@formatter:on } - @Deprecated - public boolean isWorkspaceEditResourceChangesSupported() { - return capabilities.getWorkspace() != null && capabilities.getWorkspace().getWorkspaceEdit() != null && isTrue(capabilities.getWorkspace().getWorkspaceEdit().getResourceChanges()); - } - public boolean isResourceOperationSupported() { //@formatter:off return capabilities.getWorkspace() != null diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/syntaxserver/SyntaxProjectsManager.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/syntaxserver/SyntaxProjectsManager.java index 9571359220..b5fac45d4c 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/syntaxserver/SyntaxProjectsManager.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/syntaxserver/SyntaxProjectsManager.java @@ -54,6 +54,7 @@ import org.eclipse.jdt.ls.core.internal.preferences.Preferences; import org.eclipse.lsp4j.DidChangeWatchedFilesRegistrationOptions; import org.eclipse.lsp4j.FileSystemWatcher; +import org.eclipse.lsp4j.jsonrpc.messages.Either; public class SyntaxProjectsManager extends ProjectsManager { //@formatter:off @@ -138,12 +139,12 @@ public List registerWatchers() { List fileWatchers = new ArrayList<>(); Set patterns = new LinkedHashSet<>(basicWatchers); patterns.addAll(Stream.of(sources).map(ResourceUtils::toGlobPattern).collect(Collectors.toList())); - + for (String pattern : patterns) { - FileSystemWatcher watcher = new FileSystemWatcher(pattern); + FileSystemWatcher watcher = new FileSystemWatcher(Either.forLeft(pattern)); fileWatchers.add(watcher); } - + if (!patterns.equals(watchers)) { JavaLanguageServerPlugin.logInfo(">> registerFeature 'workspace/didChangeWatchedFiles'"); DidChangeWatchedFilesRegistrationOptions didChangeWatchedFilesRegistrationOptions = new DidChangeWatchedFilesRegistrationOptions(fileWatchers); @@ -159,7 +160,7 @@ public List registerWatchers() { return Collections.emptyList(); } - + private static IPath[] listAllSourcePaths() throws JavaModelException { Set classpaths = new HashSet<>(); IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHint.java b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHint.java deleted file mode 100644 index 64f0a1b7f5..0000000000 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHint.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2022 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.lsp4j.proposed; - -import java.util.List; - -import org.eclipse.lsp4j.Position; -import org.eclipse.lsp4j.jsonrpc.messages.Either; -import org.eclipse.lsp4j.jsonrpc.validation.NonNull; -import org.eclipse.lsp4j.util.Preconditions; - -/** - * Inlay hint information. - * - * @since 3.17.0 - proposed state - */ -public class InlayHint { - - /** - * The position of this hint. - */ - @NonNull - private Position position; - - /** - * The label of this hint. A human readable string or an array of - * InlayHintLabelPart label parts. - * - * *Note* that neither the string nor the label part can be empty. - */ - @NonNull - private Either> label; - - /** - * The kind of this hint. Can be omitted in which case the client should fall - * back to a reasonable default. - */ - private InlayHintKind kind; - - public InlayHint(@NonNull Position position, Either> label) { - this.position = Preconditions.checkNotNull(position, "position"); - this.label = label; - - } - - public InlayHint() { - - } - - public Position getPosition() { - return position; - } - - public void setPosition(Position position) { - this.position = position; - } - - public Either> getLabel() { - return label; - } - - public void setLabel(Either> label) { - this.label = label; - } - - public InlayHintKind getKind() { - return kind; - } - - public void setKind(InlayHintKind kind) { - this.kind = kind; - } -} diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHintKind.java b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHintKind.java deleted file mode 100644 index 7de5d4f191..0000000000 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHintKind.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2022 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.lsp4j.proposed; - -public enum InlayHintKind { - - /** - * An inlay hint that for a type annotation. - */ - Type(1), - - /** - * An inlay hint that is for a parameter. - */ - Parameter(2); - - private final int value; - - InlayHintKind(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - - public static InlayHintKind forValue(int value) { - InlayHintKind[] allValues = InlayHintKind.values(); - if (value < 1 || value > allValues.length) - throw new IllegalArgumentException("Illegal enum value: " + value); - return allValues[value - 1]; - } -} diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHintLabelPart.java b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHintLabelPart.java deleted file mode 100644 index 327a03d49a..0000000000 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHintLabelPart.java +++ /dev/null @@ -1,17 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2022 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.lsp4j.proposed; - -public class InlayHintLabelPart { -} diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHintParams.java b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHintParams.java deleted file mode 100644 index a52730e012..0000000000 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHintParams.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2022 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.lsp4j.proposed; - -import org.eclipse.lsp4j.Range; -import org.eclipse.lsp4j.TextDocumentIdentifier; -import org.eclipse.lsp4j.WorkDoneProgressParams; -import org.eclipse.lsp4j.jsonrpc.messages.Either; -import org.eclipse.lsp4j.jsonrpc.validation.NonNull; -import org.eclipse.lsp4j.util.Preconditions; -import org.eclipse.xtext.xbase.lib.Pure; - -public class InlayHintParams implements WorkDoneProgressParams { - - /** - * An optional token that a server can use to report work done progress. - */ - private Either workDoneToken; - - /** - * The document to format. - */ - @NonNull - private TextDocumentIdentifier textDocument; - - /** - * The visible document range for which inlay hints should be computed. - */ - @NonNull - private Range range; - - /** - * An optional token that a server can use to report work done progress. - */ - @Pure - @Override - public Either getWorkDoneToken() { - return this.workDoneToken; - } - - /** - * An optional token that a server can use to report work done progress. - */ - public void setWorkDoneToken(final Either workDoneToken) { - this.workDoneToken = workDoneToken; - } - - public void setWorkDoneToken(final String workDoneToken) { - if (workDoneToken == null) { - this.workDoneToken = null; - return; - } - this.workDoneToken = Either.forLeft(workDoneToken); - } - - /** - * The document to format. - */ - @Pure - @NonNull - public TextDocumentIdentifier getTextDocument() { - return this.textDocument; - } - - /** - * The document to format. - */ - public void setTextDocument(@NonNull final TextDocumentIdentifier textDocument) { - this.textDocument = Preconditions.checkNotNull(textDocument, "textDocument"); - } - - public void setWorkDoneToken(final Integer workDoneToken) { - if (workDoneToken == null) { - this.workDoneToken = null; - return; - } - this.workDoneToken = Either.forRight(workDoneToken); - } - - /** - * Returns the visible document range for which inlay hints should be computed. - * - * @return the visible document range for which inlay hints should be computed. - */ - @Pure - @NonNull - public Range getRange() { - return range; - } - - /** - * Set the visible document range for which inlay hints should be computed. - * - * @param range - */ - public void setRange(@NonNull Range range) { - this.range = Preconditions.checkNotNull(range, "range"); - } -} diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHintProvider.java b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHintProvider.java deleted file mode 100644 index 09a87e3aee..0000000000 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/proposed/InlayHintProvider.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2022 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.lsp4j.proposed; - -import java.util.List; -import java.util.concurrent.CompletableFuture; - -import org.eclipse.lsp4j.jsonrpc.services.JsonRequest; - -public interface InlayHintProvider { - - @JsonRequest("textDocument/inlayHint") - default CompletableFuture> inlayHint(InlayHintParams params) { - throw new UnsupportedOperationException(); - } - -} diff --git a/org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target b/org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target index 419a52ad05..1a650924f1 100644 --- a/org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target +++ b/org.eclipse.jdt.ls.target/org.eclipse.jdt.ls.tp.target @@ -3,8 +3,6 @@ - - @@ -33,10 +31,10 @@ - + - + diff --git a/org.eclipse.jdt.ls.tests.syntaxserver/META-INF/MANIFEST.MF b/org.eclipse.jdt.ls.tests.syntaxserver/META-INF/MANIFEST.MF index 8932fe10d5..d5860cb19a 100644 --- a/org.eclipse.jdt.ls.tests.syntaxserver/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.ls.tests.syntaxserver/META-INF/MANIFEST.MF @@ -18,8 +18,8 @@ Require-Bundle: org.eclipse.jdt.ls.core, org.apache.commons.io;bundle-version="2.2.0", org.apache.commons.lang3;bundle-version="3.1.0", com.google.gson;bundle-version="2.7.0", - org.eclipse.lsp4j;bundle-version="[0.12.0,0.13.0)", - org.eclipse.lsp4j.jsonrpc;bundle-version="[0.12.0,0.13.0)", + org.eclipse.lsp4j;bundle-version="[0.19.0,0.20.0)", + org.eclipse.lsp4j.jsonrpc;bundle-version="[0.19.0,0.20.0)", org.eclipse.xtend.lib, org.eclipse.xtext.xbase.lib, org.eclipse.jdt.launching, diff --git a/org.eclipse.jdt.ls.tests/META-INF/MANIFEST.MF b/org.eclipse.jdt.ls.tests/META-INF/MANIFEST.MF index b972c6d2e0..34e34709b5 100644 --- a/org.eclipse.jdt.ls.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.ls.tests/META-INF/MANIFEST.MF @@ -1,5 +1,6 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 +Automatic-Module-Name: org.eclipse.jdt.ls.tests Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.eclipse.jdt.ls.tests;singleton:=true Bundle-Version: 1.20.0.qualifier @@ -23,8 +24,8 @@ Require-Bundle: org.eclipse.jdt.ls.core, org.eclipse.buildship.core;bundle-version="1.0.18", org.apache.commons.lang3;bundle-version="3.1.0", com.google.gson;bundle-version="2.7.0", - org.eclipse.lsp4j;bundle-version="[0.12.0,0.13.0)", - org.eclipse.lsp4j.jsonrpc;bundle-version="[0.12.0,0.13.0)", + org.eclipse.lsp4j;bundle-version="[0.19.0,0.20.0)", + org.eclipse.lsp4j.jsonrpc;bundle-version="[0.19.0,0.20.0)", org.eclipse.xtend.lib, org.eclipse.xtext.xbase.lib, org.eclipse.jdt.launching, diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/commands/TypeHierarchyCommandTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/commands/TypeHierarchyCommandTest.java index f96813b79d..60b2c92cce 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/commands/TypeHierarchyCommandTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/commands/TypeHierarchyCommandTest.java @@ -14,7 +14,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.util.List; @@ -22,92 +22,79 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jdt.ls.core.internal.WorkspaceHelper; +import org.eclipse.jdt.ls.core.internal.handlers.TypeHierarchyHandler; import org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.TextDocumentIdentifier; -import org.eclipse.lsp4j.TypeHierarchyDirection; import org.eclipse.lsp4j.TypeHierarchyItem; -import org.eclipse.lsp4j.TypeHierarchyParams; +import org.eclipse.lsp4j.TypeHierarchyPrepareParams; +import org.eclipse.lsp4j.TypeHierarchySubtypesParams; +import org.eclipse.lsp4j.TypeHierarchySupertypesParams; import org.junit.Before; import org.junit.Test; public class TypeHierarchyCommandTest extends AbstractInvisibleProjectBasedTest { private IProject fJProject; - private TypeHierarchyCommand fCommand; + private TypeHierarchyHandler fCommand; + private final IProgressMonitor monitor = new NullProgressMonitor(); @Before public void setup() throws Exception { importProjects("maven/salut"); fJProject = WorkspaceHelper.getProject("salut"); - fCommand = new TypeHierarchyCommand(); + fCommand = new TypeHierarchyHandler(); } @Test public void testTypeHierarchy() throws Exception { - IProgressMonitor monitor = new NullProgressMonitor(); - TypeHierarchyParams params = new TypeHierarchyParams(); String uriString = fJProject.getFile("src/main/java/org/sample/TestJavadoc.java").getLocationURI().toString(); TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString); Position position = new Position(4, 20); - params.setTextDocument(identifier); - params.setResolve(1); - params.setDirection(TypeHierarchyDirection.Both); - params.setPosition(position); - TypeHierarchyItem item = fCommand.typeHierarchy(params, monitor); + TypeHierarchyItem item = fCommand.prepareTypeHierarchy(new TypeHierarchyPrepareParams(identifier, position), monitor).get(0); assertNotNull(item); assertEquals(item.getName(), "TestJavadoc"); - assertNotNull(item.getChildren()); - assertEquals(item.getChildren().size(), 0); - assertNotNull(item.getParents()); - assertEquals(item.getParents().size(), 1); - assertEquals(item.getParents().get(0).getName(), "Object"); + List children = fCommand.callHierarchySubtypes(new TypeHierarchySubtypesParams(item), monitor); + assertNotNull(children); + assertEquals(children.size(), 0); + List parents = fCommand.callHierarchySupertypes(new TypeHierarchySupertypesParams(item), monitor); + assertNotNull(parents); + assertEquals(parents.size(), 1); + assertEquals(parents.get(0).getName(), "Object"); } @Test public void testSuperTypeHierarchy() throws Exception { - IProgressMonitor monitor = new NullProgressMonitor(); - TypeHierarchyParams params = new TypeHierarchyParams(); String uriString = fJProject.getFile("src/main/java/org/sample/CallHierarchy.java").getLocationURI().toString(); TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString); Position position = new Position(7, 27); - params.setTextDocument(identifier); - params.setResolve(1); - params.setDirection(TypeHierarchyDirection.Parents); - params.setPosition(position); - TypeHierarchyItem item = fCommand.typeHierarchy(params, monitor); + TypeHierarchyItem item = fCommand.prepareTypeHierarchy(new TypeHierarchyPrepareParams(identifier, position), monitor).get(0); assertNotNull(item); assertEquals(item.getName(), "CallHierarchy$FooBuilder"); - assertNull(item.getChildren()); - assertEquals(item.getParents().size(), 2); - TypeHierarchyItem builder = item.getParents().get(0); + List parents = fCommand.callHierarchySupertypes(new TypeHierarchySupertypesParams(item), monitor); + assertEquals(parents.size(), 2); + TypeHierarchyItem builder = parents.get(0); assertNotNull(builder); assertEquals(builder.getName(), "Builder"); - assertNull(builder.getParents()); - TypeHierarchyItem object = item.getParents().get(1); + TypeHierarchyItem object = parents.get(1); assertNotNull(object); assertEquals(object.getName(), "Object"); - assertNull(object.getParents()); + List objectParents = fCommand.callHierarchySupertypes(new TypeHierarchySupertypesParams(object), monitor); + assertTrue(objectParents.isEmpty()); } @Test public void testSubTypeHierarchy() throws Exception { - IProgressMonitor monitor = new NullProgressMonitor(); - TypeHierarchyParams params = new TypeHierarchyParams(); String uriString = fJProject.getFile("src/main/java/org/sample/CallHierarchy.java").getLocationURI().toString(); TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString); Position position = new Position(2, 43); - params.setTextDocument(identifier); - params.setResolve(2); - params.setDirection(TypeHierarchyDirection.Children); - params.setPosition(position); - TypeHierarchyItem item = fCommand.typeHierarchy(params, monitor); + TypeHierarchyItem item = fCommand.prepareTypeHierarchy(new TypeHierarchyPrepareParams(identifier, position), monitor).get(0); assertNotNull(item); assertEquals(item.getName(), "Builder"); - assertNull(item.getParents()); - assertEquals(item.getChildren().size(), 9); - for (TypeHierarchyItem child : item.getChildren()) { - List subChild = child.getChildren(); + List children = fCommand.callHierarchySubtypes(new TypeHierarchySubtypesParams(item), monitor); + assertEquals(children.size(), 9); + for (TypeHierarchyItem child : children) { + List subChild = fCommand.callHierarchySubtypes(new TypeHierarchySubtypesParams(child), monitor); assertNotNull(subChild); if (subChild.size() == 1) { assertEquals(subChild.get(0).getName(), "ReflectionToStringBuilder"); @@ -121,19 +108,15 @@ public void testMultipleProjects() throws Exception { importProjects("eclipse/gh2871"); IProject project = WorkspaceHelper.getProject("project1"); IProgressMonitor monitor = new NullProgressMonitor(); - TypeHierarchyParams params = new TypeHierarchyParams(); String uriString = project.getFile("src/org/sample/First.java").getLocationURI().toString(); TextDocumentIdentifier identifier = new TextDocumentIdentifier(uriString); Position position = new Position(1, 22); - params.setTextDocument(identifier); - params.setResolve(1); - params.setDirection(TypeHierarchyDirection.Both); - params.setPosition(position); - TypeHierarchyItem item = fCommand.typeHierarchy(params, monitor); + TypeHierarchyItem item = fCommand.prepareTypeHierarchy(new TypeHierarchyPrepareParams(identifier, position), monitor).get(0); assertNotNull(item); assertEquals(item.getName(), "First"); - assertNotNull(item.getChildren()); - assertEquals(item.getChildren().size(), 1); - assertEquals(item.getChildren().get(0).getName(), "Second"); + List children = fCommand.callHierarchySubtypes(new TypeHierarchySubtypesParams(item), monitor); + assertNotNull(children); + assertEquals(children.size(), 1); + assertEquals(children.get(0).getName(), "Second"); } } diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/InitHandlerTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/InitHandlerTest.java index 4946b077c5..ca18173d1c 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/InitHandlerTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/InitHandlerTest.java @@ -38,6 +38,7 @@ import java.util.Random; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import java.util.function.Function; import java.util.stream.Collectors; import org.apache.commons.io.FileUtils; @@ -78,6 +79,7 @@ import org.eclipse.lsp4j.InitializeParams; import org.eclipse.lsp4j.InitializeResult; import org.eclipse.lsp4j.InitializedParams; +import org.eclipse.lsp4j.RelativePattern; import org.eclipse.lsp4j.SynchronizationCapabilities; import org.eclipse.lsp4j.TextDocumentClientCapabilities; import org.eclipse.lsp4j.TextDocumentSyncKind; @@ -316,28 +318,22 @@ public void testWatchers() throws Exception { // 8 basic + 3 project roots assertEquals("Unexpected watchers:\n" + toString(watchers), 12, watchers.size()); List projectWatchers = watchers.subList(9, 12); - assertTrue(projectWatchers.get(0).getGlobPattern().endsWith("/TestProject")); + assertTrue(projectWatchers.get(0).getGlobPattern().map(Function.identity(), RelativePattern::getPattern).endsWith("/TestProject")); assertTrue(WatchKind.Delete == projectWatchers.get(0).getKind()); - assertTrue(projectWatchers.get(1).getGlobPattern().endsWith("/maven/salut")); - assertTrue(projectWatchers.get(2).getGlobPattern().endsWith("/gradle/simple-gradle")); + assertTrue(projectWatchers.get(1).getGlobPattern().map(Function.identity(), RelativePattern::getPattern).endsWith("/maven/salut")); + assertTrue(projectWatchers.get(2).getGlobPattern().map(Function.identity(), RelativePattern::getPattern).endsWith("/gradle/simple-gradle")); watchers = watchers.subList(0, 9); - Collections.sort(watchers, new Comparator() { - - @Override - public int compare(FileSystemWatcher o1, FileSystemWatcher o2) { - return o1.getGlobPattern().compareTo(o2.getGlobPattern()); - } - }); - assertEquals("**/*.gradle", watchers.get(0).getGlobPattern()); - assertEquals("**/*.gradle.kts", watchers.get(1).getGlobPattern()); - assertEquals("**/*.java", watchers.get(2).getGlobPattern()); - assertEquals("**/.classpath", watchers.get(3).getGlobPattern()); - assertEquals("**/.project", watchers.get(4).getGlobPattern()); - assertEquals("**/.settings/*.prefs", watchers.get(5).getGlobPattern()); - assertEquals("**/gradle.properties", watchers.get(6).getGlobPattern()); - assertEquals("**/pom.xml", watchers.get(7).getGlobPattern()); - assertEquals("**/src/**", watchers.get(8).getGlobPattern()); + Collections.sort(watchers, Comparator.comparing(fileSystemWatcher -> fileSystemWatcher.getGlobPattern().map(Function.identity(), RelativePattern::getPattern))); + assertEquals("**/*.gradle", watchers.get(0).getGlobPattern().map(Function.identity(), RelativePattern::getPattern)); + assertEquals("**/*.gradle.kts", watchers.get(1).getGlobPattern().map(Function.identity(), RelativePattern::getPattern)); + assertEquals("**/*.java", watchers.get(2).getGlobPattern().map(Function.identity(), RelativePattern::getPattern)); + assertEquals("**/.classpath", watchers.get(3).getGlobPattern().map(Function.identity(), RelativePattern::getPattern)); + assertEquals("**/.project", watchers.get(4).getGlobPattern().map(Function.identity(), RelativePattern::getPattern)); + assertEquals("**/.settings/*.prefs", watchers.get(5).getGlobPattern().map(Function.identity(), RelativePattern::getPattern)); + assertEquals("**/gradle.properties", watchers.get(6).getGlobPattern().map(Function.identity(), RelativePattern::getPattern)); + assertEquals("**/pom.xml", watchers.get(7).getGlobPattern().map(Function.identity(), RelativePattern::getPattern)); + assertEquals("**/src/**", watchers.get(8).getGlobPattern().map(Function.identity(), RelativePattern::getPattern)); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("salut"); String location = project.getLocation().toString(); IJavaProject javaProject = JavaCore.create(project); @@ -362,18 +358,12 @@ public int compare(FileSystemWatcher o1, FileSystemWatcher o2) { verify(client, times(1)).registerCapability(any()); assertEquals("Unexpected watchers:\n" + toString(watchers), 12, newWatchers.size()); projectWatchers = newWatchers.subList(9, 12); - assertTrue(projectWatchers.get(0).getGlobPattern().endsWith("/TestProject")); - assertTrue(projectWatchers.get(1).getGlobPattern().endsWith("/maven/salut")); - assertTrue(projectWatchers.get(2).getGlobPattern().endsWith("/gradle/simple-gradle")); + assertTrue(projectWatchers.get(0).getGlobPattern().map(Function.identity(), RelativePattern::getPattern).endsWith("/TestProject")); + assertTrue(projectWatchers.get(1).getGlobPattern().map(Function.identity(), RelativePattern::getPattern).endsWith("/maven/salut")); + assertTrue(projectWatchers.get(2).getGlobPattern().map(Function.identity(), RelativePattern::getPattern).endsWith("/gradle/simple-gradle")); newWatchers = watchers.subList(0, 9); - Collections.sort(newWatchers, new Comparator() { - - @Override - public int compare(FileSystemWatcher o1, FileSystemWatcher o2) { - return o1.getGlobPattern().compareTo(o2.getGlobPattern()); - } - }); + Collections.sort(newWatchers, Comparator.comparing(fileSystemWatcher -> fileSystemWatcher.getGlobPattern().map(Function.identity(), RelativePattern::getPattern))); assertEquals(newWatchers, watchers); } @@ -398,7 +388,7 @@ public void testSettingsWatchers() throws Exception { } private String toString(List watchers) { - return watchers.stream().map(FileSystemWatcher::getGlobPattern).collect(Collectors.joining("\n")); + return watchers.stream().map(FileSystemWatcher::getGlobPattern).map(globPattern -> globPattern.map(Function.identity(), RelativePattern::getPattern)).collect(Collectors.joining("\n")); } @Test diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/InlayHintHandlerTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/InlayHintHandlerTest.java index eab88d5046..f662b69e67 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/InlayHintHandlerTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/InlayHintHandlerTest.java @@ -26,11 +26,11 @@ import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.ls.core.internal.WorkspaceHelper; +import org.eclipse.lsp4j.InlayHint; +import org.eclipse.lsp4j.InlayHintParams; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.TextDocumentIdentifier; -import org.eclipse.lsp4j.proposed.InlayHint; -import org.eclipse.lsp4j.proposed.InlayHintParams; import org.junit.Test; public class InlayHintHandlerTest extends AbstractCompilationUnitBasedTest { diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/PrepareRenameHandlerTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/PrepareRenameHandlerTest.java index 8174b2260a..628ed069c4 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/PrepareRenameHandlerTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/PrepareRenameHandlerTest.java @@ -415,6 +415,6 @@ private Either prepareRename(ICompilationUnit cu, Po TextDocumentIdentifier identifier = new TextDocumentIdentifier(JDTUtils.toURI(cu)); TextDocumentPositionParams params = new TextDocumentPositionParams(identifier, pos); - return handler.prepareRename(params, monitor); + return Either.forLeft(handler.prepareRename(params, monitor)); } } diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/EclipseProjectImporterTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/EclipseProjectImporterTest.java index 072c7e5fa2..e5eda89288 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/EclipseProjectImporterTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/EclipseProjectImporterTest.java @@ -26,6 +26,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.function.Function; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspace; @@ -38,6 +39,7 @@ import org.eclipse.jdt.ls.core.internal.ResourceUtils; import org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences; import org.eclipse.lsp4j.FileSystemWatcher; +import org.eclipse.lsp4j.RelativePattern; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -234,7 +236,7 @@ public void importJavaProjectWithRootSource() throws Exception { assertIsJavaProject(project); List watchers = projectsManager.registerWatchers(); assertEquals(11, watchers.size()); - String srcGlobPattern = watchers.get(9).getGlobPattern(); + String srcGlobPattern = watchers.get(9).getGlobPattern().map(Function.identity(), RelativePattern::getPattern); assertTrue("Unexpected source glob pattern: " + srcGlobPattern, srcGlobPattern.endsWith("projectwithrootsource/**")); } diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporterTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporterTest.java index 2eb220e0a9..6605da5028 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporterTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/InvisibleProjectImporterTest.java @@ -27,6 +27,7 @@ import java.util.EnumSet; import java.util.List; import java.util.Set; +import java.util.function.Function; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -52,6 +53,7 @@ import org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences; import org.eclipse.jdt.ls.core.internal.preferences.Preferences; import org.eclipse.lsp4j.FileSystemWatcher; +import org.eclipse.lsp4j.RelativePattern; import org.junit.Test; public class InvisibleProjectImporterTest extends AbstractInvisibleProjectBasedTest { @@ -115,11 +117,13 @@ public void automaticJarDetectionLibUnderSource() throws Exception { List watchers = projectsManager.registerWatchers(); //watchers.sort((a, b) -> a.getGlobPattern().compareTo(b.getGlobPattern())); assertEquals(12, watchers.size()); // basic(9) + project(1) + library(1) - String srcGlobPattern = watchers.stream().filter(w -> "**/src/**".equals(w.getGlobPattern())).findFirst().get().getGlobPattern(); + String srcGlobPattern = watchers.stream().map(FileSystemWatcher::getGlobPattern).map(globPattern -> globPattern.map(Function.identity(), RelativePattern::getPattern)).filter("**/src/**"::equals).findFirst().get(); assertTrue("Unexpected source glob pattern: " + srcGlobPattern, srcGlobPattern.equals("**/src/**")); - String projGlobPattern = watchers.stream().filter(w -> w.getGlobPattern().endsWith(projectFolder.getName() + "/**")).findFirst().get().getGlobPattern(); + String projGlobPattern = watchers.stream().map(FileSystemWatcher::getGlobPattern).map(globPattern -> globPattern.map(Function.identity(), RelativePattern::getPattern)).filter(w -> w.endsWith(projectFolder.getName() + "/**")) + .findFirst().get(); assertTrue("Unexpected project glob pattern: " + projGlobPattern, projGlobPattern.endsWith(projectFolder.getName() + "/**")); - String libGlobPattern = watchers.stream().filter(w -> w.getGlobPattern().endsWith(projectFolder.getName() + "/lib/**")).findFirst().get().getGlobPattern(); + String libGlobPattern = watchers.stream().map(FileSystemWatcher::getGlobPattern).map(globPattern -> globPattern.map(Function.identity(), RelativePattern::getPattern)).filter(w -> w.endsWith(projectFolder.getName() + "/lib/**")) + .findFirst().get(); assertTrue("Unexpected library glob pattern: " + libGlobPattern, libGlobPattern.endsWith(projectFolder.getName() + "/lib/**")); } @@ -140,11 +144,11 @@ public void automaticJarDetection() throws Exception { assertEquals("foo-sources.jar", classpath[2].getSourceAttachmentPath().lastSegment()); List watchers = projectsManager.registerWatchers(); - watchers.sort((a, b) -> a.getGlobPattern().compareTo(b.getGlobPattern())); + watchers.sort((a, b) -> a.getGlobPattern().map(Function.identity(), RelativePattern::getPattern).compareTo(b.getGlobPattern().map(Function.identity(), RelativePattern::getPattern))); assertEquals(10, watchers.size()); - String srcGlobPattern = watchers.get(7).getGlobPattern(); + String srcGlobPattern = watchers.get(7).getGlobPattern().map(Function.identity(), RelativePattern::getPattern); assertTrue("Unexpected source glob pattern: " + srcGlobPattern, srcGlobPattern.equals("**/src/**")); - String libGlobPattern = watchers.get(9).getGlobPattern(); + String libGlobPattern = watchers.get(9).getGlobPattern().map(Function.identity(), RelativePattern::getPattern); assertTrue("Unexpected lib glob pattern: " + libGlobPattern, libGlobPattern.endsWith(projectFolder.getName() + "/lib/**")); }