From 14cd98c2f396c4767f4bae437a62664dec03de69 Mon Sep 17 00:00:00 2001 From: Fred Bricon Date: Mon, 4 Sep 2023 10:56:27 +0200 Subject: [PATCH 1/2] feat: add command to update microprofile configuration from LSP4MP Signed-off-by: Fred Bricon --- .../codeactions/LSPLazyCodeActionIntentionAction.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/codeactions/LSPLazyCodeActionIntentionAction.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/codeactions/LSPLazyCodeActionIntentionAction.java index 2c9a81afc..72260e480 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/codeactions/LSPLazyCodeActionIntentionAction.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/codeactions/LSPLazyCodeActionIntentionAction.java @@ -16,6 +16,8 @@ import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInspection.util.IntentionFamilyName; import com.intellij.codeInspection.util.IntentionName; +import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.impl.SimpleDataContext; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; From ec8547946f86794d3a96b981d576e5ea469267c9 Mon Sep 17 00:00:00 2001 From: Fred Bricon Date: Tue, 5 Sep 2023 14:12:56 +0200 Subject: [PATCH 2/2] feat: add command to update Qute configuration from Qute LS Signed-off-by: Fred Bricon --- .../AbstractDelegateInspection.java | 2 +- ...ractDelegateInspectionWithExclusions.java} | 21 ++- .../LSPLazyCodeActionIntentionAction.java | 2 - .../ui/components/InspectionHyperlink.java | 45 ++++++ ...MicroprofileUpdateConfigurationAction.java | 7 +- ...ProfilePropertiesDuplicatesInspection.java | 2 + ...rofilePropertiesExpressionsInspection.java | 2 + ...croProfilePropertiesGlobalInspection.java} | 7 +- ...roProfilePropertiesRequiredInspection.java | 2 + ...icroProfilePropertiesSyntaxInspection.java | 2 + ...ProfilePropertiesUnassignedInspection.java | 10 +- ...croProfilePropertiesUnknownInspection.java | 7 +- ...MicroProfilePropertiesValueInspection.java | 4 +- .../settings/MicroProfileConfigurable.java | 15 +- .../settings/MicroProfileInspectionsInfo.java | 17 +- .../lsp4mp4ij/settings/MicroProfileView.java | 23 ++- .../UserDefinedMicroProfileSettings.java | 2 +- .../quarkus/lsp/QuarkusLanguageClient.java | 2 +- .../intellij/qute/lsp/QuteServer.java | 2 +- .../QuteUpdateConfigurationAction.java | 145 ++++++++++++++++++ .../inspections/QuteGlobalInspection.java | 28 ++++ .../QuteUndefinedNamespaceInspection.java | 2 + .../QuteUndefinedObjectInspection.java | 2 + .../qute/settings/QuteConfigurable.java | 5 +- .../qute/settings/QuteInspectionsInfo.java | 48 +++++- .../intellij/qute/settings/QuteView.java | 12 +- .../settings/UserDefinedQuteSettings.java | 5 +- .../resources/META-INF/lsp4ij-quarkus.xml | 10 +- src/main/resources/META-INF/lsp4ij-qute.xml | 12 +- src/main/resources/META-INF/plugin.xml | 2 + .../messages/MicroProfileBundle.properties | 1 + .../resources/messages/QuteBundle.properties | 2 + 32 files changed, 373 insertions(+), 75 deletions(-) rename src/main/java/com/redhat/devtools/intellij/{qute/psi/core => lsp4ij}/inspections/AbstractDelegateInspection.java (93%) rename src/main/java/com/redhat/devtools/intellij/{lsp4mp4ij/psi/core/inspections/AbstractDelegateInspectionWithExcludedProperties.java => lsp4ij/inspections/AbstractDelegateInspectionWithExclusions.java} (63%) create mode 100644 src/main/java/com/redhat/devtools/intellij/lsp4ij/ui/components/InspectionHyperlink.java rename src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/{AbstractDelegateInspection.java => MicroProfilePropertiesGlobalInspection.java} (66%) create mode 100644 src/main/java/com/redhat/devtools/intellij/qute/psi/core/command/QuteUpdateConfigurationAction.java create mode 100644 src/main/java/com/redhat/devtools/intellij/qute/psi/core/inspections/QuteGlobalInspection.java diff --git a/src/main/java/com/redhat/devtools/intellij/qute/psi/core/inspections/AbstractDelegateInspection.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/inspections/AbstractDelegateInspection.java similarity index 93% rename from src/main/java/com/redhat/devtools/intellij/qute/psi/core/inspections/AbstractDelegateInspection.java rename to src/main/java/com/redhat/devtools/intellij/lsp4ij/inspections/AbstractDelegateInspection.java index 6e248a850..daca8791a 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/psi/core/inspections/AbstractDelegateInspection.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/inspections/AbstractDelegateInspection.java @@ -11,7 +11,7 @@ * Contributors: * Red Hat Inc. - initial API and implementation *******************************************************************************/ -package com.redhat.devtools.intellij.qute.psi.core.inspections; +package com.redhat.devtools.intellij.lsp4ij.inspections; import com.intellij.codeInspection.LocalInspectionTool; diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/AbstractDelegateInspectionWithExcludedProperties.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/inspections/AbstractDelegateInspectionWithExclusions.java similarity index 63% rename from src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/AbstractDelegateInspectionWithExcludedProperties.java rename to src/main/java/com/redhat/devtools/intellij/lsp4ij/inspections/AbstractDelegateInspectionWithExclusions.java index c67bf92fb..a2bc0357d 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/AbstractDelegateInspectionWithExcludedProperties.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/inspections/AbstractDelegateInspectionWithExclusions.java @@ -11,12 +11,11 @@ * Contributors: * Red Hat Inc. - initial API and implementation *******************************************************************************/ -package com.redhat.devtools.intellij.lsp4mp4ij.psi.core.inspections; +package com.redhat.devtools.intellij.lsp4ij.inspections; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.ui.InspectionOptionsPanel; import com.intellij.codeInspection.ui.ListEditForm; -import com.redhat.devtools.intellij.lsp4mp4ij.MicroProfileBundle; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -24,17 +23,27 @@ import java.util.List; /** - * No-op {@link LocalInspectionTool} used as a basis for mapping properties inspection severities to matching LSP severities. - * Adds the possibility to define excluded properties. + * Base {@link LocalInspectionTool} providing the possibility to define exclusions. */ -public abstract class AbstractDelegateInspectionWithExcludedProperties extends LocalInspectionTool { +public abstract class AbstractDelegateInspectionWithExclusions extends LocalInspectionTool { + private final String exclusionsLabel; + + /** + * Inspection constructor + * @param exclusionsLabel the label to use for the exclusion component in the options panel + */ + public AbstractDelegateInspectionWithExclusions(@NotNull String exclusionsLabel) { + this.exclusionsLabel = exclusionsLabel; + } + + //Field is public, so it can be serialized as XML public final @NotNull List excludeList = new ArrayList<>(); public JComponent createOptionsPanel() { InspectionOptionsPanel panel = new InspectionOptionsPanel(); - var injectionListTable = new ListEditForm("", MicroProfileBundle.message("microprofile.properties.validation.excluded.properties"), excludeList); + var injectionListTable = new ListEditForm("", exclusionsLabel, excludeList); panel.addGrowing(injectionListTable.getContentPanel()); diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/codeactions/LSPLazyCodeActionIntentionAction.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/codeactions/LSPLazyCodeActionIntentionAction.java index 72260e480..2c9a81afc 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/codeactions/LSPLazyCodeActionIntentionAction.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/codeactions/LSPLazyCodeActionIntentionAction.java @@ -16,8 +16,6 @@ import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInspection.util.IntentionFamilyName; import com.intellij.codeInspection.util.IntentionName; -import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.actionSystem.impl.SimpleDataContext; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/ui/components/InspectionHyperlink.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/ui/components/InspectionHyperlink.java new file mode 100644 index 000000000..9fc4a45d2 --- /dev/null +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/ui/components/InspectionHyperlink.java @@ -0,0 +1,45 @@ +package com.redhat.devtools.intellij.lsp4ij.ui.components; + +import com.intellij.ide.DataManager; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.options.ex.Settings; +import com.intellij.openapi.util.NlsContexts; +import com.intellij.profile.codeInspection.ui.ErrorsConfigurable; +import com.intellij.ui.HyperlinkLabel; +import com.redhat.devtools.intellij.lsp4mp4ij.MicroProfileBundle; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.event.HyperlinkEvent; + +/** + * HyperlinkLabel that opens an inspection settings page + */ +public class InspectionHyperlink extends HyperlinkLabel { + + /** + * Creates a new hyperlink to an inspection settings page + * @param label the hyperlink label + * @param inspectionGroupPath the group path to open in the inspections settings + */ + public InspectionHyperlink(@NotNull @NlsContexts.LinkLabel String label, @NotNull String inspectionGroupPath) { + super(label); + addHyperlinkListener(e -> { + if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) { + @NotNull DataContext dataContext = DataManager.getInstance().getDataContext(this); + @Nullable Settings settings = Settings.KEY.getData(dataContext); + if (settings != null) { + @Nullable ErrorsConfigurable inspections = settings.find(ErrorsConfigurable.class); + if (inspections != null) { + settings.select(inspections).doWhenDone(new Runnable() { + @Override + public void run() { + inspections.selectInspectionGroup(new String[]{inspectionGroupPath}); + } + }); + } + } + } + }); + } +} diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/command/MicroprofileUpdateConfigurationAction.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/command/MicroprofileUpdateConfigurationAction.java index 238bbd9de..9170f6d80 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/command/MicroprofileUpdateConfigurationAction.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/command/MicroprofileUpdateConfigurationAction.java @@ -25,7 +25,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.impl.FakePsiElement; import com.redhat.devtools.intellij.lsp4ij.commands.CommandExecutor; -import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.inspections.AbstractDelegateInspectionWithExcludedProperties; +import com.redhat.devtools.intellij.lsp4ij.inspections.AbstractDelegateInspectionWithExclusions; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.inspections.MicroProfilePropertiesUnassignedInspection; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.inspections.MicroProfilePropertiesUnknownInspection; import org.eclipse.lsp4j.Command; @@ -43,7 +43,6 @@ public class MicroprofileUpdateConfigurationAction extends AnAction { private final Map updaters = new HashMap<>(); public MicroprofileUpdateConfigurationAction() { - //TODO potentially load those from an extension point? updaters.put("microprofile.tools.validation.unknown.excluded", new InspectionConfigurationUpdater(MicroProfilePropertiesUnknownInspection.ID)); updaters.put("microprofile.tools.validation.unassigned.excluded", new InspectionConfigurationUpdater(MicroProfilePropertiesUnassignedInspection.ID)); } @@ -99,8 +98,8 @@ public void updateConfiguration(Project project, JsonElement value) { private void updateConfiguration(Project project, @NotNull String value) { InspectionProfile profile = InspectionProfileManager.getInstance(project).getCurrentProfile(); InspectionToolWrapper toolWrapper = profile.getInspectionTool(inspectionId, project); - if (toolWrapper != null && toolWrapper.getTool() instanceof AbstractDelegateInspectionWithExcludedProperties) { - Key key = new Key<>(inspectionId); + if (toolWrapper != null && toolWrapper.getTool() instanceof AbstractDelegateInspectionWithExclusions) { + Key key = new Key<>(inspectionId); profile.modifyToolSettings(key, getPsiElement(project), (tool) -> { tool.excludeList.add(value); }); diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesDuplicatesInspection.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesDuplicatesInspection.java index 3f3fc890a..310b2ed9a 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesDuplicatesInspection.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesDuplicatesInspection.java @@ -13,6 +13,8 @@ *******************************************************************************/ package com.redhat.devtools.intellij.lsp4mp4ij.psi.core.inspections; +import com.redhat.devtools.intellij.lsp4ij.inspections.AbstractDelegateInspection; + /** * Dummy inspection for duplicate properties in Microprofile properties files */ diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesExpressionsInspection.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesExpressionsInspection.java index 7b2949fda..5438b3a2f 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesExpressionsInspection.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesExpressionsInspection.java @@ -13,6 +13,8 @@ *******************************************************************************/ package com.redhat.devtools.intellij.lsp4mp4ij.psi.core.inspections; +import com.redhat.devtools.intellij.lsp4ij.inspections.AbstractDelegateInspection; + /** * Dummy inspection for expression values in Microprofile properties files */ diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/AbstractDelegateInspection.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesGlobalInspection.java similarity index 66% rename from src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/AbstractDelegateInspection.java rename to src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesGlobalInspection.java index 9c5f28726..24a8702be 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/AbstractDelegateInspection.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesGlobalInspection.java @@ -13,10 +13,11 @@ *******************************************************************************/ package com.redhat.devtools.intellij.lsp4mp4ij.psi.core.inspections; -import com.intellij.codeInspection.LocalInspectionTool; +import com.redhat.devtools.intellij.lsp4ij.inspections.AbstractDelegateInspection; /** - * No-op {@link LocalInspectionTool} used as a basis for mapping inspection severities to matching LSP severities. + * Dummy inspection for general validation in Microprofile properties files */ -public abstract class AbstractDelegateInspection extends LocalInspectionTool { +public class MicroProfilePropertiesGlobalInspection extends AbstractDelegateInspection { + public static final String ID = getShortName(MicroProfilePropertiesGlobalInspection.class.getSimpleName()); } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesRequiredInspection.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesRequiredInspection.java index 33c4aa717..9fd408288 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesRequiredInspection.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesRequiredInspection.java @@ -13,6 +13,8 @@ *******************************************************************************/ package com.redhat.devtools.intellij.lsp4mp4ij.psi.core.inspections; +import com.redhat.devtools.intellij.lsp4ij.inspections.AbstractDelegateInspection; + /** * Dummy inspection for missing required properties in Microprofile properties files */ diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesSyntaxInspection.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesSyntaxInspection.java index e13c0bf3b..13a318021 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesSyntaxInspection.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesSyntaxInspection.java @@ -13,6 +13,8 @@ *******************************************************************************/ package com.redhat.devtools.intellij.lsp4mp4ij.psi.core.inspections; +import com.redhat.devtools.intellij.lsp4ij.inspections.AbstractDelegateInspection; + /** * Dummy inspection for property syntax errors in Microprofile properties files */ diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesUnassignedInspection.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesUnassignedInspection.java index b3c4b078a..f0791a415 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesUnassignedInspection.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesUnassignedInspection.java @@ -13,9 +13,17 @@ *******************************************************************************/ package com.redhat.devtools.intellij.lsp4mp4ij.psi.core.inspections; +import com.redhat.devtools.intellij.lsp4ij.inspections.AbstractDelegateInspectionWithExclusions; +import com.redhat.devtools.intellij.lsp4mp4ij.MicroProfileBundle; +import org.jetbrains.annotations.NotNull; + /** * Dummy inspection for unknown properties in Microprofile properties files */ -public class MicroProfilePropertiesUnassignedInspection extends AbstractDelegateInspectionWithExcludedProperties { +public class MicroProfilePropertiesUnassignedInspection extends AbstractDelegateInspectionWithExclusions { public static final String ID = getShortName(MicroProfilePropertiesUnassignedInspection.class.getSimpleName()); + + public MicroProfilePropertiesUnassignedInspection() { + super(MicroProfileBundle.message("microprofile.properties.validation.excluded.properties")); + } } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesUnknownInspection.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesUnknownInspection.java index e8cb383c8..5ca04a4b7 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesUnknownInspection.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesUnknownInspection.java @@ -13,16 +13,19 @@ *******************************************************************************/ package com.redhat.devtools.intellij.lsp4mp4ij.psi.core.inspections; +import com.redhat.devtools.intellij.lsp4ij.inspections.AbstractDelegateInspectionWithExclusions; +import com.redhat.devtools.intellij.lsp4mp4ij.MicroProfileBundle; + import java.util.Arrays; /** * Dummy inspection for unknown properties in Microprofile properties files */ -public class MicroProfilePropertiesUnknownInspection extends AbstractDelegateInspectionWithExcludedProperties { +public class MicroProfilePropertiesUnknownInspection extends AbstractDelegateInspectionWithExclusions { public static final String ID = getShortName(MicroProfilePropertiesUnknownInspection.class.getSimpleName()); public MicroProfilePropertiesUnknownInspection() { - super(); + super(MicroProfileBundle.message("microprofile.properties.validation.excluded.properties")); excludeList.addAll(Arrays.asList("*/mp-rest/providers/*/priority", "mp.openapi.schema.*", "kafka-streams.*", "camel.*")); } } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesValueInspection.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesValueInspection.java index 8d805c567..852414af3 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesValueInspection.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesValueInspection.java @@ -13,9 +13,11 @@ *******************************************************************************/ package com.redhat.devtools.intellij.lsp4mp4ij.psi.core.inspections; +import com.intellij.codeInspection.LocalInspectionTool; + /** * Dummy inspection for invalid values in Microprofile properties files */ -public class MicroProfilePropertiesValueInspection extends AbstractDelegateInspection { +public class MicroProfilePropertiesValueInspection extends LocalInspectionTool { public static final String ID = getShortName(MicroProfilePropertiesValueInspection.class.getSimpleName()); } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/MicroProfileConfigurable.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/MicroProfileConfigurable.java index 716bdcca5..ca6c93c7a 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/MicroProfileConfigurable.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/MicroProfileConfigurable.java @@ -61,25 +61,12 @@ public void setDisplayName(String name) { } - @Override - public void reset() { - if (myView == null) return; - UserDefinedMicroProfileSettings settings = UserDefinedMicroProfileSettings.getInstance(project); - myView.setValidationEnabled(settings.isValidationEnabled()); - } - @Override public boolean isModified() { - if (myView == null) return false; - UserDefinedMicroProfileSettings settings = UserDefinedMicroProfileSettings.getInstance(project); - return !(myView.isValidationEnabled()== settings.isValidationEnabled()); + return false; } @Override public void apply() throws ConfigurationException { - if (myView == null) return; - UserDefinedMicroProfileSettings settings = UserDefinedMicroProfileSettings.getInstance(project); - settings.setValidationEnabled(myView.isValidationEnabled()); - settings.fireStateChanged(); } } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/MicroProfileInspectionsInfo.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/MicroProfileInspectionsInfo.java index 2f734dc31..e994db2c7 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/MicroProfileInspectionsInfo.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/MicroProfileInspectionsInfo.java @@ -17,6 +17,7 @@ import com.intellij.codeInspection.ex.InspectionToolWrapper; import com.intellij.openapi.project.Project; import com.intellij.profile.codeInspection.InspectionProfileManager; +import com.redhat.devtools.intellij.lsp4ij.inspections.AbstractDelegateInspectionWithExclusions; import com.redhat.devtools.intellij.lsp4ij.operations.diagnostics.SeverityMapping; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.inspections.*; import org.eclipse.lsp4j.DiagnosticSeverity; @@ -42,12 +43,15 @@ public class MicroProfileInspectionsInfo { private List excludedUnknownProperties; private List excludedUnassignedProperties; + private boolean enabled = true; + private MicroProfileInspectionsInfo() { } public static MicroProfileInspectionsInfo getMicroProfileInspectionInfo(Project project) { MicroProfileInspectionsInfo wrapper = new MicroProfileInspectionsInfo(); InspectionProfile profile = InspectionProfileManager.getInstance(project).getCurrentProfile(); + wrapper.enabled = SeverityMapping.getSeverity(MicroProfilePropertiesGlobalInspection.ID, profile) != null; wrapper.syntaxSeverity = SeverityMapping.getSeverity(MicroProfilePropertiesSyntaxInspection.ID, profile); wrapper.unknownSeverity = SeverityMapping.getSeverity(MicroProfilePropertiesUnknownInspection.ID, profile); wrapper.duplicateSeverity = SeverityMapping.getSeverity(MicroProfilePropertiesDuplicatesInspection.ID, profile); @@ -65,13 +69,17 @@ public static MicroProfileInspectionsInfo getMicroProfileInspectionInfo(Project private static List getExclusions(InspectionProfile profile, String inspectionId, Project project) { List exclusions = new ArrayList<>(); InspectionToolWrapper toolWrapper = profile.getInspectionTool(inspectionId, project); - if (toolWrapper != null && toolWrapper.getTool() instanceof AbstractDelegateInspectionWithExcludedProperties) { - AbstractDelegateInspectionWithExcludedProperties inspection = (AbstractDelegateInspectionWithExcludedProperties) toolWrapper.getTool(); + if (toolWrapper != null && toolWrapper.getTool() instanceof AbstractDelegateInspectionWithExclusions) { + AbstractDelegateInspectionWithExclusions inspection = (AbstractDelegateInspectionWithExclusions) toolWrapper.getTool(); exclusions.addAll(inspection.excludeList); } return exclusions; } + public boolean enabled() { + return enabled; + } + public DiagnosticSeverity unknownSeverity() { return unknownSeverity; } @@ -113,11 +121,12 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; MicroProfileInspectionsInfo that = (MicroProfileInspectionsInfo) o; - return syntaxSeverity == that.syntaxSeverity && unknownSeverity == that.unknownSeverity && duplicateSeverity == that.duplicateSeverity && valueSeverity == that.valueSeverity && requiredSeverity == that.requiredSeverity && expressionSeverity == that.expressionSeverity && unassignedSeverity == that.unassignedSeverity && Objects.equals(excludedUnknownProperties, that.excludedUnknownProperties) && Objects.equals(excludedUnassignedProperties, that.excludedUnassignedProperties); + return enabled == that.enabled && syntaxSeverity == that.syntaxSeverity && unknownSeverity == that.unknownSeverity && duplicateSeverity == that.duplicateSeverity && valueSeverity == that.valueSeverity && requiredSeverity == that.requiredSeverity && expressionSeverity == that.expressionSeverity && unassignedSeverity == that.unassignedSeverity && Objects.equals(excludedUnknownProperties, that.excludedUnknownProperties) && Objects.equals(excludedUnassignedProperties, that.excludedUnassignedProperties); } @Override public int hashCode() { - return Objects.hash(syntaxSeverity, unknownSeverity, duplicateSeverity, valueSeverity, requiredSeverity, expressionSeverity, unassignedSeverity, excludedUnknownProperties, excludedUnassignedProperties); + return Objects.hash(enabled, syntaxSeverity, unknownSeverity, duplicateSeverity, valueSeverity, requiredSeverity, expressionSeverity, unassignedSeverity, excludedUnknownProperties, excludedUnassignedProperties); } + } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/MicroProfileView.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/MicroProfileView.java index 2cd1155ea..c721cce99 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/MicroProfileView.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/MicroProfileView.java @@ -13,17 +13,27 @@ *******************************************************************************/ package com.redhat.devtools.intellij.lsp4mp4ij.settings; +import com.intellij.ide.DataManager; import com.intellij.openapi.Disposable; +import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.options.ex.Settings; +import com.intellij.profile.codeInspection.ui.ErrorsConfigurable; +import com.intellij.ui.HyperlinkLabel; import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.components.JBCheckBox; import com.intellij.util.ui.FormBuilder; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UI; +import com.redhat.devtools.intellij.lsp4ij.ui.components.InspectionHyperlink; import com.redhat.devtools.intellij.lsp4mp4ij.MicroProfileBundle; +import net.miginfocom.layout.CC; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.border.TitledBorder; +import javax.swing.event.HyperlinkEvent; /** * MicroProfile view. @@ -32,8 +42,6 @@ public class MicroProfileView implements Disposable { private final JPanel myMainPanel; - private JBCheckBox validationEnabledCheckBox = new JBCheckBox(MicroProfileBundle.message("microprofile.validation.enabled")); - public MicroProfileView() { JPanel settingsPanel = createSettings(); this.myMainPanel = JBUI.Panels.simplePanel(10,10) @@ -43,7 +51,7 @@ public MicroProfileView() { private JPanel createSettings() { return FormBuilder.createFormBuilder() - .addComponent(validationEnabledCheckBox) + .addComponent(new InspectionHyperlink("Configure Microprofile inspections", "MicroProfile")) .addComponentFillVertically(new JPanel(), 0) .getPanel(); } @@ -56,13 +64,4 @@ public JComponent getComponent() { public void dispose() { } - - public boolean isValidationEnabled() { - return validationEnabledCheckBox.isSelected(); - } - - public void setValidationEnabled(boolean enable) { - validationEnabledCheckBox.setSelected(enable); - } - } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/UserDefinedMicroProfileSettings.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/UserDefinedMicroProfileSettings.java index f067d1548..b41f9d0d7 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/UserDefinedMicroProfileSettings.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/UserDefinedMicroProfileSettings.java @@ -140,7 +140,7 @@ public Map toSettingsForMicroProfileLS() { Map validation = new HashMap<>(); tools.put("validation", validation); - validation.put("enabled", isValidationEnabled()); + validation.put("enabled", inspectionsInfo.enabled()); validation.put("syntax", getSeverityNode(inspectionsInfo.syntaxSeverity())); validation.put("duplicate", getSeverityNode(inspectionsInfo.duplicateSeverity())); validation.put("value", getSeverityNode(inspectionsInfo.valueSeverity())); diff --git a/src/main/java/com/redhat/devtools/intellij/quarkus/lsp/QuarkusLanguageClient.java b/src/main/java/com/redhat/devtools/intellij/quarkus/lsp/QuarkusLanguageClient.java index ca4020279..251d6262d 100644 --- a/src/main/java/com/redhat/devtools/intellij/quarkus/lsp/QuarkusLanguageClient.java +++ b/src/main/java/com/redhat/devtools/intellij/quarkus/lsp/QuarkusLanguageClient.java @@ -89,7 +89,7 @@ private void sendPropertiesChangeEvent(List scope, @Override public void profileChanged(@NotNull InspectionProfile profile) { - // Track MicroProfile inspections settings (declared in Editor/Inspection/MicroProfue UI settings) changed, + // Track MicroProfile inspections settings (declared in Editor/Inspection/MicroProfile UI settings) changed, // convert them to matching LSP4MP configuration and push them via 'workspace/didChangeConfiguration'. MicroProfileInspectionsInfo newInspectionState = MicroProfileInspectionsInfo.getMicroProfileInspectionInfo(getProject()); if (!Objects.equals(newInspectionState, inspectionsInfo)) { 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 fcd5c49fb..38ee1c6c6 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 @@ -56,7 +56,7 @@ public Object getInitializationOptions(URI rootUri) { Map extendedClientCapabilities = new HashMap<>(); Map commands = new HashMap<>(); Map commandsKind = new HashMap<>(); - commandsKind.put("valueSet", Arrays.asList("qute.command.java.definition", /* TODO support "qute.command.configuration.update" , */ "qute.command.open.uri")); + commandsKind.put("valueSet", Arrays.asList("qute.command.java.definition", "qute.command.configuration.update" , "qute.command.open.uri")); commands.put("commandsKind", commandsKind); extendedClientCapabilities.put("commands", commands); extendedClientCapabilities.put("shouldLanguageServerExitOnShutdown", Boolean.TRUE); diff --git a/src/main/java/com/redhat/devtools/intellij/qute/psi/core/command/QuteUpdateConfigurationAction.java b/src/main/java/com/redhat/devtools/intellij/qute/psi/core/command/QuteUpdateConfigurationAction.java new file mode 100644 index 000000000..6f47fce5d --- /dev/null +++ b/src/main/java/com/redhat/devtools/intellij/qute/psi/core/command/QuteUpdateConfigurationAction.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2023 Red Hat Inc. and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + * + * Contributors: + * Red Hat Inc. - initial API and implementation + *******************************************************************************/ +package com.redhat.devtools.intellij.qute.psi.core.command; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.intellij.codeInspection.InspectionProfile; +import com.intellij.codeInspection.ex.InspectionProfileImpl; +import com.intellij.codeInspection.ex.InspectionToolWrapper; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Key; +import com.intellij.profile.codeInspection.InspectionProfileManager; +import com.intellij.psi.PsiElement; +import com.intellij.psi.impl.FakePsiElement; +import com.redhat.devtools.intellij.lsp4ij.commands.CommandExecutor; +import com.redhat.devtools.intellij.lsp4ij.inspections.AbstractDelegateInspectionWithExclusions; +import com.redhat.devtools.intellij.qute.psi.core.inspections.QuteGlobalInspection; +import org.eclipse.lsp4j.Command; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class QuteUpdateConfigurationAction extends AnAction { + private final Map updaters = new HashMap<>(); + + public QuteUpdateConfigurationAction() { + //TODO potentially load those from an extension point? + updaters.put("qute.validation.enabled", new InspectionConfigurationEnabler(QuteGlobalInspection.ID)); + updaters.put("qute.validation.excluded", new InspectionConfigurationUpdater(QuteGlobalInspection.ID)); + } + + @Override + public void actionPerformed(@NotNull AnActionEvent e) { + JsonObject configUpdate = getConfigUpdate(e); + if (configUpdate != null && e.getProject() != null) { + String section = configUpdate.get("section").getAsString(); + ConfigurationUpdater updater = updaters.get(section); + if (updater == null) { + throw new UnsupportedOperationException("Updating "+section+" is not supported yet!"); + } + JsonElement value = configUpdate.get("value"); + updater.updateConfiguration(e.getProject(), value); + } + } + + private @Nullable JsonObject getConfigUpdate(@NotNull AnActionEvent e) { + @Nullable Command command = e.getData(CommandExecutor.LSP_COMMAND); + if (command == null) { + return null; + } + List arguments = command.getArguments(); + if (arguments != null && !arguments.isEmpty()) { + Object arg = arguments.get(0); + if (arg instanceof JsonObject) { + return (JsonObject) arg; + } + } + return null; + } + + interface ConfigurationUpdater { + void updateConfiguration(Project project, JsonElement value); + } + + private static class InspectionConfigurationUpdater implements ConfigurationUpdater { + + private final String inspectionId; + + InspectionConfigurationUpdater(String inspectionId) { + this.inspectionId = inspectionId; + } + + @Override + public void updateConfiguration(Project project, JsonElement value) { + if (value != null) { + updateConfiguration(project, value.getAsString()); + } + } + + private void updateConfiguration(Project project, @NotNull String value) { + InspectionProfile profile = InspectionProfileManager.getInstance(project).getCurrentProfile(); + InspectionToolWrapper toolWrapper = profile.getInspectionTool(inspectionId, project); + if (toolWrapper != null && toolWrapper.getTool() instanceof AbstractDelegateInspectionWithExclusions) { + Key key = new Key<>(inspectionId); + profile.modifyToolSettings(key, getPsiElement(project), (tool) -> { + tool.excludeList.add(value); + }); + } + } + + private PsiElement getPsiElement(Project project) { + return new FakePsiElement() { + @Override + public PsiElement getParent() { + return null; + } + + @Override + public @NotNull Project getProject() { + return project; + } + }; + } + } + + private static class InspectionConfigurationEnabler implements ConfigurationUpdater { + + private final String inspectionId; + + InspectionConfigurationEnabler(String inspectionId) { + this.inspectionId = inspectionId; + } + + @Override + public void updateConfiguration(Project project, JsonElement value) { + if (value != null) { + toggleInspection(project, Boolean.valueOf(value.getAsString()));//safer than value.getAsBoolean() + } + } + + private void toggleInspection(Project project, @NotNull boolean enabled) { + InspectionProfile profile = InspectionProfileManager.getInstance(project).getCurrentProfile(); + if (profile instanceof InspectionProfileImpl) { + InspectionProfileImpl profileImpl = (InspectionProfileImpl) profile; + profileImpl.setToolEnabled(inspectionId, enabled); + } + } + } +} diff --git a/src/main/java/com/redhat/devtools/intellij/qute/psi/core/inspections/QuteGlobalInspection.java b/src/main/java/com/redhat/devtools/intellij/qute/psi/core/inspections/QuteGlobalInspection.java new file mode 100644 index 000000000..9fc0db9c0 --- /dev/null +++ b/src/main/java/com/redhat/devtools/intellij/qute/psi/core/inspections/QuteGlobalInspection.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2023 Red Hat Inc. and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + * + * Contributors: + * Red Hat Inc. - initial API and implementation + *******************************************************************************/ +package com.redhat.devtools.intellij.qute.psi.core.inspections; + +import com.redhat.devtools.intellij.lsp4ij.inspections.AbstractDelegateInspectionWithExclusions; +import com.redhat.devtools.intellij.qute.QuteBundle; + +/** + * Dummy inspection for general validation in Qute template files + */ +public class QuteGlobalInspection extends AbstractDelegateInspectionWithExclusions { + public static final String ID = getShortName(QuteGlobalInspection.class.getSimpleName()); + + QuteGlobalInspection() { + super(QuteBundle.message("qute.validation.excluded.options.label")); + } +} diff --git a/src/main/java/com/redhat/devtools/intellij/qute/psi/core/inspections/QuteUndefinedNamespaceInspection.java b/src/main/java/com/redhat/devtools/intellij/qute/psi/core/inspections/QuteUndefinedNamespaceInspection.java index 29a3ea16e..1e2a28a9e 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/psi/core/inspections/QuteUndefinedNamespaceInspection.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/psi/core/inspections/QuteUndefinedNamespaceInspection.java @@ -13,6 +13,8 @@ *******************************************************************************/ package com.redhat.devtools.intellij.qute.psi.core.inspections; +import com.redhat.devtools.intellij.lsp4ij.inspections.AbstractDelegateInspection; + /** * Dummy inspection for undefined namespaces in Qute templates */ diff --git a/src/main/java/com/redhat/devtools/intellij/qute/psi/core/inspections/QuteUndefinedObjectInspection.java b/src/main/java/com/redhat/devtools/intellij/qute/psi/core/inspections/QuteUndefinedObjectInspection.java index 1fce8e42f..575b9d65d 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/psi/core/inspections/QuteUndefinedObjectInspection.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/psi/core/inspections/QuteUndefinedObjectInspection.java @@ -13,6 +13,8 @@ *******************************************************************************/ package com.redhat.devtools.intellij.qute.psi.core.inspections; +import com.redhat.devtools.intellij.lsp4ij.inspections.AbstractDelegateInspection; + /** * Dummy inspection for undefined objects in Qute templates */ diff --git a/src/main/java/com/redhat/devtools/intellij/qute/settings/QuteConfigurable.java b/src/main/java/com/redhat/devtools/intellij/qute/settings/QuteConfigurable.java index 307d57cdf..58d15552c 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/settings/QuteConfigurable.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/settings/QuteConfigurable.java @@ -65,7 +65,6 @@ public void setDisplayName(String name) { public void reset() { if (myView == null) return; UserDefinedQuteSettings settings = UserDefinedQuteSettings.getInstance(project); - myView.setValidationEnabled(settings.isValidationEnabled()); myView.setNativeModeSupportEnabled(settings.isNativeModeSupportEnabled()); } @@ -73,15 +72,13 @@ public void reset() { public boolean isModified() { if (myView == null) return false; UserDefinedQuteSettings settings = UserDefinedQuteSettings.getInstance(project); - return myView.isValidationEnabled() != settings.isValidationEnabled() || - myView.isNativeModeSupportEnabled() != settings.isNativeModeSupportEnabled(); + return myView.isNativeModeSupportEnabled() != settings.isNativeModeSupportEnabled(); } @Override public void apply() throws ConfigurationException { if (myView == null) return; UserDefinedQuteSettings settings = UserDefinedQuteSettings.getInstance(project); - settings.setValidationEnabled(myView.isValidationEnabled()); settings.setNativeModeSupportEnabled(myView.isNativeModeSupportEnabled()); settings.fireStateChanged(); } diff --git a/src/main/java/com/redhat/devtools/intellij/qute/settings/QuteInspectionsInfo.java b/src/main/java/com/redhat/devtools/intellij/qute/settings/QuteInspectionsInfo.java index e066e5972..b17546799 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/settings/QuteInspectionsInfo.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/settings/QuteInspectionsInfo.java @@ -13,18 +13,20 @@ *******************************************************************************/ package com.redhat.devtools.intellij.qute.settings; -import com.intellij.codeHighlighting.HighlightDisplayLevel; -import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.codeInspection.InspectionProfile; -import com.intellij.lang.annotation.HighlightSeverity; +import com.intellij.codeInspection.ex.InspectionToolWrapper; import com.intellij.openapi.project.Project; import com.intellij.profile.codeInspection.InspectionProfileManager; import com.redhat.devtools.intellij.lsp4ij.operations.diagnostics.SeverityMapping; +import com.redhat.devtools.intellij.lsp4ij.inspections.AbstractDelegateInspectionWithExclusions; +import com.redhat.devtools.intellij.qute.psi.core.inspections.QuteGlobalInspection; import com.redhat.devtools.intellij.qute.psi.core.inspections.QuteUndefinedNamespaceInspection; import com.redhat.devtools.intellij.qute.psi.core.inspections.QuteUndefinedObjectInspection; import org.eclipse.lsp4j.DiagnosticSeverity; -import org.gradle.configurationcache.problems.ProblemSeverity; -import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; /** * Contains Qute inspection settings relevant to Qute LS configuration @@ -32,17 +34,27 @@ //TODO switch to a record, when Java 17 is required public class QuteInspectionsInfo { + private boolean enabled = true; private DiagnosticSeverity undefinedObjectSeverity = DiagnosticSeverity.Warning; private DiagnosticSeverity undefinedNamespaceSeverity = DiagnosticSeverity.Warning; + public List getExcludedFiles() { + return excludedFiles; + } + + private List excludedFiles; + + private QuteInspectionsInfo() { } public static QuteInspectionsInfo getQuteInspectionsInfo(Project project) { QuteInspectionsInfo wrapper = new QuteInspectionsInfo(); InspectionProfile profile = InspectionProfileManager.getInstance(project).getCurrentProfile(); + wrapper.enabled = SeverityMapping.getSeverity(QuteGlobalInspection.ID, profile) != null; wrapper.undefinedObjectSeverity = SeverityMapping.getSeverity(QuteUndefinedObjectInspection.ID, profile); wrapper.undefinedNamespaceSeverity = SeverityMapping.getSeverity(QuteUndefinedNamespaceInspection.ID, profile); + wrapper.excludedFiles = getExclusions(profile, QuteGlobalInspection.ID, project); return wrapper; } @@ -54,4 +66,30 @@ public DiagnosticSeverity undefinedNamespaceSeverity() { return undefinedNamespaceSeverity; } + public boolean enabled() { + return enabled; + } + + private static List getExclusions(InspectionProfile profile, String inspectionId, Project project) { + List exclusions = new ArrayList<>(); + InspectionToolWrapper toolWrapper = profile.getInspectionTool(inspectionId, project); + if (toolWrapper != null && toolWrapper.getTool() instanceof AbstractDelegateInspectionWithExclusions) { + AbstractDelegateInspectionWithExclusions inspection = (AbstractDelegateInspectionWithExclusions) toolWrapper.getTool(); + exclusions.addAll(inspection.excludeList); + } + return exclusions; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + QuteInspectionsInfo that = (QuteInspectionsInfo) o; + return enabled == that.enabled && undefinedObjectSeverity == that.undefinedObjectSeverity && undefinedNamespaceSeverity == that.undefinedNamespaceSeverity && Objects.equals(excludedFiles, that.excludedFiles); + } + + @Override + public int hashCode() { + return Objects.hash(enabled, undefinedObjectSeverity, undefinedNamespaceSeverity, excludedFiles); + } } diff --git a/src/main/java/com/redhat/devtools/intellij/qute/settings/QuteView.java b/src/main/java/com/redhat/devtools/intellij/qute/settings/QuteView.java index cd8f280ae..349cda9f0 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/settings/QuteView.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/settings/QuteView.java @@ -18,6 +18,7 @@ import com.intellij.util.ui.FormBuilder; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UI; +import com.redhat.devtools.intellij.lsp4ij.ui.components.InspectionHyperlink; import com.redhat.devtools.intellij.qute.QuteBundle; import javax.swing.*; @@ -29,7 +30,6 @@ public class QuteView implements Disposable { private final JPanel myMainPanel; - private JBCheckBox validationEnabledCheckBox = new JBCheckBox(QuteBundle.message("qute.setting.validation.enabled")); private JBCheckBox nativeModeSupportEnabledCheckBox = new JBCheckBox(QuteBundle.message("qute.setting.validation.native.enabled")); public QuteView() { @@ -39,7 +39,7 @@ public QuteView() { private JPanel createSettings() { return FormBuilder.createFormBuilder() - .addComponent(validationEnabledCheckBox) + .addComponent(new InspectionHyperlink("Configure Qute inspections", "Qute")) .addComponent(nativeModeSupportEnabledCheckBox) .addComponentFillVertically(new JPanel(), 0) .getPanel(); @@ -54,14 +54,6 @@ public void dispose() { } - public boolean isValidationEnabled() { - return validationEnabledCheckBox.isSelected(); - } - - public void setValidationEnabled(boolean enabled) { - validationEnabledCheckBox.setSelected(enabled); - } - public boolean isNativeModeSupportEnabled() { return nativeModeSupportEnabledCheckBox.isSelected(); } diff --git a/src/main/java/com/redhat/devtools/intellij/qute/settings/UserDefinedQuteSettings.java b/src/main/java/com/redhat/devtools/intellij/qute/settings/UserDefinedQuteSettings.java index 25328b59a..22e987516 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/settings/UserDefinedQuteSettings.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/settings/UserDefinedQuteSettings.java @@ -152,7 +152,10 @@ public Map toSettingsForQuteLS() { // Validation Map validation = new HashMap<>(); qute.put("validation", validation); - validation.put("enabled", isValidationEnabled()); + + validation.put("enabled", inspectionsInfo.enabled()); + validation.put("excluded", inspectionsInfo.getExcludedFiles()); + validation.put("undefinedObject", getSeverityNode(inspectionsInfo.undefinedObjectSeverity())); validation.put("undefinedNamespace", getSeverityNode(inspectionsInfo.undefinedNamespaceSeverity())); return settings; diff --git a/src/main/resources/META-INF/lsp4ij-quarkus.xml b/src/main/resources/META-INF/lsp4ij-quarkus.xml index 20de85dbf..7394280e0 100644 --- a/src/main/resources/META-INF/lsp4ij-quarkus.xml +++ b/src/main/resources/META-INF/lsp4ij-quarkus.xml @@ -1,5 +1,4 @@ - + + + + + + diff --git a/src/main/resources/messages/MicroProfileBundle.properties b/src/main/resources/messages/MicroProfileBundle.properties index 61e6bd28b..6aca12094 100644 --- a/src/main/resources/messages/MicroProfileBundle.properties +++ b/src/main/resources/messages/MicroProfileBundle.properties @@ -25,6 +25,7 @@ microprofile.validation.enabled=Enable validation microprofile.properties=Properties microprofile.properties.title=MicroProfile configuration in microprofile-config.properties microprofile.properties.inlayHint.enabled=Show evaluated property expression as inlay hint? +microprofile.properties.validation=Validation microprofile.properties.validation.syntax=Syntax checking microprofile.properties.validation.unknown=Unknown properties microprofile.properties.validation.duplicate=Duplicate properties diff --git a/src/main/resources/messages/QuteBundle.properties b/src/main/resources/messages/QuteBundle.properties index e46ee236b..1d43c2b28 100644 --- a/src/main/resources/messages/QuteBundle.properties +++ b/src/main/resources/messages/QuteBundle.properties @@ -25,8 +25,10 @@ qute.settings.title=Qute qute.inspection.group.name=Qute +qute.templates.inspection=Validation qute.templates.inspection.group.name=Templates qute.templates.validation.undefinedNamespace=Undefined namespaces qute.templates.validation.undefinedObject=Undefined objects qute.setting.validation.enabled=Enable validation qute.setting.validation.native.enabled=Enable native image mode support +qute.validation.excluded.options.label=Files excluded from the Qute validation