From c13e9caada905ce96b5e94fee36b0ca9f6e1900f Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Thu, 23 Feb 2023 04:53:45 +0100 Subject: [PATCH] Use LSP4J 0.20.0 (#2417) * Onboard legacy TypeHierarchy API * Bump versions & adopt new APIs (eg remap globPatterns to String) * Remove custom inlayHints, use standard * Declare null notebook service --- org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF | 14 +- .../internal/JDTDelegateCommandHandler.java | 8 +- .../core/internal/JavaClientConnection.java | 10 - .../commands/TypeHierarchyCommand.java | 8 +- .../internal/handlers/InlayHintVisitor.java | 2 +- .../internal/handlers/InlayHintsHandler.java | 4 +- .../internal/handlers/JDTLanguageServer.java | 26 +- .../handlers/PrepareRenameHandler.java | 9 +- .../managers/StandardProjectsManager.java | 6 +- .../preferences/ClientPreferences.java | 5 - .../syntaxserver/SyntaxProjectsManager.java | 7 +- .../eclipse/lsp4j/legacy/typeHierarchy/ABOUT | 2 + .../ResolveTypeHierarchyItemParams.java | 154 +++++++ .../TypeHierarchyCapabilities.java | 69 ++++ .../typeHierarchy/TypeHierarchyDirection.java | 57 +++ .../typeHierarchy/TypeHierarchyItem.java | 390 ++++++++++++++++++ .../typeHierarchy/TypeHierarchyParams.java | 116 ++++++ .../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 | 6 +- .../internal/handlers/InitHandlerTest.java | 50 +-- .../handlers/InlayHintHandlerTest.java | 4 +- .../handlers/PrepareRenameHandlerTest.java | 2 +- .../managers/EclipseProjectImporterTest.java | 4 +- .../InvisibleProjectImporterTest.java | 16 +- 31 files changed, 880 insertions(+), 387 deletions(-) create mode 100644 org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/ABOUT create mode 100644 org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/ResolveTypeHierarchyItemParams.java create mode 100644 org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyCapabilities.java create mode 100644 org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyDirection.java create mode 100644 org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyItem.java create mode 100644 org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyParams.java 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 5334ed9235..5f40ffa9c6 100644 --- a/org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF @@ -25,13 +25,14 @@ 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.20.0.0,0.21.0)", + org.eclipse.lsp4j.jsonrpc;bundle-version="[0.20.0,0.21.0)", org.eclipse.xtext.xbase.lib, org.eclipse.core.filesystem;bundle-version="1.7.0", org.eclipse.jdt.apt.pluggable.core;bundle-version="1.2.0";resolution:=optional, org.eclipse.m2e.apt.core;bundle-version="1.3.0";resolution:=optional -Export-Package: org.eclipse.jdt.ls.core.internal;x-friends:="org.eclipse.jdt.ls.tests,org.eclipse.jdt.ls.tests.syntaxserver", +Export-Package: org.eclipse.jdt.ls.core.contentassist;x-friends:="org.eclipse.jdt.ls.tests", + org.eclipse.jdt.ls.core.internal;x-friends:="org.eclipse.jdt.ls.tests,org.eclipse.jdt.ls.tests.syntaxserver", org.eclipse.jdt.ls.core.internal.cleanup;x-friends:="org.eclipse.jdt.ls.tests", org.eclipse.jdt.ls.core.internal.codemanipulation;x-friends:="org.eclipse.jdt.ls.tests", org.eclipse.jdt.ls.core.internal.commands;x-friends:="org.eclipse.jdt.ls.tests", @@ -46,20 +47,19 @@ Export-Package: org.eclipse.jdt.ls.core.internal;x-friends:="org.eclipse.jdt.ls. org.eclipse.jdt.ls.core.internal.corext.util;x-internal:=true, org.eclipse.jdt.ls.core.internal.corrections;x-internal:=true, org.eclipse.jdt.ls.core.internal.corrections.proposals;x-internal:=true, + org.eclipse.jdt.ls.core.internal.framework.protobuf;x-friends:="org.eclipse.jdt.ls.tests", org.eclipse.jdt.ls.core.internal.handlers;x-friends:="org.eclipse.jdt.ls.tests", org.eclipse.jdt.ls.core.internal.hover;x-friends:="org.eclipse.jdt.ls.tests", org.eclipse.jdt.ls.core.internal.javadoc;x-friends:="org.eclipse.jdt.ls.tests", org.eclipse.jdt.ls.core.internal.lsp;x-friends:="org.eclipse.jdt.ls.tests", org.eclipse.jdt.ls.core.internal.managers;x-friends:="org.eclipse.jdt.ls.tests,org.eclipse.jdt.ls.tests.syntaxserver", - org.eclipse.jdt.ls.core.internal.framework.protobuf;x-friends:="org.eclipse.jdt.ls.tests", org.eclipse.jdt.ls.core.internal.preferences;x-friends:="org.eclipse.jdt.ls.tests,org.eclipse.jdt.ls.tests.syntaxserver", org.eclipse.jdt.ls.core.internal.semantictokens;x-friends:="org.eclipse.jdt.ls.tests", 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.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" + org.eclipse.lsp4j.extended;x-friends:="org.eclipse.jdt.ls.tests", + org.eclipse.lsp4j.legacy.typeHierarchy;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..bbc30dc9cd 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 @@ -36,13 +36,13 @@ 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; +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 { 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..a53b232029 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; @@ -221,8 +213,6 @@ public List configuration(ConfigurationParams configurationParams) { return this.client.configuration(configurationParams).join(); } - // TODO : remove this method when LSP4J will provide InlayHint support. See - // https://github.com/eclipse/lsp4j/issues/570 public CompletableFuture refreshInlayHints() { return this.client.refreshInlayHints(); } 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/commands/TypeHierarchyCommand.java index 85edb928bb..7bfd5fa2c4 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/commands/TypeHierarchyCommand.java @@ -36,11 +36,11 @@ 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.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 TypeHierarchyCommand { 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 f696851a04..473bd364fd 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 @@ -119,8 +119,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; @@ -139,16 +142,16 @@ import org.eclipse.lsp4j.TypeDefinitionParams; 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; @@ -157,7 +160,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"; @@ -482,10 +485,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)); }); } @@ -788,12 +791,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)); }); } @@ -1112,4 +1115,11 @@ 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; + } } 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/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 1402b539ee..77c5a5c3f8 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 @@ -287,11 +287,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..e62e08cf14 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,9 +139,9 @@ 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); } @@ -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/legacy/typeHierarchy/ABOUT b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/ABOUT new file mode 100644 index 0000000000..953d69d44f --- /dev/null +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/ABOUT @@ -0,0 +1,2 @@ +These files are extracted from lsp4j-0.12.0-sources.jar. +They're still used by JDT-LS but aren't supported by newer LSP/LSP4J. \ No newline at end of file diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/ResolveTypeHierarchyItemParams.java b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/ResolveTypeHierarchyItemParams.java new file mode 100644 index 0000000000..77fbeb5236 --- /dev/null +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/ResolveTypeHierarchyItemParams.java @@ -0,0 +1,154 @@ +/** + * Copyright (c) 2016-2018 TypeFox and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, + * or the Eclipse Distribution License v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +package org.eclipse.lsp4j.legacy.typeHierarchy; + +import org.eclipse.lsp4j.jsonrpc.validation.NonNull; +import org.eclipse.lsp4j.util.Preconditions; +import org.eclipse.xtext.xbase.lib.Pure; +import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; + +import com.google.common.annotations.Beta; + +/** + * Request to resolve an unresolved {@link TypeHierarchyItem type hierarchy item} which is indicated if the + * {@link TypeHierarchyItem#getParents parents} or the {@link TypeHierarchyItem#getChildren children} is not + * defined. If resolved and no {@code parents} or {@code children} are available then an empty list is returned. + */ +@Beta +@SuppressWarnings("all") +public class ResolveTypeHierarchyItemParams { + /** + * The hierarchy item to resolve. + */ + @NonNull + private TypeHierarchyItem item; + + /** + * The number of hierarchy levels to resolve. {@code 0} indicates no hierarchy level. + */ + private int resolve; + + /** + * The direction of the type hierarchy resolution. + */ + @NonNull + private TypeHierarchyDirection direction; + + public ResolveTypeHierarchyItemParams() { + } + + public ResolveTypeHierarchyItemParams(@NonNull final TypeHierarchyItem item, final int resolve, @NonNull final TypeHierarchyDirection direction) { + this.item = Preconditions.checkNotNull(item, "item"); + this.resolve = resolve; + this.direction = Preconditions.checkNotNull(direction, "direction"); + } + + /** + * The hierarchy item to resolve. + */ + @Pure + @NonNull + public TypeHierarchyItem getItem() { + return this.item; + } + + /** + * The hierarchy item to resolve. + */ + public void setItem(@NonNull final TypeHierarchyItem item) { + this.item = Preconditions.checkNotNull(item, "item"); + } + + /** + * The number of hierarchy levels to resolve. {@code 0} indicates no hierarchy level. + */ + @Pure + public int getResolve() { + return this.resolve; + } + + /** + * The number of hierarchy levels to resolve. {@code 0} indicates no hierarchy level. + */ + public void setResolve(final int resolve) { + this.resolve = resolve; + } + + /** + * The direction of the type hierarchy resolution. + */ + @Pure + @NonNull + public TypeHierarchyDirection getDirection() { + return this.direction; + } + + /** + * The direction of the type hierarchy resolution. + */ + public void setDirection(@NonNull final TypeHierarchyDirection direction) { + this.direction = Preconditions.checkNotNull(direction, "direction"); + } + + @Override + @Pure + public String toString() { + ToStringBuilder b = new ToStringBuilder(this); + b.add("item", this.item); + b.add("resolve", this.resolve); + b.add("direction", this.direction); + return b.toString(); + } + + @Override + @Pure + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ResolveTypeHierarchyItemParams other = (ResolveTypeHierarchyItemParams) obj; + if (this.item == null) { + if (other.item != null) { + return false; + } + } else if (!this.item.equals(other.item)) { + return false; + } + if (other.resolve != this.resolve) { + return false; + } + if (this.direction == null) { + if (other.direction != null) { + return false; + } + } else if (!this.direction.equals(other.direction)) { + return false; + } + return true; + } + + @Override + @Pure + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.item== null) ? 0 : this.item.hashCode()); + result = prime * result + this.resolve; + return prime * result + ((this.direction== null) ? 0 : this.direction.hashCode()); + } +} diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyCapabilities.java b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyCapabilities.java new file mode 100644 index 0000000000..e9129646e5 --- /dev/null +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyCapabilities.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2016-2018 TypeFox and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, + * or the Eclipse Distribution License v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +package org.eclipse.lsp4j.legacy.typeHierarchy; + +import org.eclipse.lsp4j.DynamicRegistrationCapabilities; +import org.eclipse.xtext.xbase.lib.Pure; +import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; + +import com.google.common.annotations.Beta; + +/** + * Capabilities specific to the {@code textDocument/typeHierarchy}. + * + *

+ * Note: the {@code textDocument/typeHierarchy} + * language feature is not yet part of the official LSP specification. + */ +@Beta +@SuppressWarnings("all") +public class TypeHierarchyCapabilities extends DynamicRegistrationCapabilities { + public TypeHierarchyCapabilities() { + } + + public TypeHierarchyCapabilities(final Boolean dynamicRegistration) { + super(dynamicRegistration); + } + + @Override + @Pure + public String toString() { + ToStringBuilder b = new ToStringBuilder(this); + b.add("dynamicRegistration", getDynamicRegistration()); + return b.toString(); + } + + @Override + @Pure + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + if (!super.equals(obj)) { + return false; + } + return true; + } + + @Override + @Pure + public int hashCode() { + return super.hashCode(); + } +} diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyDirection.java b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyDirection.java new file mode 100644 index 0000000000..acc45835d1 --- /dev/null +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyDirection.java @@ -0,0 +1,57 @@ +/****************************************************************************** + * Copyright (c) 2019 TypeFox and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, + * or the Eclipse Distribution License v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + ******************************************************************************/ +package org.eclipse.lsp4j.legacy.typeHierarchy; + +import org.eclipse.lsp4j.services.TextDocumentService; + +/** + * Direction specific to the + * {@link TextDocumentService#typeHierarchy(TypeHierarchyParams) + * textDocument/typeHierarchy} and + * {@link TextDocumentService#resolveTypeHierarchy(ResolveTypeHierarchyItemParams) + * typeHierarchy/resolve} LS methods. + * + *

+ * Valid values are: + *

    + *
  • {@link TypeHierarchyDirection#Children Children},
  • + *
  • {@link TypeHierarchyDirection#Parents Parents},
  • + *
  • {@link TypeHierarchyDirection#Both Both}.
  • + *
+ * + */ +public enum TypeHierarchyDirection { + + /** + * Flag for retrieving/resolving the subtypes. Value: {@code 0}. + */ + Children, + + /** + * Flag to use when retrieving/resolving the supertypes. Value: {@code 1}. + */ + Parents, + + /** + * Flag for resolving both the super- and subtypes. Value: {@code 2}. + */ + Both; + + public static TypeHierarchyDirection forValue(int value) { + TypeHierarchyDirection[] values = TypeHierarchyDirection.values(); + if (value < 0 || value >= values.length) { + throw new IllegalArgumentException("Illegal enum value: " + value); + } + return values[value]; + } + +} diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyItem.java b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyItem.java new file mode 100644 index 0000000000..68668f73e1 --- /dev/null +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyItem.java @@ -0,0 +1,390 @@ +/** + * Copyright (c) 2016-2018 TypeFox and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, + * or the Eclipse Distribution License v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +package org.eclipse.lsp4j.legacy.typeHierarchy; + +import java.util.List; + +import org.eclipse.lsp4j.Range; +import org.eclipse.lsp4j.SymbolKind; +import org.eclipse.lsp4j.jsonrpc.json.adapters.JsonElementTypeAdapter; +import org.eclipse.lsp4j.jsonrpc.validation.NonNull; +import org.eclipse.lsp4j.util.Preconditions; +import org.eclipse.xtext.xbase.lib.Pure; +import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; + +import com.google.common.annotations.Beta; +import com.google.gson.annotations.JsonAdapter; + +/** + * Representation of an item that carries type information (such as class, interface, enumeration, etc) with additional parentage details. + */ +@Beta +@SuppressWarnings("all") +public class TypeHierarchyItem { + /** + * The human readable name of the hierarchy item. + */ + @NonNull + private String name; + + /** + * Optional detail for the hierarchy item. It can be, for instance, the signature of a function or method. + */ + private String detail; + + /** + * The kind of the hierarchy item. For instance, class or interface. + */ + @NonNull + private SymbolKind kind; + + /** + * {@code true} if the hierarchy item is deprecated. Otherwise, {@code false}. It is {@code false} by default. + */ + private Boolean deprecated; + + /** + * The URI of the text document where this type hierarchy item belongs to. + */ + @NonNull + private String uri; + + /** + * The range enclosing this type hierarchy item not including leading/trailing whitespace but everything else + * like comments. This information is typically used to determine if the clients cursor is inside the type + * hierarchy item to reveal in the symbol in the UI. + * + * @see TypeHierarchyItem#selectionRange + */ + @NonNull + private Range range; + + /** + * The range that should be selected and revealed when this type hierarchy item is being picked, e.g the name of a function. + * Must be contained by the the {@link TypeHierarchyItem#getRange range}. + * + * @see TypeHierarchyItem#range + */ + @NonNull + private Range selectionRange; + + /** + * If this type hierarchy item is resolved, it contains the direct parents. Could be empty if the item does not have any + * direct parents. If not defined, the parents have not been resolved yet. + */ + private List parents; + + /** + * If this type hierarchy item is resolved, it contains the direct children of the current item. + * Could be empty if the item does not have any descendants. If not defined, the children have not been resolved. + */ + private List children; + + /** + * An optional data field can be used to identify a type hierarchy item in a resolve request. + */ + @JsonAdapter(JsonElementTypeAdapter.Factory.class) + private Object data; + + /** + * The human readable name of the hierarchy item. + */ + @Pure + @NonNull + public String getName() { + return this.name; + } + + /** + * The human readable name of the hierarchy item. + */ + public void setName(@NonNull final String name) { + this.name = Preconditions.checkNotNull(name, "name"); + } + + /** + * Optional detail for the hierarchy item. It can be, for instance, the signature of a function or method. + */ + @Pure + public String getDetail() { + return this.detail; + } + + /** + * Optional detail for the hierarchy item. It can be, for instance, the signature of a function or method. + */ + public void setDetail(final String detail) { + this.detail = detail; + } + + /** + * The kind of the hierarchy item. For instance, class or interface. + */ + @Pure + @NonNull + public SymbolKind getKind() { + return this.kind; + } + + /** + * The kind of the hierarchy item. For instance, class or interface. + */ + public void setKind(@NonNull final SymbolKind kind) { + this.kind = Preconditions.checkNotNull(kind, "kind"); + } + + /** + * {@code true} if the hierarchy item is deprecated. Otherwise, {@code false}. It is {@code false} by default. + */ + @Pure + public Boolean getDeprecated() { + return this.deprecated; + } + + /** + * {@code true} if the hierarchy item is deprecated. Otherwise, {@code false}. It is {@code false} by default. + */ + public void setDeprecated(final Boolean deprecated) { + this.deprecated = deprecated; + } + + /** + * The URI of the text document where this type hierarchy item belongs to. + */ + @Pure + @NonNull + public String getUri() { + return this.uri; + } + + /** + * The URI of the text document where this type hierarchy item belongs to. + */ + public void setUri(@NonNull final String uri) { + this.uri = Preconditions.checkNotNull(uri, "uri"); + } + + /** + * The range enclosing this type hierarchy item not including leading/trailing whitespace but everything else + * like comments. This information is typically used to determine if the clients cursor is inside the type + * hierarchy item to reveal in the symbol in the UI. + * + * @see TypeHierarchyItem#selectionRange + */ + @Pure + @NonNull + public Range getRange() { + return this.range; + } + + /** + * The range enclosing this type hierarchy item not including leading/trailing whitespace but everything else + * like comments. This information is typically used to determine if the clients cursor is inside the type + * hierarchy item to reveal in the symbol in the UI. + * + * @see TypeHierarchyItem#selectionRange + */ + public void setRange(@NonNull final Range range) { + this.range = Preconditions.checkNotNull(range, "range"); + } + + /** + * The range that should be selected and revealed when this type hierarchy item is being picked, e.g the name of a function. + * Must be contained by the the {@link TypeHierarchyItem#getRange range}. + * + * @see TypeHierarchyItem#range + */ + @Pure + @NonNull + public Range getSelectionRange() { + return this.selectionRange; + } + + /** + * The range that should be selected and revealed when this type hierarchy item is being picked, e.g the name of a function. + * Must be contained by the the {@link TypeHierarchyItem#getRange range}. + * + * @see TypeHierarchyItem#range + */ + public void setSelectionRange(@NonNull final Range selectionRange) { + this.selectionRange = Preconditions.checkNotNull(selectionRange, "selectionRange"); + } + + /** + * If this type hierarchy item is resolved, it contains the direct parents. Could be empty if the item does not have any + * direct parents. If not defined, the parents have not been resolved yet. + */ + @Pure + public List getParents() { + return this.parents; + } + + /** + * If this type hierarchy item is resolved, it contains the direct parents. Could be empty if the item does not have any + * direct parents. If not defined, the parents have not been resolved yet. + */ + public void setParents(final List parents) { + this.parents = parents; + } + + /** + * If this type hierarchy item is resolved, it contains the direct children of the current item. + * Could be empty if the item does not have any descendants. If not defined, the children have not been resolved. + */ + @Pure + public List getChildren() { + return this.children; + } + + /** + * If this type hierarchy item is resolved, it contains the direct children of the current item. + * Could be empty if the item does not have any descendants. If not defined, the children have not been resolved. + */ + public void setChildren(final List children) { + this.children = children; + } + + /** + * An optional data field can be used to identify a type hierarchy item in a resolve request. + */ + @Pure + public Object getData() { + return this.data; + } + + /** + * An optional data field can be used to identify a type hierarchy item in a resolve request. + */ + public void setData(final Object data) { + this.data = data; + } + + @Override + @Pure + public String toString() { + ToStringBuilder b = new ToStringBuilder(this); + b.add("name", this.name); + b.add("detail", this.detail); + b.add("kind", this.kind); + b.add("deprecated", this.deprecated); + b.add("uri", this.uri); + b.add("range", this.range); + b.add("selectionRange", this.selectionRange); + b.add("parents", this.parents); + b.add("children", this.children); + b.add("data", this.data); + return b.toString(); + } + + @Override + @Pure + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + TypeHierarchyItem other = (TypeHierarchyItem) obj; + if (this.name == null) { + if (other.name != null) { + return false; + } + } else if (!this.name.equals(other.name)) { + return false; + } + if (this.detail == null) { + if (other.detail != null) { + return false; + } + } else if (!this.detail.equals(other.detail)) { + return false; + } + if (this.kind == null) { + if (other.kind != null) { + return false; + } + } else if (!this.kind.equals(other.kind)) { + return false; + } + if (this.deprecated == null) { + if (other.deprecated != null) { + return false; + } + } else if (!this.deprecated.equals(other.deprecated)) { + return false; + } + if (this.uri == null) { + if (other.uri != null) { + return false; + } + } else if (!this.uri.equals(other.uri)) { + return false; + } + if (this.range == null) { + if (other.range != null) { + return false; + } + } else if (!this.range.equals(other.range)) { + return false; + } + if (this.selectionRange == null) { + if (other.selectionRange != null) { + return false; + } + } else if (!this.selectionRange.equals(other.selectionRange)) { + return false; + } + if (this.parents == null) { + if (other.parents != null) { + return false; + } + } else if (!this.parents.equals(other.parents)) { + return false; + } + if (this.children == null) { + if (other.children != null) { + return false; + } + } else if (!this.children.equals(other.children)) { + return false; + } + if (this.data == null) { + if (other.data != null) { + return false; + } + } else if (!this.data.equals(other.data)) { + return false; + } + return true; + } + + @Override + @Pure + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.name== null) ? 0 : this.name.hashCode()); + result = prime * result + ((this.detail== null) ? 0 : this.detail.hashCode()); + result = prime * result + ((this.kind== null) ? 0 : this.kind.hashCode()); + result = prime * result + ((this.deprecated== null) ? 0 : this.deprecated.hashCode()); + result = prime * result + ((this.uri== null) ? 0 : this.uri.hashCode()); + result = prime * result + ((this.range== null) ? 0 : this.range.hashCode()); + result = prime * result + ((this.selectionRange== null) ? 0 : this.selectionRange.hashCode()); + result = prime * result + ((this.parents== null) ? 0 : this.parents.hashCode()); + result = prime * result + ((this.children== null) ? 0 : this.children.hashCode()); + return prime * result + ((this.data== null) ? 0 : this.data.hashCode()); + } +} diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyParams.java b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyParams.java new file mode 100644 index 0000000000..a6ef5f4a34 --- /dev/null +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/lsp4j/legacy/typeHierarchy/TypeHierarchyParams.java @@ -0,0 +1,116 @@ +/** + * Copyright (c) 2016-2018 TypeFox and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, + * or the Eclipse Distribution License v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ +package org.eclipse.lsp4j.legacy.typeHierarchy; + +import org.eclipse.lsp4j.TextDocumentPositionParams; +import org.eclipse.xtext.xbase.lib.Pure; +import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; + +import com.google.common.annotations.Beta; + +/** + * The type hierarchy request is sent from the client resolve a {@link TypeHierarchyItem type hierarchy item} for + * a give cursor location in the text document. The request would also allow to specify if the item should be resolved + * and whether sub- or supertypes are to be resolved. + */ +@Beta +@SuppressWarnings("all") +public class TypeHierarchyParams extends TextDocumentPositionParams { + /** + * The number of hierarchy levels to resolve. {@code 0} indicates no hierarchy level. It defaults to {@code 0}. + */ + private int resolve; + + /** + * The direction of the type hierarchy resolution. If not defined, defaults to {@link TypeHierarchyDirection#Children Children}. + */ + private TypeHierarchyDirection direction; + + /** + * The number of hierarchy levels to resolve. {@code 0} indicates no hierarchy level. It defaults to {@code 0}. + */ + @Pure + public int getResolve() { + return this.resolve; + } + + /** + * The number of hierarchy levels to resolve. {@code 0} indicates no hierarchy level. It defaults to {@code 0}. + */ + public void setResolve(final int resolve) { + this.resolve = resolve; + } + + /** + * The direction of the type hierarchy resolution. If not defined, defaults to {@link TypeHierarchyDirection#Children Children}. + */ + @Pure + public TypeHierarchyDirection getDirection() { + return this.direction; + } + + /** + * The direction of the type hierarchy resolution. If not defined, defaults to {@link TypeHierarchyDirection#Children Children}. + */ + public void setDirection(final TypeHierarchyDirection direction) { + this.direction = direction; + } + + @Override + @Pure + public String toString() { + ToStringBuilder b = new ToStringBuilder(this); + b.add("resolve", this.resolve); + b.add("direction", this.direction); + b.add("textDocument", getTextDocument()); + b.add("position", getPosition()); + return b.toString(); + } + + @Override + @Pure + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + if (!super.equals(obj)) { + return false; + } + TypeHierarchyParams other = (TypeHierarchyParams) obj; + if (other.resolve != this.resolve) { + return false; + } + if (this.direction == null) { + if (other.direction != null) { + return false; + } + } else if (!this.direction.equals(other.direction)) { + return false; + } + return true; + } + + @Override + @Pure + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + this.resolve; + return prime * result + ((this.direction== null) ? 0 : this.direction.hashCode()); + } +} 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 70fe3b6395..05b6898504 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 @@ - - @@ -32,10 +30,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 a9a66c069b..4829893cd6 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.20.0,0.21.0)", + org.eclipse.lsp4j.jsonrpc;bundle-version="[0.20.0,0.21.0)", org.eclipse.xtext.xbase.lib, org.eclipse.jdt.launching, org.eclipse.ltk.core.refactoring, diff --git a/org.eclipse.jdt.ls.tests/META-INF/MANIFEST.MF b/org.eclipse.jdt.ls.tests/META-INF/MANIFEST.MF index 4f76c00cb0..08dcf79e20 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.21.0.qualifier @@ -24,8 +25,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.20.0,0.21.0)", + org.eclipse.lsp4j.jsonrpc;bundle-version="[0.20.0,0.21.0)", org.eclipse.xtext.xbase.lib, org.eclipse.jdt.launching, org.eclipse.ltk.core.refactoring, 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..8dfd45a5a9 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 @@ -25,9 +25,9 @@ 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.legacy.typeHierarchy.TypeHierarchyDirection; +import org.eclipse.lsp4j.legacy.typeHierarchy.TypeHierarchyItem; +import org.eclipse.lsp4j.legacy.typeHierarchy.TypeHierarchyParams; import org.junit.Before; import org.junit.Test; 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/**")); }