From dc84a4e7f0fe5a3156bcbf4bd5bb2bc11a492584 Mon Sep 17 00:00:00 2001 From: BoykoAlex Date: Fri, 21 Apr 2023 23:10:21 -0400 Subject: [PATCH] Removal of deprecated API --- .../commands/RewriteRefactoringsHandler.java | 84 +++++++++---------- .../commons/STS4LanguageClientImpl.java | 4 +- .../tooling/ls/eclipse/commons/Utils.java | 7 -- 3 files changed, 44 insertions(+), 51 deletions(-) diff --git a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/commands/RewriteRefactoringsHandler.java b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/commands/RewriteRefactoringsHandler.java index c313f03fe..f0fb5f86a 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/commands/RewriteRefactoringsHandler.java +++ b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/commands/RewriteRefactoringsHandler.java @@ -29,10 +29,9 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.IStructuredSelection; 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.LanguageServerDefinition; -import org.eclipse.lsp4e.LanguageServiceAccessor; import org.eclipse.lsp4j.ExecuteCommandParams; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.PlatformUI; @@ -107,58 +106,59 @@ public class RewriteRefactoringsHandler extends AbstractHandler { if (project != null && CoreUtil.promptForProjectSave(project)) { LanguageServerDefinition def = LanguageServersRegistry.getInstance().getDefinition(BootLanguageServerPlugin.BOOT_LS_DEFINITION_ID); Assert.isLegal(def != null, "No definition found for Boot Language Server"); - LanguageServerWrapper wrapper = LanguageServiceAccessor.getLSWrapper(project, def); final String uri = project.getLocationURI().toASCIIString(); ExecuteCommandParams commandParams = new ExecuteCommandParams(); commandParams.setCommand(REWRITE_REFACTORINGS_LIST); commandParams.setArguments(List.of(uri, recipeFilter.toString())); + try { List allRewriteRecipesJson = new ArrayList<>(); List syncRecipesJson = Collections.synchronizedList(allRewriteRecipesJson); - wrapper.getInitializedServer().thenComposeAsync(ls -> 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); - - PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { - RecipeTreeModel recipesModel = new RecipeTreeModel(descriptors); - int returnCode = new SelectRecipesDialog(Display.getCurrent().getActiveShell(), recipesModel).open(); - if (returnCode == Window.OK) { - try { - RecipeDescriptor recipeToApply = recipesModel.getSelectedRecipeDescriptors(); - PlatformUI.getWorkbench().getProgressService().run(true, false, monitor -> { - try { - monitor.beginTask("Applying recipe '" + recipeToApply.displayName + "'", IProgressMonitor.UNKNOWN); - ExecuteCommandParams cmdParams = new ExecuteCommandParams(); - cmdParams.setCommand(REWRITE_REFACTORINGS_EXEC); - cmdParams.setArguments(List.of( - uri, - serializationGson.toJsonTree(recipeToApply) - )); - - wrapper.getInitializedServer() - .thenComposeAsync(ls -> ls.getWorkspaceService().executeCommand(cmdParams)).get(); - } catch (Exception e) { - throw new InvocationTargetException(e); - } finally { - monitor.done(); - } - }); - - } catch (CoreException | InvocationTargetException | InterruptedException e) { - 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."); - } + + LanguageServers.forProject(project).withPreferredServer(def).computeFirst(ls -> + 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); + + PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { + RecipeTreeModel recipesModel = new RecipeTreeModel(descriptors); + int returnCode = new SelectRecipesDialog(Display.getCurrent().getActiveShell(), recipesModel).open(); + if (returnCode == Window.OK) { + try { + RecipeDescriptor recipeToApply = recipesModel.getSelectedRecipeDescriptors(); + PlatformUI.getWorkbench().getProgressService().run(true, false, monitor -> { + try { + monitor.beginTask("Applying recipe '" + recipeToApply.displayName + "'", IProgressMonitor.UNKNOWN); + ExecuteCommandParams cmdParams = new ExecuteCommandParams(); + cmdParams.setCommand(REWRITE_REFACTORINGS_EXEC); + cmdParams.setArguments(List.of( + uri, + serializationGson.toJsonTree(recipeToApply) + )); + + ls.getWorkspaceService().executeCommand(cmdParams).get(); + } catch (Exception e) { + throw new InvocationTargetException(e); + } finally { + monitor.done(); + } + }); + + } catch (CoreException | InvocationTargetException | InterruptedException e) { + 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) { throw new ExecutionException("Failed to apply Rewrite recipe(s)", e); } diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java index 035fa0dc2..0d741ddb2 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageClientImpl.java @@ -213,7 +213,7 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La updateHighlightAnnotations(editor, sourceViewer, annotationModel, target, updateCodeMinings); } } else { - URI uri = Utils.findDocUri(doc); + URI uri = LSPEclipseUtils.toUri(doc); if (uri != null) { updateHighlightAnnotations(editor, sourceViewer, annotationModel, uri.toASCIIString(), updateCodeMinings); } @@ -488,7 +488,7 @@ public class STS4LanguageClientImpl extends LanguageClientImpl implements STS4La AbstractTextEditor editor = (AbstractTextEditor) _editor; IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput()); if (doc!=null) { - URI uri = Utils.findDocUri(doc); + URI uri = LSPEclipseUtils.toUri(doc); if (cursorMovement.getUri().equals(uri.toASCIIString())) { org.eclipse.lsp4j.Position pos = cursorMovement.getPosition(); int offset = LSPEclipseUtils.toOffset(pos, doc); diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/Utils.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/Utils.java index 13c025ab9..94f1349d7 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/Utils.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/Utils.java @@ -67,13 +67,6 @@ public class Utils { .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) { for (LSPDocumentInfo info : LanguageServiceAccessor.getLSPDocumentInfosFor(doc, (x) -> true)) { if (info.getVersion() == id.getVersion()) {