Skip to content

Commit

Permalink
fix: use plugin disposable instead of project
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Apr 24, 2024
1 parent 4c5ed29 commit 338ea33
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 10 deletions.
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 com.redhat.devtools.intellij.quarkus.QuarkusPluginDisposable;
import org.jetbrains.annotations.NotNull;

import java.util.Set;
Expand All @@ -35,7 +36,7 @@
*
* <code>
* ClasspathResourceChangeManager.Listener myListener = ...
* project.getMessageBus().connect(project).subscribe(ClasspathResourceChangeManager.TOPIC, myListener);
* project.getMessageBus().connect(QuarkusPluginDisposable.getInstance(project)).subscribe(ClasspathResourceChangeManager.TOPIC, myListener);
* </code>
*
*
Expand Down Expand Up @@ -72,15 +73,15 @@ public ClasspathResourceChangedManager(Project project) {
// Send source files changed in debounce mode
this.resourceChangedNotifier = new ClasspathResourceChangedNotifier(project);
listener = new ClasspathResourceChangedListener(this);
projectConnection = project.getMessageBus().connect();
projectConnection = project.getMessageBus().connect(QuarkusPluginDisposable.getInstance(project));
// Track end of Java libraries update
LibraryTablesRegistrar.getInstance().getLibraryTable(project).addListener(listener);
// Track update of Psi Java, properties files
PsiManager.getInstance(project).addPsiTreeChangeListener(listener, project);
// Track modules changes
projectConnection.subscribe(ProjectTopics.MODULES, listener);
// Track delete, create, update of file
appConnection = ApplicationManager.getApplication().getMessageBus().connect(project);
appConnection = ApplicationManager.getApplication().getMessageBus().connect(QuarkusPluginDisposable.getInstance());
appConnection.subscribe(VirtualFileManager.VFS_CHANGES, listener);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.messages.MessageBusConnection;
import com.redhat.devtools.intellij.lsp4mp4ij.classpath.ClasspathResourceChangedManager;
import com.redhat.devtools.intellij.quarkus.QuarkusPluginDisposable;
import org.jetbrains.annotations.NotNull;

import java.util.Set;
Expand Down Expand Up @@ -84,7 +85,7 @@ private void evict(Module javaProject) {
private PsiMicroProfileProjectManager(Project project) {
this.project = project;
microprofileProjectListener = new MicroProfileProjectListener();
connection = project.getMessageBus().connect(project);
connection = project.getMessageBus().connect(QuarkusPluginDisposable.getInstance(project));
connection.subscribe(ClasspathResourceChangedManager.TOPIC, microprofileProjectListener);
connection.subscribe(ProjectTopics.MODULES, microprofileProjectListener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static QuarkusDeploymentSupport getInstance(@NotNull Project project) {

public QuarkusDeploymentSupport(Project project) {
this.project = project;
connection = project.getMessageBus().connect(project);
connection = project.getMessageBus().connect(QuarkusPluginDisposable.getInstance(project));
connection.subscribe(ClasspathResourceChangedManager.TOPIC, this);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.redhat.devtools.intellij.quarkus;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

/**
* The service is intended to be used instead of a project/application as a parent disposable.
*
* copied from https://github.com/JetBrains/intellij-community/blob/idea/241.14494.240/python/openapi/src/com/jetbrains/python/PythonPluginDisposable.java
*/
@Service({Service.Level.APP, Service.Level.PROJECT})
public final class QuarkusPluginDisposable implements Disposable {
public static @NotNull Disposable getInstance() {
return ApplicationManager.getApplication().getService(QuarkusPluginDisposable.class);
}

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

@Override
public void dispose() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static QuarkusProjectService getInstance(@NotNull Project project) {
private final MessageBusConnection connection;

public QuarkusProjectService(Project project) {
connection = project.getMessageBus().connect();
connection = project.getMessageBus().connect(QuarkusPluginDisposable.getInstance(project));
connection.subscribe(ClasspathResourceChangedManager.TOPIC, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.redhat.devtools.intellij.lsp4mp4ij.settings.UserDefinedMicroProfileSettings;
import com.redhat.devtools.intellij.quarkus.QuarkusDeploymentSupport;
import com.redhat.devtools.intellij.quarkus.QuarkusModuleUtil;
import com.redhat.devtools.intellij.quarkus.QuarkusPluginDisposable;
import com.redhat.devtools.lsp4ij.JSONUtils;
import com.redhat.devtools.lsp4ij.client.CoalesceByKey;
import com.redhat.devtools.lsp4ij.client.IndexAwareLanguageClient;
Expand Down Expand Up @@ -59,10 +60,10 @@ public class QuarkusLanguageClient extends IndexAwareLanguageClient implements M

public QuarkusLanguageClient(Project project) {
super(project);
// Call Quarkus deployment support here to react on library changed (to evict quarkus deploiement cache) before
// Call Quarkus deployment support here to react on library changed (to evict quarkus deployment cache) before
// sending an LSP microprofile/propertiesChanged notifications
QuarkusDeploymentSupport.getInstance(project);
connection = project.getMessageBus().connect(project);
connection = project.getMessageBus().connect(QuarkusPluginDisposable.getInstance(project));
connection.subscribe(ClasspathResourceChangedManager.TOPIC, this);
inspectionsInfo = MicroProfileInspectionsInfo.getMicroProfileInspectionInfo(project);
connection.subscribe(ProfileChangeAdapter.TOPIC, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.Project;
import com.intellij.util.concurrency.NonUrgentExecutor;
import com.intellij.util.messages.MessageBusConnection;
import com.redhat.devtools.intellij.quarkus.QuarkusModuleUtil;
import com.redhat.devtools.intellij.quarkus.QuarkusPluginDisposable;
import com.redhat.devtools.intellij.quarkus.buildtool.BuildToolDelegate;
import com.redhat.devtools.intellij.quarkus.buildtool.ProjectImportListener;
import com.redhat.devtools.intellij.quarkus.settings.UserDefinedQuarkusSettings;
Expand All @@ -34,6 +36,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CancellationException;

/**
* Quarkus run configuration manager used to:
Expand Down Expand Up @@ -92,7 +95,7 @@ public QuarkusRunConfigurationManager(Project project) {

@NotNull
private MessageBusConnection addProjectImportListener(Project project) {
MessageBusConnection connection = project.getMessageBus().connect();
MessageBusConnection connection = project.getMessageBus().connect(QuarkusPluginDisposable.getInstance(project));
ProjectImportListener listener = new ProjectImportListener() {

@Override
Expand Down Expand Up @@ -183,6 +186,8 @@ private boolean addQuarkusRunConfigurationTypeInServicesViewIfNeeded(boolean log
runDashboardManager.setTypes(types);
}
return true;
} catch (ProcessCanceledException | CancellationException ignored) {
return false;
} catch (Exception e) {
// This case comes from when Ultimate is used and Ultimate Quarkus support update in same time their Quarkus Configuration Type.
// java.util.ConcurrentModificationException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.profile.ProfileChangeAdapter;
import com.intellij.util.messages.MessageBusConnection;
import com.redhat.devtools.intellij.quarkus.QuarkusPluginDisposable;
import com.redhat.devtools.lsp4ij.client.CoalesceByKey;
import com.redhat.devtools.lsp4ij.client.IndexAwareLanguageClient;
import com.redhat.devtools.intellij.lsp4mp4ij.classpath.ClasspathResourceChangedManager;
Expand Down Expand Up @@ -54,7 +55,7 @@ public class QuteLanguageClient extends IndexAwareLanguageClient implements Qute

public QuteLanguageClient(Project project) {
super(project);
connection = project.getMessageBus().connect(project);
connection = project.getMessageBus().connect(QuarkusPluginDisposable.getInstance(project));
connection.subscribe(ClasspathResourceChangedManager.TOPIC, this);
inspectionsInfo = QuteInspectionsInfo.getQuteInspectionsInfo(project);
connection.subscribe(ProfileChangeAdapter.TOPIC, this);
Expand Down

0 comments on commit 338ea33

Please sign in to comment.