Skip to content

Commit

Permalink
Use LSP4J 0.19.0
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mickaelistria committed Jan 24, 2023
1 parent 59af6c6 commit 13b6268
Show file tree
Hide file tree
Showing 25 changed files with 182 additions and 547 deletions.
5 changes: 2 additions & 3 deletions org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -103,29 +97,6 @@ public Object executeCommand(String commandId, List<Object> arguments, IProgress
projectNames = (ArrayList<String>) arguments.get(1);
}
return ResolveSourceMappingHandler.resolveStackTraceLocation((String) arguments.get(0), projectNames);
case "java.navigate.resolveTypeHierarchy":
TypeHierarchyCommand resolveTypeHierarchyCommand = new TypeHierarchyCommand();
TypeHierarchyItem toResolve = JSONUtility.toModel(arguments.get(0), TypeHierarchyItem.class);
TypeHierarchyDirection resolveDirection = TypeHierarchyDirection.forValue(JSONUtility.toModel(arguments.get(1), Integer.class));
int resolveDepth = JSONUtility.toModel(arguments.get(2), Integer.class);
ResolveTypeHierarchyItemParams resolveParams = new ResolveTypeHierarchyItemParams();
resolveParams.setItem(toResolve);
resolveParams.setDirection(resolveDirection);
resolveParams.setResolve(resolveDepth);
TypeHierarchyItem resolvedItem = resolveTypeHierarchyCommand.resolveTypeHierarchy(resolveParams, monitor);
return resolvedItem;
case "java.navigate.openTypeHierarchy":
TypeHierarchyCommand typeHierarchyCommand = new TypeHierarchyCommand();
TypeHierarchyParams params = new TypeHierarchyParams();
TextDocumentPositionParams textParams = JSONUtility.toModel(arguments.get(0), TextDocumentPositionParams.class);
TypeHierarchyDirection direction = TypeHierarchyDirection.forValue(JSONUtility.toModel(arguments.get(1), Integer.class));
int resolve = JSONUtility.toModel(arguments.get(2), Integer.class);
params.setResolve(resolve);
params.setDirection(direction);
params.setTextDocument(textParams.getTextDocument());
params.setPosition(textParams.getPosition());
TypeHierarchyItem typeHierarchyItem = typeHierarchyCommand.typeHierarchy(params, monitor);
return typeHierarchyItem;
case "java.project.upgradeGradle":
String projectUri = (String) arguments.get(0);
String gradleVersion = arguments.size() > 1 ? (String) arguments.get(1) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<Void> refreshInlayHints() {
throw new UnsupportedOperationException();
}
}

private final LogHandler logHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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";
Expand Down Expand Up @@ -480,10 +487,10 @@ public JavaProtocolExtensions getJavaExtensions() {
* @see org.eclipse.lsp4j.services.WorkspaceService#symbol(org.eclipse.lsp4j.WorkspaceSymbolParams)
*/
@Override
public CompletableFuture<List<? extends SymbolInformation>> symbol(WorkspaceSymbolParams params) {
public CompletableFuture<Either<List<? extends SymbolInformation>, List<? extends WorkspaceSymbol>>> symbol(WorkspaceSymbolParams params) {
logInfo(">> workspace/symbol");
return computeAsync((monitor) -> {
return WorkspaceSymbolHandler.search(params.getQuery(), monitor);
return Either.forLeft(WorkspaceSymbolHandler.search(params.getQuery(), monitor));
});
}

Expand Down Expand Up @@ -792,12 +799,12 @@ public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTy
* @see org.eclipse.lsp4j.services.TextDocumentService#prepareRename(org.eclipse.lsp4j.PrepareRenameParams)
*/
@Override
public CompletableFuture<Either<Range, PrepareRenameResult>> prepareRename(PrepareRenameParams params) {
public CompletableFuture<Either3<Range, PrepareRenameResult, PrepareRenameDefaultBehavior>> 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));
});
}

Expand Down Expand Up @@ -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<List<TypeHierarchyItem>> prepareTypeHierarchy(TypeHierarchyPrepareParams params) {
return computeAsyncWithClientProgress(monitor -> new TypeHierarchyHandler().prepareTypeHierarchy(params, monitor));
}

@Override
public CompletableFuture<List<TypeHierarchyItem>> typeHierarchySubtypes(TypeHierarchySubtypesParams params) {
return computeAsyncWithClientProgress(monitor -> new TypeHierarchyHandler().callHierarchySubtypes(params, monitor));
}

@Override
public CompletableFuture<List<TypeHierarchyItem>> typeHierarchySupertypes(TypeHierarchySupertypesParams params) {
return computeAsyncWithClientProgress(monitor -> new TypeHierarchyHandler().callHierarchySupertypes(params, monitor));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -46,8 +44,7 @@ public PrepareRenameHandler(PreferenceManager preferenceManager) {
this.preferenceManager = preferenceManager;
}

public Either<Range, PrepareRenameResult> prepareRename(TextDocumentPositionParams params, IProgressMonitor monitor) {

public Range prepareRename(TextDocumentPositionParams params, IProgressMonitor monitor) {
final ICompilationUnit unit = JDTUtils.resolveCompilationUnit(params.getTextDocument().getUri());
if (unit != null) {
try {
Expand All @@ -62,7 +59,7 @@ public Either<Range, PrepareRenameResult> 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
Expand All @@ -80,7 +77,7 @@ public Either<Range, PrepareRenameResult> 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());
}
}
}
Expand Down
Loading

0 comments on commit 13b6268

Please sign in to comment.