From d379c708efe039614a4a0fa8e75a0d8565acea5f Mon Sep 17 00:00:00 2001 From: Fred Bricon Date: Thu, 17 Aug 2023 15:38:41 +0200 Subject: [PATCH] feat: expose MicroProfile server settings Signed-off-by: Fred Bricon --- .../lsp4ij/client/LanguageClientImpl.java | 26 ++-- .../LSPInspectionToolProvider.java | 22 --- .../diagnostics/LSPLocalInspectionTool.java | 96 ------------- .../AbstractDelegateInspection.java | 22 +++ ...ProfilePropertiesDuplicatesInspection.java | 21 +++ ...rofilePropertiesExpressionsInspection.java | 21 +++ ...roProfilePropertiesRequiredInspection.java | 21 +++ ...icroProfilePropertiesSyntaxInspection.java | 21 +++ ...croProfilePropertiesUnknownInspection.java | 21 +++ ...MicroProfilePropertiesValueInspection.java | 21 +++ .../settings/MicroProfileConfigurable.java | 4 +- .../settings/MicroProfileInspectionsInfo.java | 131 ++++++++++++++++++ .../lsp4mp4ij/settings/MicroProfileView.java | 5 +- .../lsp4mp4ij/settings/ProblemSeverity.java | 46 ++++++ .../UserDefinedMicroProfileSettings.java | 25 +++- .../MicroProfilePropertiesView.java | 2 +- .../quarkus/lsp/QuarkusLanguageClient.java | 39 +++++- .../intellij/quarkus/lsp/QuarkusServer.java | 5 +- .../resources/META-INF/lsp4ij-quarkus.xml | 55 ++++++++ src/main/resources/META-INF/lsp4ij.xml | 1 - .../MicroProfilePropertiesDuplicates.html | 21 +++ .../MicroProfilePropertiesExpressions.html | 21 +++ .../MicroProfilePropertiesRequired.html | 17 +++ .../MicroProfilePropertiesSyntax.html | 21 +++ .../MicroProfilePropertiesUnknown.html | 17 +++ .../MicroProfilePropertiesValue.html | 21 +++ .../messages/MicroProfileBundle.properties | 12 +- ...enApplicationPropertiesCompletionTest.java | 4 +- 28 files changed, 586 insertions(+), 153 deletions(-) delete mode 100644 src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPInspectionToolProvider.java delete mode 100644 src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPLocalInspectionTool.java create mode 100644 src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/AbstractDelegateInspection.java create mode 100644 src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesDuplicatesInspection.java create mode 100644 src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesExpressionsInspection.java create mode 100644 src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesRequiredInspection.java create mode 100644 src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesSyntaxInspection.java create mode 100644 src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesUnknownInspection.java create mode 100644 src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesValueInspection.java create mode 100644 src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/MicroProfileInspectionsInfo.java create mode 100644 src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/ProblemSeverity.java create mode 100644 src/main/resources/inspectionDescriptions/MicroProfilePropertiesDuplicates.html create mode 100644 src/main/resources/inspectionDescriptions/MicroProfilePropertiesExpressions.html create mode 100644 src/main/resources/inspectionDescriptions/MicroProfilePropertiesRequired.html create mode 100644 src/main/resources/inspectionDescriptions/MicroProfilePropertiesSyntax.html create mode 100644 src/main/resources/inspectionDescriptions/MicroProfilePropertiesUnknown.html create mode 100644 src/main/resources/inspectionDescriptions/MicroProfilePropertiesValue.html diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/client/LanguageClientImpl.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/client/LanguageClientImpl.java index 7318513da..64b5c9274 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/client/LanguageClientImpl.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/client/LanguageClientImpl.java @@ -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); + } + } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPInspectionToolProvider.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPInspectionToolProvider.java deleted file mode 100644 index a304746e9..000000000 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPInspectionToolProvider.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020 Red Hat, Inc. - * Distributed under license by Red Hat, Inc. All rights reserved. - * This program is made available under the terms of the - * Eclipse Public License v2.0 which accompanies this distribution, - * and is available at https://www.eclipse.org/legal/epl-v20.html - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - ******************************************************************************/ -package com.redhat.devtools.intellij.lsp4ij.operations.diagnostics; - -import com.intellij.codeInspection.InspectionToolProvider; -import org.jetbrains.annotations.NotNull; - -public class LSPInspectionToolProvider implements InspectionToolProvider { - @NotNull - @Override - public Class[] getInspectionClasses() { - return new Class[] { LSPLocalInspectionTool.class}; - } -} diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPLocalInspectionTool.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPLocalInspectionTool.java deleted file mode 100644 index 2ca7bee31..000000000 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/diagnostics/LSPLocalInspectionTool.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020 Red Hat, Inc. - * Distributed under license by Red Hat, Inc. All rights reserved. - * This program is made available under the terms of the - * Eclipse Public License v2.0 which accompanies this distribution, - * and is available at https://www.eclipse.org/legal/epl-v20.html - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - ******************************************************************************/ -package com.redhat.devtools.intellij.lsp4ij.operations.diagnostics; - -import com.intellij.codeInspection.InspectionManager; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.ProblemDescriptor; -import com.intellij.codeInspection.ProblemHighlightType; -import com.intellij.codeInspection.ex.ExternalAnnotatorBatchInspection; -import com.intellij.psi.PsiFile; -import org.eclipse.lsp4j.DiagnosticSeverity; -import org.jetbrains.annotations.Nls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class LSPLocalInspectionTool extends LocalInspectionTool implements ExternalAnnotatorBatchInspection { - private static final Logger LOGGER = LoggerFactory.getLogger(LSPLocalInspectionTool.class); - - @Nls - @NotNull - @Override - public String getDisplayName() { - return "LSP"; - } - - @Nls - @NotNull - @Override - public String getGroupDisplayName() { - return "LSP"; - } - - @Override - public boolean isEnabledByDefault() { - return true; - } - - - @Nullable - @Override - public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { - /*VirtualFile virtualFile = file.getVirtualFile(); - if (virtualFile != null) { - Editor editor = LSPIJUtils.editorForFile(virtualFile); - if (editor != null) { - List problemDescriptors = new ArrayList<>(); - try { - for(LanguageServerWrapper wrapper : LanguageServiceAccessor.getInstance(file.getProject()).getLSWrappers(virtualFile, capabilities -> true)) { - RangeHighlighter[] highlighters = LSPDiagnosticsToMarkers.getMarkers(editor, wrapper.serverDefinition.id); - if (highlighters != null) { - for(RangeHighlighter highlighter : highlighters) { - PsiElement element; - if (highlighter.getEndOffset() - highlighter.getStartOffset() > 0) { - element = new LSPPSiElement(editor.getProject(), file, highlighter.getStartOffset(), highlighter.getEndOffset(), editor.getDocument().getText(new TextRange(highlighter.getStartOffset(), highlighter.getEndOffset()))); - } else { - element = PsiUtilCore.getElementAtOffset(file, highlighter.getStartOffset()); - } - ProblemHighlightType highlightType = getHighlighType(((Diagnostic)highlighter.getErrorStripeTooltip()).getSeverity()); - problemDescriptors.add(manager.createProblemDescriptor(element, ((Diagnostic)highlighter.getErrorStripeTooltip()).getMessage(), true, highlightType, isOnTheFly)); - } - } - } - } catch (IOException e) { - LOGGER.warn(e.getLocalizedMessage(), e); - } - return problemDescriptors.toArray(new ProblemDescriptor[problemDescriptors.size()]); - } - - }*/ - return super.checkFile(file, manager, isOnTheFly); - } - - private ProblemHighlightType getHighlighType(DiagnosticSeverity severity) { - switch (severity) { - case Error: - return ProblemHighlightType.ERROR; - case Hint: - case Information: - return ProblemHighlightType.INFORMATION; - case Warning: - return ProblemHighlightType.WARNING; - } - return ProblemHighlightType.INFORMATION; - } - -} 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/AbstractDelegateInspection.java new file mode 100644 index 000000000..9c5f28726 --- /dev/null +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/AbstractDelegateInspection.java @@ -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 { +} 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 new file mode 100644 index 000000000..3f3fc890a --- /dev/null +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesDuplicatesInspection.java @@ -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()); +} 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 new file mode 100644 index 000000000..7b2949fda --- /dev/null +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesExpressionsInspection.java @@ -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()); +} 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 new file mode 100644 index 000000000..33c4aa717 --- /dev/null +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesRequiredInspection.java @@ -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()); +} 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 new file mode 100644 index 000000000..e13c0bf3b --- /dev/null +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesSyntaxInspection.java @@ -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()); +} 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 new file mode 100644 index 000000000..1672ea0e8 --- /dev/null +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesUnknownInspection.java @@ -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()); +} 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 new file mode 100644 index 000000000..8d805c567 --- /dev/null +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/inspections/MicroProfilePropertiesValueInspection.java @@ -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()); +} 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 cb7502ac7..490297414 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 @@ -28,7 +28,7 @@ public class MicroProfileConfigurable extends NamedConfigurable + *
  • Any severity below HighlightSeverity.WEAK_WARNING is mapped to ProblemSeverity.none
  • + *
  • Any severity below HighlightSeverity.ERROR is mapped to ProblemSeverity.warning
  • + *
  • Any other severity is mapped to ProblemSeverity.error
  • + * + * + * @param highlightSeverity the severity to map to a {@link ProblemSeverity} + * @return the matching {@link ProblemSeverity} + */ + public static @NotNull ProblemSeverity getSeverity(@NotNull HighlightSeverity highlightSeverity) { + if (HighlightSeverity.WEAK_WARNING.compareTo(highlightSeverity) > 0) { + return none; + } + if (HighlightSeverity.ERROR.compareTo(highlightSeverity) > 0) { + return warning; + } + return error; + } +} 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 1ae376a1d..750c88029 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 @@ -14,16 +14,15 @@ package com.redhat.devtools.intellij.lsp4mp4ij.settings; import com.intellij.openapi.components.PersistentStateComponent; -import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; import com.intellij.openapi.project.Project; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.xmlb.annotations.Tag; -import com.jetbrains.jsonSchema.JsonSchemaCatalogProjectConfiguration; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -32,6 +31,7 @@ * User defined MicroProfile settings for: * *
      + *
    • validation
    • *
    • properties files managed with the MicroProfile language server
    • *
    • Java files managed with the MicroProfile language server
    • *
    @@ -42,7 +42,7 @@ ) public class UserDefinedMicroProfileSettings implements PersistentStateComponent { - public volatile MyState myState = new MyState(); + private volatile MyState myState = new MyState(); private final List myChangeHandlers = ContainerUtil.createConcurrentList(); @@ -103,7 +103,8 @@ public void loadState(@NotNull MyState state) { * * @return the proper settings expected by the MicroProfile language server. */ - public Map toSettingsForMicroProfileLS() { + public Map toSettingsForMicroProfileLS(MicroProfileInspectionsInfo inspectionsInfo) { + Map settings = new HashMap<>(); Map microprofile = new HashMap<>(); settings.put("microprofile", microprofile); @@ -122,10 +123,24 @@ public Map toSettingsForMicroProfileLS() { codeLens.put("urlCodeLensEnabled", isUrlCodeLensEnabled()); tools.put("codeLens", codeLens); + Map validation = new HashMap<>(); + tools.put("validation", validation); + validation.put("enabled", inspectionsInfo.enabled()); + 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())); return settings; } - static class MyState { + private Map getSeverityNode(ProblemSeverity severity) { + return Collections.singletonMap("severity", severity.name()); + } + + + public static class MyState { @Tag("inlayHintEnabled") public boolean myInlayHintEnabled = true; diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/properties/MicroProfilePropertiesView.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/properties/MicroProfilePropertiesView.java index 83323b368..aac6546d7 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/properties/MicroProfilePropertiesView.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/settings/properties/MicroProfilePropertiesView.java @@ -31,7 +31,7 @@ public class MicroProfilePropertiesView implements Disposable { private final JPanel myMainPanel; - private JBCheckBox inlayHintCheckBox = new JBCheckBox(MicroProfileBundle.message("microprofile.properties.inlayHint.enabled")); + private final JBCheckBox inlayHintCheckBox = new JBCheckBox(MicroProfileBundle.message("microprofile.properties.inlayHint.enabled")); public MicroProfilePropertiesView() { JComponent descriptionPanel = createDescription(null); 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 5e27be2bc..f453f86fa 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 @@ -10,44 +10,57 @@ ******************************************************************************/ package com.redhat.devtools.intellij.quarkus.lsp; +import com.intellij.codeInspection.InspectionProfile; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.module.Module; +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.profile.ProfileChangeAdapter; import com.intellij.util.messages.MessageBusConnection; import com.redhat.devtools.intellij.lsp4ij.client.CoalesceByKey; +import com.redhat.devtools.intellij.lsp4ij.client.IndexAwareLanguageClient; +import com.redhat.devtools.intellij.lsp4mp4ij.classpath.ClasspathResourceChangedManager; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.ProjectLabelManager; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.PropertiesManager; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.PropertiesManagerForJava; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.project.PsiMicroProfileProjectManager; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils; import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl; +import com.redhat.devtools.intellij.lsp4mp4ij.settings.MicroProfileInspectionsInfo; import com.redhat.devtools.intellij.lsp4mp4ij.settings.UserDefinedMicroProfileSettings; import com.redhat.devtools.intellij.quarkus.QuarkusModuleUtil; -import com.redhat.devtools.intellij.lsp4ij.client.IndexAwareLanguageClient; -import com.redhat.devtools.intellij.lsp4mp4ij.classpath.ClasspathResourceChangedManager; import org.eclipse.lsp4j.*; import org.eclipse.lsp4mp.commons.*; import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData; import org.eclipse.lsp4mp.commons.utils.JSONUtility; import org.eclipse.lsp4mp.ls.api.MicroProfileLanguageClientAPI; import org.eclipse.lsp4mp.ls.api.MicroProfileLanguageServerAPI; +import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; -public class QuarkusLanguageClient extends IndexAwareLanguageClient implements MicroProfileLanguageClientAPI, ClasspathResourceChangedManager.Listener { +public class QuarkusLanguageClient extends IndexAwareLanguageClient implements MicroProfileLanguageClientAPI, ClasspathResourceChangedManager.Listener, ProfileChangeAdapter { private final MessageBusConnection connection; + private MicroProfileInspectionsInfo inspectionsInfo; + public QuarkusLanguageClient(Project project) { super(project); connection = project.getMessageBus().connect(project); connection.subscribe(ClasspathResourceChangedManager.TOPIC, this); + inspectionsInfo = MicroProfileInspectionsInfo.getMicroProfileInspectionInfo(project); + connection.subscribe(ProfileChangeAdapter.TOPIC, this); // Track MicroProfile settings changed to push them to the language server with LSP didChangeConfiguration. UserDefinedMicroProfileSettings.getInstance(project).addChangeHandler(getDidChangeConfigurationListener()); } @@ -61,7 +74,7 @@ public void dispose() { @Override protected Object createSettings() { - return UserDefinedMicroProfileSettings.getInstance(getProject()).toSettingsForMicroProfileLS(); + return UserDefinedMicroProfileSettings.getInstance(getProject()).toSettingsForMicroProfileLS(inspectionsInfo); } private void sendPropertiesChangeEvent(List scope, Set uris) { @@ -74,6 +87,24 @@ private void sendPropertiesChangeEvent(List scope, } } + @Override + public void profileChanged(@NotNull InspectionProfile profile) { + // Track MicroProfile inspections settings (declared in Editor/Inspection/MicroProfue 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)) { + inspectionsInfo = newInspectionState; + ApplicationManager.getApplication().invokeLater(() -> { + new Task.Backgroundable(getProject(), "Updating LSP4MP configuration...", true) { + @Override + public void run(@NotNull ProgressIndicator progressIndicator) { + triggerChangeConfiguration(); + } + }.queue(); + }, ModalityState.defaultModalityState(), getProject().getDisposed()); + } + } + @Override public void librariesChanged() { if (isDisposed()) { diff --git a/src/main/java/com/redhat/devtools/intellij/quarkus/lsp/QuarkusServer.java b/src/main/java/com/redhat/devtools/intellij/quarkus/lsp/QuarkusServer.java index 3f24a2047..12c025e5e 100644 --- a/src/main/java/com/redhat/devtools/intellij/quarkus/lsp/QuarkusServer.java +++ b/src/main/java/com/redhat/devtools/intellij/quarkus/lsp/QuarkusServer.java @@ -14,6 +14,7 @@ import com.intellij.ide.plugins.PluginManager; import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.project.Project; +import com.redhat.devtools.intellij.lsp4mp4ij.settings.MicroProfileInspectionsInfo; import com.redhat.devtools.intellij.quarkus.TelemetryService; import com.redhat.devtools.intellij.lsp4ij.server.JavaProcessCommandBuilder; import com.redhat.devtools.intellij.lsp4ij.server.ProcessStreamConnectionProvider; @@ -51,9 +52,9 @@ public QuarkusServer(Project project) { @Override public Object getInitializationOptions(URI rootUri) { - Map root = new HashMap<>(); - Map settings = UserDefinedMicroProfileSettings.getInstance(project).toSettingsForMicroProfileLS(); + MicroProfileInspectionsInfo inspectionsInfo = MicroProfileInspectionsInfo.getMicroProfileInspectionInfo(project); + Map settings = UserDefinedMicroProfileSettings.getInstance(project).toSettingsForMicroProfileLS(inspectionsInfo); root.put("settings", settings); Map extendedClientCapabilities = new HashMap<>(); diff --git a/src/main/resources/META-INF/lsp4ij-quarkus.xml b/src/main/resources/META-INF/lsp4ij-quarkus.xml index 56fb1dd12..a66f7383a 100644 --- a/src/main/resources/META-INF/lsp4ij-quarkus.xml +++ b/src/main/resources/META-INF/lsp4ij-quarkus.xml @@ -58,6 +58,61 @@ implementationClass="com.redhat.devtools.intellij.lsp4ij.operations.documentLink.LSPDocumentLinkAnnotator"/> + + + + + + + diff --git a/src/main/resources/META-INF/lsp4ij.xml b/src/main/resources/META-INF/lsp4ij.xml index 3753131af..f78df8d07 100644 --- a/src/main/resources/META-INF/lsp4ij.xml +++ b/src/main/resources/META-INF/lsp4ij.xml @@ -47,7 +47,6 @@ - diff --git a/src/main/resources/inspectionDescriptions/MicroProfilePropertiesDuplicates.html b/src/main/resources/inspectionDescriptions/MicroProfilePropertiesDuplicates.html new file mode 100644 index 000000000..0692a915c --- /dev/null +++ b/src/main/resources/inspectionDescriptions/MicroProfilePropertiesDuplicates.html @@ -0,0 +1,21 @@ + + +Reports duplicate properties in MicroProfile .properties files. +

    Example:

    +
    
    +my.property=one
    +my.property=two
    +
    +
    +

    + ⚠ This inspection is used to configure the Tools for MicroProfile server in Settings | Languages & Frameworks | Language Servers.

    + Consequently, some limitations apply: +

    +
      +
    • Scope: values are ignored
    • +
    • Severity: only Error and (Weak) Warning are respected. Other values mean no errors will be reported
    • +
    • Highlighting in Editor: values are ignored
    • +
    +
    + + \ No newline at end of file diff --git a/src/main/resources/inspectionDescriptions/MicroProfilePropertiesExpressions.html b/src/main/resources/inspectionDescriptions/MicroProfilePropertiesExpressions.html new file mode 100644 index 000000000..73231713d --- /dev/null +++ b/src/main/resources/inspectionDescriptions/MicroProfilePropertiesExpressions.html @@ -0,0 +1,21 @@ + + +Reports invalid expressions in values of MicroProfile .properties files. +

    Example:

    +
    
    +my.property=${invalid.property}
    +
    + +
    +

    + ⚠ This inspection is used to configure the Tools for MicroProfile server in Settings | Languages & Frameworks | Language Servers.

    + Consequently, some limitations apply: +

    +
      +
    • Scope: values are ignored
    • +
    • Severity: only Error and (Weak) Warning are respected. Other values mean no errors will be reported
    • +
    • Highlighting in Editor: values are ignored
    • +
    +
    + + \ No newline at end of file diff --git a/src/main/resources/inspectionDescriptions/MicroProfilePropertiesRequired.html b/src/main/resources/inspectionDescriptions/MicroProfilePropertiesRequired.html new file mode 100644 index 000000000..d425c6ddc --- /dev/null +++ b/src/main/resources/inspectionDescriptions/MicroProfilePropertiesRequired.html @@ -0,0 +1,17 @@ + + +Reports required properties missing from MicroProfile .properties files. +

    +
    +

    + ⚠ This inspection is used to configure the Tools for MicroProfile server in Settings | Languages & Frameworks | Language Servers.

    + Consequently, some limitations apply: +

    +
      +
    • Scope: values are ignored
    • +
    • Severity: only Error and (Weak) Warning are respected. Other values mean no errors will be reported
    • +
    • Highlighting in Editor: values are ignored
    • +
    +
    + + \ No newline at end of file diff --git a/src/main/resources/inspectionDescriptions/MicroProfilePropertiesSyntax.html b/src/main/resources/inspectionDescriptions/MicroProfilePropertiesSyntax.html new file mode 100644 index 000000000..44240300f --- /dev/null +++ b/src/main/resources/inspectionDescriptions/MicroProfilePropertiesSyntax.html @@ -0,0 +1,21 @@ + + +Reports syntax errors in MicroProfile .properties files. +

    Example:

    +
    
    +valid.property=no syntax error
    +invalid.property
    +
    +
    +

    + ⚠ This inspection is used to configure the Tools for MicroProfile server in Settings | Languages & Frameworks | Language Servers.

    + Consequently, some limitations apply: +

    +
      +
    • Scope: values are ignored
    • +
    • Severity: only Error and (Weak) Warning are respected. Other values mean no errors will be reported
    • +
    • Highlighting in Editor: values are ignored
    • +
    +
    + + \ No newline at end of file diff --git a/src/main/resources/inspectionDescriptions/MicroProfilePropertiesUnknown.html b/src/main/resources/inspectionDescriptions/MicroProfilePropertiesUnknown.html new file mode 100644 index 000000000..258d85520 --- /dev/null +++ b/src/main/resources/inspectionDescriptions/MicroProfilePropertiesUnknown.html @@ -0,0 +1,17 @@ + + +Reports unknown properties in MicroProfile .properties files. +

    +
    +

    + ⚠ This inspection is used to configure the Tools for MicroProfile server in Settings | Languages & Frameworks | Language Servers.

    + Consequently, some limitations apply: +

    +
      +
    • Scope: values are ignored
    • +
    • Severity: only Error and (Weak) Warning are respected. Other values mean no errors will be reported
    • +
    • Highlighting in Editor: values are ignored
    • +
    +
    + + \ No newline at end of file diff --git a/src/main/resources/inspectionDescriptions/MicroProfilePropertiesValue.html b/src/main/resources/inspectionDescriptions/MicroProfilePropertiesValue.html new file mode 100644 index 000000000..f758ac7d9 --- /dev/null +++ b/src/main/resources/inspectionDescriptions/MicroProfilePropertiesValue.html @@ -0,0 +1,21 @@ + + +Reports invalid values in MicroProfile .properties files. +

    Example:

    +
    
    +#Expects true/false
    +service.enabled=maybe
    +
    +
    +

    + ⚠ This inspection is used to configure the Tools for MicroProfile server in Settings | Languages & Frameworks | Language Servers.

    + Consequently, some limitations apply: +

    +
      +
    • Scope: values are ignored
    • +
    • Severity: only Error and (Weak) Warning are respected. Other values mean no errors will be reported
    • +
    • Highlighting in Editor: values are ignored
    • +
    +
    + + \ No newline at end of file diff --git a/src/main/resources/messages/MicroProfileBundle.properties b/src/main/resources/messages/MicroProfileBundle.properties index e65a34570..a84d28698 100644 --- a/src/main/resources/messages/MicroProfileBundle.properties +++ b/src/main/resources/messages/MicroProfileBundle.properties @@ -15,12 +15,20 @@ microprofile=MicroProfile microprofile.title=MicroProfile microprofile.description=Configure MicroProfile support in Java and 'microprofile-config.properties' files. - +microprofile.properties.inspection.group.name=Properties +microprofile.java.inspection.group.name=Java files +microprofile.inspection.group.name=MicroProfile ## MicroProfile UI settings page for properties files 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.syntax=Syntax checking +microprofile.properties.validation.unknown=Unknown properties +microprofile.properties.validation.duplicate=Duplicate properties +microprofile.properties.validation.value=Invalid values +microprofile.properties.validation.required=Required properties +microprofile.properties.validation.expression=Property expressions +microprofile.properties.validation.unassigned=Unassigned properties ## MicroProfile UI settings page for Java files microprofile.java=Java microprofile.java.title=MicroProfile configuration in Java files diff --git a/src/test/java/com/redhat/devtools/intellij/quarkus/completion/MavenApplicationPropertiesCompletionTest.java b/src/test/java/com/redhat/devtools/intellij/quarkus/completion/MavenApplicationPropertiesCompletionTest.java index 0c0cc37ee..76e4403e8 100644 --- a/src/test/java/com/redhat/devtools/intellij/quarkus/completion/MavenApplicationPropertiesCompletionTest.java +++ b/src/test/java/com/redhat/devtools/intellij/quarkus/completion/MavenApplicationPropertiesCompletionTest.java @@ -36,7 +36,7 @@ public void testBooleanCompletion() throws Exception { codeInsightTestFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_LINE_END); codeInsightTestFixture.performEditorAction(IdeActions.ACTION_EDITOR_START_NEW_LINE); insertLine("quarkus.arc.auto-inject-fields="); - LookupElement[] elements = codeInsightTestFixture.complete(CompletionType.BASIC); + LookupElement[] elements = codeInsightTestFixture.completeBasic(); assertNotNull(elements); assertEquals(2, elements.length); } @@ -44,7 +44,7 @@ public void testBooleanCompletion() throws Exception { private void insertLine(String s) throws InterruptedException { for (int i = 0; i < s.length(); ++i) { codeInsightTestFixture.type(s.charAt(i)); - Thread.sleep(1000); } + Thread.sleep(1000); } }