Skip to content

Commit

Permalink
feat: expose MicroProfile server settings
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Aug 22, 2023
1 parent 8dfef36 commit dff5144
Show file tree
Hide file tree
Showing 26 changed files with 528 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,21 @@ protected synchronized Runnable getDidChangeConfigurationListener() {
if (didChangeConfigurationListener != null) {
return didChangeConfigurationListener;
}
didChangeConfigurationListener = () -> {
LanguageServer languageServer = getLanguageServer();
if (languageServer == null) {
return;
}
Object settings = createSettings();
if(settings == null) {
return;
}
DidChangeConfigurationParams params = new DidChangeConfigurationParams(settings);
languageServer.getWorkspaceService().didChangeConfiguration(params);
};
didChangeConfigurationListener = this::triggerChangeConfiguration;
return didChangeConfigurationListener;
}

protected void triggerChangeConfiguration() {
LanguageServer languageServer = getLanguageServer();
if (languageServer == null) {
return;
}
Object settings = createSettings();
if(settings == null) {
return;
}
DidChangeConfigurationParams params = new DidChangeConfigurationParams(settings);
languageServer.getWorkspaceService().didChangeConfiguration(params);
}

}
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,21 @@
/*******************************************************************************
* 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;

/**
* Dummy inspection for duplicate properties in Microprofile properties files
*/
public class MicroProfilePropertiesDuplicatesInspection extends AbstractDelegateInspection {
public static final String ID = getShortName(MicroProfilePropertiesDuplicatesInspection.class.getSimpleName());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* 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;

/**
* Dummy inspection for expression values in Microprofile properties files
*/
public class MicroProfilePropertiesExpressionsInspection extends AbstractDelegateInspection {
public static final String ID = getShortName(MicroProfilePropertiesExpressionsInspection.class.getSimpleName());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* 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;

/**
* Dummy inspection for missing required properties in Microprofile properties files
*/
public class MicroProfilePropertiesRequiredInspection extends AbstractDelegateInspection {
public static final String ID = getShortName(MicroProfilePropertiesRequiredInspection.class.getSimpleName());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* 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;

/**
* Dummy inspection for property syntax errors in Microprofile properties files
*/
public class MicroProfilePropertiesSyntaxInspection extends AbstractDelegateInspection {
public static final String ID = getShortName(MicroProfilePropertiesSyntaxInspection.class.getSimpleName());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* 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;

/**
* Dummy inspection for unassigned properties in Microprofile properties files
*/
public class MicroProfilePropertiesUnassignedInspection extends AbstractDelegateInspection {
public static final String ID = getShortName(MicroProfilePropertiesUnassignedInspection.class.getSimpleName());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* 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;

/**
* Dummy inspection for unknown properties in Microprofile properties files
*/
public class MicroProfilePropertiesUnknownInspection extends AbstractDelegateInspection {
public static final String ID = getShortName(MicroProfilePropertiesUnknownInspection.class.getSimpleName());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* 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;

/**
* Dummy inspection for invalid values in Microprofile properties files
*/
public class MicroProfilePropertiesValueInspection extends AbstractDelegateInspection {
public static final String ID = getShortName(MicroProfilePropertiesValueInspection.class.getSimpleName());
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MicroProfileConfigurable extends NamedConfigurable<UserDefinedMicro

private MicroProfileView myView;

public MicroProfileConfigurable(Project project) {
public MicroProfileConfigurable(Project ignoredProject) {
}

@Override
Expand Down Expand Up @@ -58,10 +58,8 @@ public void setDisplayName(String name) {
return MicroProfileBundle.message("microprofile");
}


@Override
public boolean isModified() {
if (myView == null) return false;
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*******************************************************************************
* 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.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.openapi.project.Project;
import com.intellij.profile.codeInspection.InspectionProfileManager;
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.inspections.*;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

/**
* Contains Microprofile inspection settings relevant to LSP4MP configuration
*/
//TODO switch to a record, when Java 17 is required
public class MicroProfileInspectionsInfo {

//See https://github.com/eclipse/lsp4mp/blob/6b483c4d292bfebabd13311d6217291da2d5d169/microprofile.ls/org.eclipse.lsp4mp.ls/src/main/java/org/eclipse/lsp4mp/settings/MicroProfileValidationSettings.java#L36
private boolean enabled = true;
private ProblemSeverity syntaxSeverity = ProblemSeverity.error;
private ProblemSeverity unknownSeverity = ProblemSeverity.warning;
private ProblemSeverity duplicateSeverity = ProblemSeverity.warning;
private ProblemSeverity valueSeverity = ProblemSeverity.error;
private ProblemSeverity requiredSeverity = ProblemSeverity.none;
private ProblemSeverity expressionSeverity = ProblemSeverity.error;
private ProblemSeverity unassignedSeverity = ProblemSeverity.warning;

public boolean enabled() {
return enabled;
}

public ProblemSeverity unknownSeverity() {
return unknownSeverity;
}

public ProblemSeverity valueSeverity() {
return valueSeverity;
}

public ProblemSeverity expressionSeverity() {
return expressionSeverity;
}

public ProblemSeverity unassignedSeverity() {
return unassignedSeverity;
}

public ProblemSeverity duplicateSeverity() {
return duplicateSeverity;
}

public ProblemSeverity syntaxSeverity() {
return syntaxSeverity;
}

public ProblemSeverity requiredSeverity() {
return requiredSeverity;
}

private MicroProfileInspectionsInfo(){}

public static MicroProfileInspectionsInfo getMicroProfileInspectionInfo(Project project) {
MicroProfileInspectionsInfo wrapper = new MicroProfileInspectionsInfo();
InspectionProfile profile = InspectionProfileManager.getInstance(project).getCurrentProfile();

wrapper.enabled = isInspectionEnabled(MicroProfilePropertiesSyntaxInspection.ID,profile)
|| isInspectionEnabled(MicroProfilePropertiesUnknownInspection.ID,profile)
|| isInspectionEnabled(MicroProfilePropertiesDuplicatesInspection.ID,profile)
|| isInspectionEnabled(MicroProfilePropertiesValueInspection.ID,profile)
|| isInspectionEnabled(MicroProfilePropertiesRequiredInspection.ID,profile)
|| isInspectionEnabled(MicroProfilePropertiesExpressionsInspection.ID,profile)
|| isInspectionEnabled(MicroProfilePropertiesUnassignedInspection.ID,profile);

wrapper.syntaxSeverity = ProblemSeverity.getSeverity(getErrorLevel(MicroProfilePropertiesSyntaxInspection.ID, profile));
wrapper.unknownSeverity = ProblemSeverity.getSeverity(getErrorLevel(MicroProfilePropertiesUnknownInspection.ID, profile));
wrapper.duplicateSeverity = ProblemSeverity.getSeverity(getErrorLevel(MicroProfilePropertiesDuplicatesInspection.ID, profile));
wrapper.valueSeverity = ProblemSeverity.getSeverity(getErrorLevel(MicroProfilePropertiesValueInspection.ID, profile));
wrapper.requiredSeverity = ProblemSeverity.getSeverity(getErrorLevel(MicroProfilePropertiesRequiredInspection.ID, profile));
wrapper.expressionSeverity = ProblemSeverity.getSeverity(getErrorLevel(MicroProfilePropertiesExpressionsInspection.ID, profile));
wrapper.unassignedSeverity = ProblemSeverity.getSeverity(getErrorLevel(MicroProfilePropertiesUnassignedInspection.ID, profile));
return wrapper;
}

private static @NotNull HighlightSeverity getErrorLevel(String inspectionId, InspectionProfile profile) {
HighlightDisplayLevel level = profile.getErrorLevel(HighlightDisplayKey.find(inspectionId), null);
return level.getSeverity();
}

private static boolean isInspectionEnabled(@NotNull String inspectionId, @NotNull InspectionProfile profile) {
return profile.isToolEnabled(HighlightDisplayKey.find(inspectionId));
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MicroProfileInspectionsInfo that = (MicroProfileInspectionsInfo) o;
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;
}

@Override
public int hashCode() {
return Objects.hash(enabled, syntaxSeverity, unknownSeverity, duplicateSeverity, valueSeverity, requiredSeverity,
expressionSeverity, unassignedSeverity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
package com.redhat.devtools.intellij.lsp4mp4ij.settings;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.ui.ComboBox;
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;
Expand All @@ -31,16 +33,15 @@ public class MicroProfileView implements Disposable {
private final JPanel myMainPanel;

public MicroProfileView() {
JComponent descriptionPanel = createDescription(MicroProfileBundle.message("microprofile.description"));
JPanel settingsPanel = createSettings(descriptionPanel);
JPanel settingsPanel = createSettings();
TitledBorder title = IdeBorderFactory.createTitledBorder(MicroProfileBundle.message("microprofile.title"));
settingsPanel.setBorder(title);
this.myMainPanel = JBUI.Panels.simplePanel(10,10)
.addToLeft(JBUI.Panels.simplePanel())
.addToCenter(settingsPanel);
}

private JPanel createSettings(JComponent description) {
private JPanel createSettings() {
return FormBuilder.createFormBuilder()
.addComponentFillVertically(new JPanel(), 0)
.getPanel();
Expand Down
Loading

0 comments on commit dff5144

Please sign in to comment.