Removal of deprecated API

This commit is contained in:
BoykoAlex
2023-04-21 23:10:21 -04:00
committed by aboyko
parent 082e677091
commit dc84a4e7f0
3 changed files with 44 additions and 51 deletions

View File

@@ -29,10 +29,9 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window; import org.eclipse.jface.window.Window;
import org.eclipse.lsp4e.LanguageServerWrapper; import org.eclipse.lsp4e.LanguageServers;
import org.eclipse.lsp4e.LanguageServersRegistry; import org.eclipse.lsp4e.LanguageServersRegistry;
import org.eclipse.lsp4e.LanguageServersRegistry.LanguageServerDefinition; import org.eclipse.lsp4e.LanguageServersRegistry.LanguageServerDefinition;
import org.eclipse.lsp4e.LanguageServiceAccessor;
import org.eclipse.lsp4j.ExecuteCommandParams; import org.eclipse.lsp4j.ExecuteCommandParams;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI; import org.eclipse.ui.PlatformUI;
@@ -107,58 +106,59 @@ public class RewriteRefactoringsHandler extends AbstractHandler {
if (project != null && CoreUtil.promptForProjectSave(project)) { if (project != null && CoreUtil.promptForProjectSave(project)) {
LanguageServerDefinition def = LanguageServersRegistry.getInstance().getDefinition(BootLanguageServerPlugin.BOOT_LS_DEFINITION_ID); LanguageServerDefinition def = LanguageServersRegistry.getInstance().getDefinition(BootLanguageServerPlugin.BOOT_LS_DEFINITION_ID);
Assert.isLegal(def != null, "No definition found for Boot Language Server"); Assert.isLegal(def != null, "No definition found for Boot Language Server");
LanguageServerWrapper wrapper = LanguageServiceAccessor.getLSWrapper(project, def);
final String uri = project.getLocationURI().toASCIIString(); final String uri = project.getLocationURI().toASCIIString();
ExecuteCommandParams commandParams = new ExecuteCommandParams(); ExecuteCommandParams commandParams = new ExecuteCommandParams();
commandParams.setCommand(REWRITE_REFACTORINGS_LIST); commandParams.setCommand(REWRITE_REFACTORINGS_LIST);
commandParams.setArguments(List.of(uri, recipeFilter.toString())); commandParams.setArguments(List.of(uri, recipeFilter.toString()));
try { try {
List<Object> allRewriteRecipesJson = new ArrayList<>(); List<Object> allRewriteRecipesJson = new ArrayList<>();
List<Object> syncRecipesJson = Collections.synchronizedList(allRewriteRecipesJson); List<Object> syncRecipesJson = Collections.synchronizedList(allRewriteRecipesJson);
wrapper.getInitializedServer().thenComposeAsync(ls -> ls.getWorkspaceService().executeCommand(commandParams).thenAccept(or -> {
if (or != null) { LanguageServers.forProject(project).withPreferredServer(def).computeFirst(ls ->
syncRecipesJson.add(or); ls.getWorkspaceService().executeCommand(commandParams).thenAccept(or -> {
} if (or != null) {
})) syncRecipesJson.add(or);
.thenRun(() -> { }
allRewriteRecipesJson.stream().filter(List.class::isInstance).map(List.class::cast).findFirst().ifPresent(obj -> { })
RecipeDescriptor[] descriptors = serializationGson.fromJson(serializationGson.toJson(obj), RecipeDescriptor[].class); .thenRun(() -> {
allRewriteRecipesJson.stream().filter(List.class::isInstance).map(List.class::cast).findFirst().ifPresent(obj -> {
PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { RecipeDescriptor[] descriptors = serializationGson.fromJson(serializationGson.toJson(obj), RecipeDescriptor[].class);
RecipeTreeModel recipesModel = new RecipeTreeModel(descriptors);
int returnCode = new SelectRecipesDialog(Display.getCurrent().getActiveShell(), recipesModel).open(); PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
if (returnCode == Window.OK) { RecipeTreeModel recipesModel = new RecipeTreeModel(descriptors);
try { int returnCode = new SelectRecipesDialog(Display.getCurrent().getActiveShell(), recipesModel).open();
RecipeDescriptor recipeToApply = recipesModel.getSelectedRecipeDescriptors(); if (returnCode == Window.OK) {
PlatformUI.getWorkbench().getProgressService().run(true, false, monitor -> { try {
try { RecipeDescriptor recipeToApply = recipesModel.getSelectedRecipeDescriptors();
monitor.beginTask("Applying recipe '" + recipeToApply.displayName + "'", IProgressMonitor.UNKNOWN); PlatformUI.getWorkbench().getProgressService().run(true, false, monitor -> {
ExecuteCommandParams cmdParams = new ExecuteCommandParams(); try {
cmdParams.setCommand(REWRITE_REFACTORINGS_EXEC); monitor.beginTask("Applying recipe '" + recipeToApply.displayName + "'", IProgressMonitor.UNKNOWN);
cmdParams.setArguments(List.of( ExecuteCommandParams cmdParams = new ExecuteCommandParams();
uri, cmdParams.setCommand(REWRITE_REFACTORINGS_EXEC);
serializationGson.toJsonTree(recipeToApply) cmdParams.setArguments(List.of(
)); uri,
serializationGson.toJsonTree(recipeToApply)
wrapper.getInitializedServer() ));
.thenComposeAsync(ls -> ls.getWorkspaceService().executeCommand(cmdParams)).get();
} catch (Exception e) { ls.getWorkspaceService().executeCommand(cmdParams).get();
throw new InvocationTargetException(e); } catch (Exception e) {
} finally { throw new InvocationTargetException(e);
monitor.done(); } finally {
} monitor.done();
}); }
});
} catch (CoreException | InvocationTargetException | InterruptedException e) {
BootLanguageServerPlugin.getDefault().getLog().error(e.getMessage(), e); } catch (CoreException | InvocationTargetException | InterruptedException e) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", "Failed to apply Rewrite recipe(s). See error log for more details."); BootLanguageServerPlugin.getDefault().getLog().error(e.getMessage(), e);
} MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", "Failed to apply Rewrite recipe(s). See error log for more details.");
} }
}); }
}); });
}); });
}));
} catch (Exception e) { } catch (Exception e) {
throw new ExecutionException("Failed to apply Rewrite recipe(s)", e); throw new ExecutionException("Failed to apply Rewrite recipe(s)", e);
} }

