diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/LanguageServiceAccessor.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/LanguageServiceAccessor.java index 5184eeb85..e5102782e 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/LanguageServiceAccessor.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/LanguageServiceAccessor.java @@ -39,7 +39,7 @@ public class LanguageServiceAccessor { private final Project project; - public static LanguageServiceAccessor getInstance(Project project) { + public static LanguageServiceAccessor getInstance(@NotNull Project project) { return project.getService(LanguageServiceAccessor.class); } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/ServerMessageHandler.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/ServerMessageHandler.java index 2704187a1..2aa0fd81f 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/ServerMessageHandler.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/ServerMessageHandler.java @@ -44,30 +44,23 @@ private static Icon messageTypeToIcon(MessageType type) { } private static NotificationType messageTypeToNotificationType(MessageType type) { - NotificationType result = null; - - switch (type) { - case Error: - result = NotificationType.ERROR; - break; - case Info: - case Log: - result = NotificationType.INFORMATION; - break; - case Warning: - result = NotificationType.WARNING; - } + NotificationType result = switch (type) { + case Error -> NotificationType.ERROR; + case Info, Log -> NotificationType.INFORMATION; + case Warning -> NotificationType.WARNING; + }; return result; } public static void showMessage(String title, MessageParams params) { - Notification notification = new Notification("Language Server Protocol", messageTypeToIcon(params.getType()), title, null, params.getMessage(), messageTypeToNotificationType(params.getType()), null); + Notification notification = new Notification("Language Server Protocol", title, params.getMessage(), messageTypeToNotificationType(params.getType())); + notification.setIcon(messageTypeToIcon(params.getType())); Notifications.Bus.notify(notification); } public static CompletableFuture showMessageRequest(LanguageServerWrapper wrapper, ShowMessageRequestParams params) { - String options[] = params.getActions().stream().map(MessageActionItem::getTitle).toArray(String[]::new); + String[] options = params.getActions().stream().map(MessageActionItem::getTitle).toArray(String[]::new); CompletableFuture future = new CompletableFuture<>(); ApplicationManager.getApplication().invokeLater(() -> { diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/console/explorer/LanguageServerProcessTreeNode.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/console/explorer/LanguageServerProcessTreeNode.java index 587f92542..fc9950460 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/console/explorer/LanguageServerProcessTreeNode.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/console/explorer/LanguageServerProcessTreeNode.java @@ -14,7 +14,7 @@ package com.redhat.devtools.intellij.lsp4ij.console.explorer; import com.intellij.icons.AllIcons; -import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.util.text.Formats; import com.intellij.ui.AnimatedIcon; import com.redhat.devtools.intellij.lsp4ij.LanguageServerWrapper; import com.redhat.devtools.intellij.lsp4ij.ServerStatus; @@ -124,6 +124,6 @@ public String getDisplayName() { public String getElapsedTime() { long endTime = System.currentTimeMillis(); long duration = endTime - startTime; - return StringUtil.formatDuration(duration, "\u2009"); + return Formats.formatDuration(duration, "\u2009"); } } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/lifecycle/LanguageServerLifecycleManager.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/lifecycle/LanguageServerLifecycleManager.java index cde5aaa08..f70871167 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/lifecycle/LanguageServerLifecycleManager.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/lifecycle/LanguageServerLifecycleManager.java @@ -17,6 +17,7 @@ import com.redhat.devtools.intellij.lsp4ij.LanguageServerWrapper; import org.eclipse.lsp4j.jsonrpc.MessageConsumer; import org.eclipse.lsp4j.jsonrpc.messages.Message; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,7 +29,7 @@ */ public class LanguageServerLifecycleManager { - public static LanguageServerLifecycleManager getInstance(Project project) { + public static LanguageServerLifecycleManager getInstance(@NotNull Project project) { return project.getService(LanguageServerLifecycleManager.class); } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPDiagnosticHandler.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPDiagnosticHandler.java index 012ef8130..2736de86f 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPDiagnosticHandler.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPDiagnosticHandler.java @@ -30,6 +30,7 @@ import org.jetbrains.annotations.NotNull; import java.net.URI; +import java.util.concurrent.Callable; import java.util.function.Consumer; /** @@ -49,7 +50,7 @@ public LSPDiagnosticHandler(LanguageServerWrapper languageServerWrapper) { @Override public void accept(PublishDiagnosticsParams params) { Project project = languageServerWrapper.getProject(); - if (project.isDisposed()) { + if (project == null || project.isDisposed()) { return; } if (ApplicationManager.getApplication().isReadAccessAllowed()) { @@ -58,9 +59,11 @@ public void accept(PublishDiagnosticsParams params) { // Cancel if needed the previous "textDocument/publishDiagnostics" for a given uri. var coalesceBy = new CoalesceByKey("textDocument/publishDiagnostics", params.getUri()); var executeInSmartMode = DumbService.getInstance(languageServerWrapper.getProject()).isDumb(); - var action = ReadAction.nonBlocking(() -> updateDiagnostics(params, project)) - .expireWith(languageServerWrapper) - .coalesceBy(coalesceBy); + var action = ReadAction.nonBlocking((Callable) () -> { + updateDiagnostics(params, project); + return null; + }).expireWith(languageServerWrapper) + .coalesceBy(coalesceBy); if (executeInSmartMode) { action.inSmartMode(project); } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/classpath/ClasspathResourceChangedManager.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/classpath/ClasspathResourceChangedManager.java index ad3b3b346..58236fd60 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/classpath/ClasspathResourceChangedManager.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/classpath/ClasspathResourceChangedManager.java @@ -25,6 +25,7 @@ import com.intellij.psi.PsiManager; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.messages.Topic; +import org.jetbrains.annotations.NotNull; import java.util.Set; @@ -53,7 +54,7 @@ public class ClasspathResourceChangedManager implements Disposable { private final MessageBusConnection appConnection; private final ClasspathResourceChangedListener listener; - public static ClasspathResourceChangedManager getInstance(Project project) { + public static ClasspathResourceChangedManager getInstance(@NotNull Project project) { return project.getService(ClasspathResourceChangedManager.class); } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/project/AbstractConfigSource.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/project/AbstractConfigSource.java index cf8610d1e..47955a7ce 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/project/AbstractConfigSource.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/project/AbstractConfigSource.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStream; +import java.nio.charset.Charset; import java.util.List; import java.util.Map; @@ -190,7 +191,7 @@ protected final T getConfig() { public void reload(PsiFile file) { reset(); String content = file.getText(); - try (InputStream input = IOUtils.toInputStream(content)) { + try (InputStream input = IOUtils.toInputStream(content, Charset.defaultCharset())) { config = loadConfig(input); lastModified = System.currentTimeMillis(); } catch (IOException e) { diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/project/PsiMicroProfileProjectManager.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/project/PsiMicroProfileProjectManager.java index 2acef6115..f143d08b2 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/project/PsiMicroProfileProjectManager.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/project/PsiMicroProfileProjectManager.java @@ -36,7 +36,7 @@ public final class PsiMicroProfileProjectManager implements Disposable { private static final String JAVA_FILE_EXTENSION = "java"; - public static PsiMicroProfileProjectManager getInstance(Project project) { + public static PsiMicroProfileProjectManager getInstance(@NotNull Project project) { return project.getService(PsiMicroProfileProjectManager.class); } diff --git a/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusDeploymentSupport.java b/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusDeploymentSupport.java index 3f0d26018..ed41db7fc 100644 --- a/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusDeploymentSupport.java +++ b/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusDeploymentSupport.java @@ -58,7 +58,7 @@ public class QuarkusDeploymentSupport implements ClasspathResourceChangedManager private final MessageBusConnection connection; private final Project project; - public static QuarkusDeploymentSupport getInstance(Project project) { + public static QuarkusDeploymentSupport getInstance(@NotNull Project project) { return project.getService(QuarkusDeploymentSupport.class); } diff --git a/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusProjectService.java b/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusProjectService.java index 5090af413..b3fd5f294 100644 --- a/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusProjectService.java +++ b/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusProjectService.java @@ -31,6 +31,7 @@ import org.eclipse.lsp4mp.commons.MicroProfileProjectInfo; import org.eclipse.lsp4mp.commons.MicroProfilePropertiesScope; import org.eclipse.lsp4mp.utils.JSONSchemaUtils; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,7 +45,7 @@ public class QuarkusProjectService implements ClasspathResourceChangedManager.Li private final Map> schemas = new ConcurrentHashMap<>(); - public static QuarkusProjectService getInstance(Project project) { + public static QuarkusProjectService getInstance(@NotNull Project project) { return project.getService(QuarkusProjectService.class); } diff --git a/src/main/java/com/redhat/devtools/intellij/quarkus/buildtool/gradle/AbstractGradleToolDelegate.java b/src/main/java/com/redhat/devtools/intellij/quarkus/buildtool/gradle/AbstractGradleToolDelegate.java index 1ee726f16..c5bddb453 100644 --- a/src/main/java/com/redhat/devtools/intellij/quarkus/buildtool/gradle/AbstractGradleToolDelegate.java +++ b/src/main/java/com/redhat/devtools/intellij/quarkus/buildtool/gradle/AbstractGradleToolDelegate.java @@ -13,18 +13,14 @@ import com.intellij.execution.RunManager; import com.intellij.execution.RunnerAndConfigurationSettings; import com.intellij.ide.util.newProjectWizard.AddModuleWizard; -import com.intellij.openapi.components.ServiceManager; -import com.intellij.openapi.externalSystem.ExternalSystemModulePropertyManager; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.externalSystem.model.settings.ExternalSystemExecutionSettings; import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId; import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType; import com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager; import com.intellij.openapi.externalSystem.service.RemoteExternalSystemFacade; -import com.intellij.openapi.externalSystem.service.project.IdeModelsProvider; -import com.intellij.openapi.externalSystem.service.project.IdeModelsProviderImpl; import com.intellij.openapi.externalSystem.service.project.ProjectDataManager; import com.intellij.openapi.externalSystem.service.project.manage.ProjectDataImportListener; -import com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManagerImpl; import com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemTaskManager; import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; import com.intellij.openapi.module.ModifiableModuleModel; @@ -160,7 +156,7 @@ private String getModuleDirPath(Module module) { */ private void collectDependencies(Module module, Path customBuildFile, Path customSettingsFile, Path outputPath, List[] result) throws IOException { try { - final ExternalSystemFacadeManager manager = ServiceManager.getService(ExternalSystemFacadeManager.class); + final ExternalSystemFacadeManager manager = ApplicationManager.getApplication().getService(ExternalSystemFacadeManager.class); ExternalSystemExecutionSettings settings = ExternalSystemApiUtil.getExecutionSettings(module.getProject(), getModuleDirPath(module), diff --git a/src/main/java/com/redhat/devtools/intellij/quarkus/facet/QuarkusFrameworkDetector.java b/src/main/java/com/redhat/devtools/intellij/quarkus/facet/QuarkusFrameworkDetector.java index d9d67b9ea..5553df95e 100644 --- a/src/main/java/com/redhat/devtools/intellij/quarkus/facet/QuarkusFrameworkDetector.java +++ b/src/main/java/com/redhat/devtools/intellij/quarkus/facet/QuarkusFrameworkDetector.java @@ -13,8 +13,8 @@ import com.intellij.facet.FacetType; import com.intellij.framework.detection.FacetBasedFrameworkDetector; import com.intellij.framework.detection.FileContentPattern; +import com.intellij.ide.highlighter.XmlFileType; import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.patterns.ElementPattern; import com.intellij.util.indexing.FileContent; import org.jetbrains.annotations.NotNull; @@ -34,7 +34,7 @@ public FacetType getFacetType() { @NotNull @Override public FileType getFileType() { - return StdFileTypes.XML; + return XmlFileType.INSTANCE; } @NotNull diff --git a/src/main/java/com/redhat/devtools/intellij/quarkus/lsp/QuarkusServer.java b/src/main/java/com/redhat/devtools/intellij/quarkus/lsp/QuarkusServer.java index 26220a382..cec31d4b9 100644 --- a/src/main/java/com/redhat/devtools/intellij/quarkus/lsp/QuarkusServer.java +++ b/src/main/java/com/redhat/devtools/intellij/quarkus/lsp/QuarkusServer.java @@ -12,6 +12,7 @@ import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.ide.plugins.PluginManager; +import com.intellij.ide.plugins.PluginManagerCore; import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.project.Project; import com.redhat.devtools.intellij.lsp4ij.server.JavaProcessCommandBuilder; @@ -23,6 +24,7 @@ import java.io.File; import java.net.URI; +import java.nio.file.Path; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -39,13 +41,17 @@ public class QuarkusServer extends ProcessStreamConnectionProvider { public QuarkusServer(Project project) { this.project = project; - IdeaPluginDescriptor descriptor = PluginManager.getPlugin(PluginId.getId("com.redhat.devtools.intellij.quarkus")); - File lsp4mpServerPath = new File(descriptor.getPath(), "lib/server/org.eclipse.lsp4mp.ls-uber.jar"); - File quarkusServerPath = new File(descriptor.getPath(), "lib/server/com.redhat.quarkus.ls.jar"); + IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("com.redhat.devtools.intellij.quarkus")); + assert descriptor != null; + Path pluginPath = descriptor.getPluginPath(); + assert pluginPath != null; + pluginPath = pluginPath.toAbsolutePath(); + Path lsp4mpServerPath = pluginPath.resolve("lib/server/org.eclipse.lsp4mp.ls-uber.jar"); + Path quarkusServerPath = pluginPath.resolve("lib/server/com.redhat.quarkus.ls.jar"); List commands = new JavaProcessCommandBuilder(project, "microprofile") - .setJar(lsp4mpServerPath.getAbsolutePath()) - .setCp(quarkusServerPath.getAbsolutePath()) + .setJar(lsp4mpServerPath.toString()) + .setCp(quarkusServerPath.toString()) .create(); commands.add("-DrunAsync=true"); super.setCommands(commands); diff --git a/src/main/java/com/redhat/devtools/intellij/qute/facet/QuteFrameworkDetector.java b/src/main/java/com/redhat/devtools/intellij/qute/facet/QuteFrameworkDetector.java index 602ceb653..71b5c6e18 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/facet/QuteFrameworkDetector.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/facet/QuteFrameworkDetector.java @@ -13,8 +13,8 @@ import com.intellij.facet.FacetType; import com.intellij.framework.detection.FacetBasedFrameworkDetector; import com.intellij.framework.detection.FileContentPattern; +import com.intellij.ide.highlighter.XmlFileType; import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.patterns.ElementPattern; import com.intellij.util.indexing.FileContent; import org.jetbrains.annotations.NotNull; @@ -34,7 +34,7 @@ public FacetType getFacetType() { @NotNull @Override public FileType getFileType() { - return StdFileTypes.XML; + return XmlFileType.INSTANCE; } @NotNull diff --git a/src/main/java/com/redhat/devtools/intellij/qute/lang/psi/QuteElementType.java b/src/main/java/com/redhat/devtools/intellij/qute/lang/psi/QuteElementType.java index f1c4bbcd2..422c9c6f8 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/lang/psi/QuteElementType.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/lang/psi/QuteElementType.java @@ -22,6 +22,6 @@ public QuteElementType(@NonNls @NotNull String debugName) { @Override public String toString() { - return "QuteElementType." + getDebugName(); + return "QuteElementType." + super.toString(); } } diff --git a/src/main/java/com/redhat/devtools/intellij/qute/lsp/QuteServer.java b/src/main/java/com/redhat/devtools/intellij/qute/lsp/QuteServer.java index adf8cce26..1146a6808 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/lsp/QuteServer.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/lsp/QuteServer.java @@ -12,6 +12,7 @@ import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.ide.plugins.PluginManager; +import com.intellij.ide.plugins.PluginManagerCore; import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.project.Project; import com.redhat.devtools.intellij.lsp4ij.server.JavaProcessCommandBuilder; @@ -23,6 +24,7 @@ import java.io.File; import java.net.URI; +import java.nio.file.Path; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -39,11 +41,14 @@ public class QuteServer extends ProcessStreamConnectionProvider { public QuteServer(Project project) { this.project = project; - IdeaPluginDescriptor descriptor = PluginManager.getPlugin(PluginId.getId("com.redhat.devtools.intellij.quarkus")); - File quteServerPath = new File(descriptor.getPath(), "lib/server/com.redhat.qute.ls-uber.jar"); + IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("com.redhat.devtools.intellij.quarkus")); + assert descriptor != null; + Path pluginPath = descriptor.getPluginPath(); + assert pluginPath != null; + Path quteServerPath = pluginPath.toAbsolutePath().resolve("lib/server/com.redhat.qute.ls-uber.jar"); List commands = new JavaProcessCommandBuilder(project, "qute") - .setJar(quteServerPath.getAbsolutePath()) + .setJar(quteServerPath.toString()) .create(); commands.add("-DrunAsync=true"); super.setCommands(commands); diff --git a/src/main/resources/META-INF/lsp4ij.xml b/src/main/resources/META-INF/lsp4ij.xml index 6e9ed2fdc..c884e9c91 100644 --- a/src/main/resources/META-INF/lsp4ij.xml +++ b/src/main/resources/META-INF/lsp4ij.xml @@ -57,6 +57,7 @@ implementation="com.redhat.devtools.intellij.lsp4ij.operations.documentLink.LSPDocumentLinkGotoDeclarationHandler"/> +