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

updateQuteConfigCommand #1151

Closed
Closed
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 @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,39 @@
* 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.*;
import java.util.ArrayList;
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<String> 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());

Expand Down
Original file line number Diff line number Diff line change
@@ -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});
}
});
}
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,7 +43,6 @@ public class MicroprofileUpdateConfigurationAction extends AnAction {
private final Map<String, ConfigurationUpdater> 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));
}
Expand Down Expand Up @@ -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<AbstractDelegateInspectionWithExcludedProperties> key = new Key<>(inspectionId);
if (toolWrapper != null && toolWrapper.getTool() instanceof AbstractDelegateInspectionWithExclusions) {
Key<AbstractDelegateInspectionWithExclusions> key = new Key<>(inspectionId);
profile.modifyToolSettings(key, getPsiElement(project), (tool) -> {
tool.excludeList.add(value);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,12 +43,15 @@ public class MicroProfileInspectionsInfo {
private List<String> excludedUnknownProperties;
private List<String> 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);
Expand All @@ -65,13 +69,17 @@ public static MicroProfileInspectionsInfo getMicroProfileInspectionInfo(Project
private static List<String> getExclusions(InspectionProfile profile, String inspectionId, Project project) {
List<String> 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;
}
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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();
}
Expand All @@ -56,13 +64,4 @@ public JComponent getComponent() {
public void dispose() {

}

public boolean isValidationEnabled() {
return validationEnabledCheckBox.isSelected();
}

public void setValidationEnabled(boolean enable) {
validationEnabledCheckBox.setSelected(enable);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public Map<String, Object> toSettingsForMicroProfileLS() {

Map<String, Object> 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()));
Expand Down
Loading
Loading