View File

@@ -213,7 +213,7 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La
updateHighlightAnnotations(editor, sourceViewer, annotationModel, target, updateCodeMinings); updateHighlightAnnotations(editor, sourceViewer, annotationModel, target, updateCodeMinings);
} }
} else { } else {
URI uri = Utils.findDocUri(doc); URI uri = LSPEclipseUtils.toUri(doc);
if (uri != null) { if (uri != null) {
updateHighlightAnnotations(editor, sourceViewer, annotationModel, uri.toASCIIString(), updateCodeMinings); updateHighlightAnnotations(editor, sourceViewer, annotationModel, uri.toASCIIString(), updateCodeMinings);
} }
@@ -488,7 +488,7 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La
AbstractTextEditor editor = (AbstractTextEditor) _editor; AbstractTextEditor editor = (AbstractTextEditor) _editor;
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput()); IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
if (doc!=null) { if (doc!=null) {
URI uri = Utils.findDocUri(doc); URI uri = LSPEclipseUtils.toUri(doc);
if (cursorMovement.getUri().equals(uri.toASCIIString())) { if (cursorMovement.getUri().equals(uri.toASCIIString())) {
org.eclipse.lsp4j.Position pos = cursorMovement.getPosition(); org.eclipse.lsp4j.Position pos = cursorMovement.getPosition();
int offset = LSPEclipseUtils.toOffset(pos, doc); int offset = LSPEclipseUtils.toOffset(pos, doc);

View File

@@ -67,13 +67,6 @@ public class Utils {
.map(viewer -> (ISourceViewer) viewer); .map(viewer -> (ISourceViewer) viewer);
} }
public static URI findDocUri(IDocument doc) {
for (LSPDocumentInfo info : LanguageServiceAccessor.getLSPDocumentInfosFor(doc, (x) -> true)) {
return info.getFileUri();
}
return null;
}
public static boolean isProperDocumentIdFor(IDocument doc, VersionedTextDocumentIdentifier id) { public static boolean isProperDocumentIdFor(IDocument doc, VersionedTextDocumentIdentifier id) {
for (LSPDocumentInfo info : LanguageServiceAccessor.getLSPDocumentInfosFor(doc, (x) -> true)) { for (LSPDocumentInfo info : LanguageServiceAccessor.getLSPDocumentInfosFor(doc, (x) -> true)) {
if (info.getVersion() == id.getVersion()) { if (info.getVersion() == id.getVersion()) {