Skip to content

Commit

Permalink
feat: support for excluding properties from validation
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Aug 31, 2023
1 parent 3fbeb41 commit c05bb45
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*******************************************************************************
* 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.lsp4mp4ij.psi.core.inspections;

import com.intellij.codeInspection.LocalInspectionTool;

/**
* No-op {@link LocalInspectionTool} used as a basis for mapping inspection severities to matching LSP severities.
*/
public abstract class AbstractDelegateInspection extends LocalInspectionTool {
}
Original file line number Diff line number Diff line change
@@ -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.lsp4mp4ij.psi.core.inspections;

import com.intellij.codeInspection.ui.ListEditForm;
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

/**
* Dummy inspection for unknown properties in Microprofile properties files
*/
public class MicroProfilePropertiesUnknownInspection extends AbstractDelegateInspectionWithExcludedProperties {
public static final String ID = getShortName(MicroProfilePropertiesUnknownInspection.class.getSimpleName());
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,29 @@
*******************************************************************************/
package com.redhat.devtools.intellij.lsp4mp4ij.psi.core.inspections;

import com.intellij.codeInspection.ui.ListEditForm;
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

/**
* Dummy inspection for unknown properties in Microprofile properties files
*/
public class MicroProfilePropertiesUnknownInspection extends AbstractDelegateInspection {
public static final String ID = getShortName(MicroProfilePropertiesUnknownInspection.class.getSimpleName());

public final List<String> excludeList = new ArrayList<>();

public JComponent createOptionsPanel() {
var panel = new MultipleCheckboxOptionsPanel(this);

var injectionListTable = new ListEditForm("", "Exclude properties. Patterns can be used ('*' = any string, '?' = any character).", excludeList);

panel.addGrowing(injectionListTable.getContentPanel());

return panel;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@
import com.intellij.codeHighlighting.HighlightDisplayLevel;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.lang.annotation.HighlightSeverity;
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.lsp4mp4ij.psi.core.inspections.*;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
Expand All @@ -39,6 +44,7 @@ public class MicroProfileInspectionsInfo {
private DiagnosticSeverity valueSeverity = DiagnosticSeverity.Error;
private DiagnosticSeverity requiredSeverity = null;
private DiagnosticSeverity expressionSeverity = DiagnosticSeverity.Error;
private List<String> excludedUnknownProperties;

private MicroProfileInspectionsInfo() {
}
Expand All @@ -52,6 +58,15 @@ public static MicroProfileInspectionsInfo getMicroProfileInspectionInfo(Project
wrapper.valueSeverity = SeverityMapping.getSeverity(MicroProfilePropertiesValueInspection.ID, profile);
wrapper.requiredSeverity = SeverityMapping.getSeverity(MicroProfilePropertiesRequiredInspection.ID, profile);
wrapper.expressionSeverity = SeverityMapping.getSeverity(MicroProfilePropertiesExpressionsInspection.ID, profile);

InspectionToolWrapper<?, ?> toolWrapper = profile.getInspectionTool(MicroProfilePropertiesUnknownInspection.ID, project);
if (toolWrapper != null) {
MicroProfilePropertiesUnknownInspection unknownPropertiesInspection = (MicroProfilePropertiesUnknownInspection) toolWrapper.getTool();
List<String> excludeList = unknownPropertiesInspection.excludeList;
if (!excludeList.isEmpty()) {
wrapper.excludedUnknownProperties = new ArrayList<>(excludeList);
}
}
return wrapper;
}

Expand Down Expand Up @@ -79,19 +94,20 @@ public DiagnosticSeverity requiredSeverity() {
return requiredSeverity;
}

public List<String> getExcludedUnknownProperties() {
return excludedUnknownProperties;
}

@Override
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;
return syntaxSeverity == that.syntaxSeverity && unknownSeverity == that.unknownSeverity && duplicateSeverity == that.duplicateSeverity && valueSeverity == that.valueSeverity && requiredSeverity == that.requiredSeverity && expressionSeverity == that.expressionSeverity && Objects.equals(excludedUnknownProperties, that.excludedUnknownProperties);
}

@Override
public int hashCode() {
return Objects.hash(syntaxSeverity, unknownSeverity, duplicateSeverity, valueSeverity, requiredSeverity,
expressionSeverity);
return Objects.hash(syntaxSeverity, unknownSeverity, duplicateSeverity, valueSeverity, requiredSeverity, expressionSeverity, excludedUnknownProperties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,19 @@ public Map<String, Object> toSettingsForMicroProfileLS() {
tools.put("validation", validation);
validation.put("enabled", isValidationEnabled());
validation.put("syntax", getSeverityNode(inspectionsInfo.syntaxSeverity()));
validation.put("unknown", getSeverityNode(inspectionsInfo.unknownSeverity()));
validation.put("duplicate", getSeverityNode(inspectionsInfo.duplicateSeverity()));
validation.put("value", getSeverityNode(inspectionsInfo.valueSeverity()));
validation.put("required", getSeverityNode(inspectionsInfo.requiredSeverity()));
validation.put("expression", getSeverityNode(inspectionsInfo.expressionSeverity()));

//Unknown properties
Map<String, Object> unknown = new HashMap<>();
validation.put("unknown", unknown);
unknown.put("severity", SeverityMapping.toString(inspectionsInfo.unknownSeverity()));
List<String> excludedUnknownProperties = inspectionsInfo.getExcludedUnknownProperties();
if (excludedUnknownProperties != null && !excludedUnknownProperties.isEmpty()) {
unknown.put("excluded", excludedUnknownProperties);
}
return settings;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<html>
<body>
Write your description here.
Start the description with a verb in 3rd person singular, like reports, detects, highlights.
In the first sentence, briefly explain what exactly the inspection helps you detect.
Make sure the sentence is not very long and complicated.
<p>
The first sentence must be in a dedicated paragraph separated from the rest of the text. This will make the description easier to read.
Make sure the description doesn’t just repeat the inspection title.
</p>
<p>
See https://jetbrains.design/intellij/text/inspections/#descriptions for more information.
</p>
<p>
Embed code snippets:
</p>
<pre><code>
// automatically highlighted according to inspection registration 'language' attribute
</code></pre>
<!-- tooltip end -->
<p>Text after this comment will only be shown in the settings of the inspection.</p>

<p>To open related settings directly from the description, add a link with `settings://$` optionally followed by `?$` to pre-select a UI element.</p>
</body>
</html>

0 comments on commit c05bb45

Please sign in to comment.