Skip to content

Commit

Permalink
Use LSP4J 0.20.0
Browse files Browse the repository at this point in the history
* Bump versions & adopt new APIs (eg remap globPatterns to String)
* Remove custom inlayHints, use standard
* Declare null notebook service
  • Loading branch information
mickaelistria committed Feb 22, 2023
1 parent c9e7d82 commit 9d93838
Show file tree
Hide file tree
Showing 22 changed files with 76 additions and 371 deletions.
4 changes: 2 additions & 2 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.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,
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 Expand Up @@ -221,8 +213,6 @@ public List<Object> 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<Void> refreshInlayHints() {
return this.client.refreshInlayHints();
}
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 @@ -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;
Expand All @@ -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;

Expand All @@ -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";
Expand Down Expand Up @@ -482,10 +485,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 @@ -788,12 +791,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 @@ -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;
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -507,14 +508,13 @@ public List<FileSystemWatcher> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -138,9 +139,9 @@ public List<FileSystemWatcher> registerWatchers() {
List<FileSystemWatcher> fileWatchers = new ArrayList<>();
Set<String> 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);
}

Expand All @@ -159,7 +160,7 @@ public List<FileSystemWatcher> registerWatchers() {
return Collections.emptyList();
}


private static IPath[] listAllSourcePaths() throws JavaModelException {
Set<IPath> classpaths = new HashSet<>();
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 9d93838

Please sign in to comment.