Skip to content

Commit

Permalink
fix: Error while adding QuarkusRunConfigurationType in Services view
Browse files Browse the repository at this point in the history
settings

Fixes #1299

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed May 6, 2024
1 parent 4c5ed29 commit 103cdbb
Show file tree
Hide file tree
Showing 5 changed files with 434 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@

import java.util.Collections;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.extensions.RequiredElement;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.serviceContainer.BaseKeyedLazyInstance;
import com.intellij.util.xmlb.annotations.Attribute;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.java.codeaction.IJavaCodeActionParticipant;
Expand Down Expand Up @@ -59,6 +62,8 @@ public String getParticipantId() {
public boolean isAdaptedForCodeAction(JavaCodeActionContext context) {
try {
return getInstance().isAdaptedForCodeAction(context);
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException t) {
throw t;
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Error while calling isAdaptedForCodeAction", e);
return false;
Expand All @@ -70,6 +75,8 @@ public List<? extends CodeAction> getCodeActions(JavaCodeActionContext context,
try {
List<? extends CodeAction> codeActions = getInstance().getCodeActions(context, diagnostic);
return codeActions != null ? codeActions : Collections.emptyList();
} catch (IndexNotReadyException | ProcessCanceledException | CancellationException t) {
throw t;
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Error while calling getCodeActions", e);
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,34 +115,8 @@ private void tryToCreateRunConfigurations(List<Module> modules) {
return;
}

boolean runConfigurationCreated = false;
for (Module module : modules) {
if (tryToCreateRunConfiguration(module)) {
runConfigurationCreated = true;
}
}
if (runConfigurationCreated) {
if (!addQuarkusRunConfigurationTypeInServicesViewIfNeeded(true)) {
// The Services view is not updated correctly (when Ultimate is used and it tries to update the services view insame time) because of this error
// java.util.ConcurrentModificationException
// at java.base/java.util.HashMap$HashIterator.nextNode(HashMap.java:1597)
// at java.base/java.util.HashMap$KeyIterator.next(HashMap.java:1620)
// at com.google.common.collect.Sets$3$1.computeNext(Sets.java:907)
// at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:145)
// at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:140)
// at java.base/java.util.AbstractCollection.addAll(AbstractCollection.java:335)
// at java.base/java.util.HashSet.<init>(HashSet.java:121)
// at com.intellij.execution.dashboard.RunDashboardManagerImpl.setTypes(RunDashboardManagerImpl.java:295)
// at

// We retry 5 times to update it
for (int i = 0; i < 5; i++) {
if (addQuarkusRunConfigurationTypeInServicesViewIfNeeded(i == 4)) {
// The update is done correctly
break;
}
}
}
tryToCreateRunConfiguration(module);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2024 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package com.redhat.devtools.intellij.quarkus.run.dashboard;

import com.intellij.execution.dashboard.RunDashboardDefaultTypesProvider;
import com.intellij.openapi.project.Project;
import com.redhat.devtools.intellij.quarkus.run.QuarkusRunConfigurationType;
import com.redhat.devtools.intellij.quarkus.settings.UserDefinedQuarkusSettings;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Collections;

/**
* Add automatically the {@link QuarkusRunConfigurationType#ID} type in the run dashboard when
* the option 'Create "Quarkus Dev Mode" run configuration on project import' is actiavted.
*/
public class QuarkusRunDashboardDefaultTypesProvider implements RunDashboardDefaultTypesProvider {

@Override
public @NotNull Collection<String> getDefaultTypeIds(@NotNull Project project) {
if (!UserDefinedQuarkusSettings.getInstance(project).isCreateQuarkusRunConfigurationOnProjectImport()) {
return Collections.emptyList();
}
return Collections.singleton(QuarkusRunConfigurationType.ID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ public abstract class TemplateDataVisitor extends JavaElementVisitor {

@Override
public void visitMethodCallExpression(PsiMethodCallExpression node) {
String methodName = node.resolveMethod().getName();
var resolvedMethod = node.resolveMethod();
if (resolvedMethod == null) {
return;
}
String methodName = resolvedMethod.getName();
if (DATA_METHOD.equals(methodName)) {
// collect the first data method
// ex : hello.data("height", 1.50, "weight", 50L);
Expand Down
Loading

0 comments on commit 103cdbb

Please sign in to comment.