Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix some deprecation warnings #1258

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MessageActionItem> 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<MessageActionItem> future = new CompletableFuture<>();

ApplicationManager.getApplication().invokeLater(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.jetbrains.annotations.NotNull;

import java.net.URI;
import java.util.concurrent.Callable;
import java.util.function.Consumer;

/**
Expand All @@ -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()) {
Expand All @@ -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<Void>) () -> {
updateDiagnostics(params, project);
return null;
}).expireWith(languageServerWrapper)
.coalesceBy(coalesceBy);
if (executeInSmartMode) {
action.inSmartMode(project);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

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

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

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

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

Expand All @@ -44,7 +45,7 @@ public class QuarkusProjectService implements ClasspathResourceChangedManager.Li

private final Map<Module, MutablePair<VirtualFile, Boolean>> schemas = new ConcurrentHashMap<>();

public static QuarkusProjectService getInstance(Project project) {
public static QuarkusProjectService getInstance(@NotNull Project project) {
return project.getService(QuarkusProjectService.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -160,7 +156,7 @@ private String getModuleDirPath(Module module) {
*/
private void collectDependencies(Module module, Path customBuildFile, Path customSettingsFile, Path outputPath, List<VirtualFile>[] 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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,7 +34,7 @@ public FacetType<QuarkusFacet, QuarkusFacetConfiguration> getFacetType() {
@NotNull
@Override
public FileType getFileType() {
return StdFileTypes.XML;
return XmlFileType.INSTANCE;
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,7 +34,7 @@ public FacetType<QuteFacet, QuteFacetConfiguration> getFacetType() {
@NotNull
@Override
public FileType getFileType() {
return StdFileTypes.XML;
return XmlFileType.INSTANCE;
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public QuteElementType(@NonNls @NotNull String debugName) {

@Override
public String toString() {
return "QuteElementType." + getDebugName();
return "QuteElementType." + super.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<String> commands = new JavaProcessCommandBuilder(project, "qute")
.setJar(quteServerPath.getAbsolutePath())
.setJar(quteServerPath.toString())
.create();
commands.add("-DrunAsync=true");
super.setCommands(commands);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/lsp4ij.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
implementation="com.redhat.devtools.intellij.lsp4ij.operations.documentLink.LSPDocumentLinkGotoDeclarationHandler"/>
<highlightUsagesHandlerFactory
implementation="com.redhat.devtools.intellij.lsp4ij.operations.highlight.LSPHighlightUsagesHandlerFactory"/>
<notificationGroup id="Language Server Protocol" displayType="BALLOON" hideFromSettings="true"/>
</extensions>

<applicationListeners>
Expand Down
Loading