Skip to content

Commit f9dc823

Browse files
committed
feat: define a custom LSP local inspection tool for Qute
Signed-off-by: azerr <[email protected]>
1 parent cf028af commit f9dc823

File tree

5 files changed

+100
-3
lines changed

5 files changed

+100
-3
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at https://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
package com.redhat.devtools.intellij.qute.lsp;
12+
13+
import com.redhat.devtools.lsp4ij.client.features.LSPClientFeatures;
14+
15+
/**
16+
* Qute client features.
17+
*/
18+
public class QuteClientFeatures extends LSPClientFeatures {
19+
20+
public QuteClientFeatures() {
21+
super.setDiagnosticFeature(new QuteDiagnosticFeature());
22+
}
23+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at https://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
package com.redhat.devtools.intellij.qute.lsp;
12+
13+
import com.intellij.codeInspection.LocalInspectionTool;
14+
import com.intellij.psi.PsiFile;
15+
import com.redhat.devtools.intellij.qute.lang.QuteLanguage;
16+
import com.redhat.devtools.intellij.qute.psi.core.inspections.QuteLSPLocalInspectionTool;
17+
import com.redhat.devtools.lsp4ij.client.features.LSPDiagnosticFeature;
18+
import org.jetbrains.annotations.NotNull;
19+
20+
/**
21+
* Qute diagnostics features.
22+
*/
23+
public class QuteDiagnosticFeature extends LSPDiagnosticFeature {
24+
25+
@Override
26+
public boolean isInspectionApplicableFor(@NotNull PsiFile file,
27+
@NotNull LocalInspectionTool inspection) {
28+
if (file.getLanguage() == QuteLanguage.INSTANCE) {
29+
// Show Qute templates warnings/errors
30+
// after clicking on "Inspect Code..." from the problem view.
31+
return QuteLSPLocalInspectionTool.ID.equals(inspection.getID());
32+
}
33+
return super.isInspectionApplicableFor(file, inspection);
34+
}
35+
}

src/main/java/com/redhat/devtools/intellij/qute/lsp/QuteLanguageServerFactory.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,34 @@
1313
import com.intellij.openapi.project.Project;
1414
import com.redhat.devtools.lsp4ij.LanguageServerFactory;
1515
import com.redhat.devtools.lsp4ij.client.LanguageClientImpl;
16+
import com.redhat.devtools.lsp4ij.client.features.LSPClientFeatures;
1617
import com.redhat.devtools.lsp4ij.server.StreamConnectionProvider;
1718
import com.redhat.qute.ls.api.QuteLanguageServerAPI;
1819
import org.eclipse.lsp4j.services.LanguageServer;
20+
import org.jetbrains.annotations.NotNull;
1921

2022
/**
2123
* Qute language server factory.
2224
*/
2325
public class QuteLanguageServerFactory implements LanguageServerFactory {
2426

2527
@Override
26-
public StreamConnectionProvider createConnectionProvider(Project project) {
28+
public @NotNull StreamConnectionProvider createConnectionProvider(@NotNull Project project) {
2729
return new QuteServer(project);
2830
}
2931

3032
@Override
31-
public LanguageClientImpl createLanguageClient(Project project) {
33+
public @NotNull LanguageClientImpl createLanguageClient(@NotNull Project project) {
3234
return new QuteLanguageClient(project);
3335
}
3436

3537
@Override
36-
public Class<? extends LanguageServer> getServerInterface() {
38+
public @NotNull Class<? extends LanguageServer> getServerInterface() {
3739
return QuteLanguageServerAPI.class;
3840
}
41+
42+
@Override
43+
public @NotNull LSPClientFeatures createClientFeatures() {
44+
return new QuteClientFeatures();
45+
}
3946
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at https://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
package com.redhat.devtools.intellij.qute.psi.core.inspections;
12+
13+
import com.redhat.devtools.lsp4ij.inspections.LSPLocalInspectionToolBase;
14+
15+
/**
16+
* Custom LSP inspection tool for Qute to display
17+
* Qute templates warnings/errors in Qute/Templates tree node
18+
* from the problem view (after clicking on "Inspect Code..." ).
19+
*/
20+
public class QuteLSPLocalInspectionTool extends LSPLocalInspectionToolBase {
21+
22+
public static final String ID = "QuteLSPLocalInspectionTool";
23+
}

src/main/resources/META-INF/lsp4ij-qute.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@
5555
key="qute.settings.title"
5656
instance="com.redhat.devtools.intellij.qute.settings.QuteConfigurable"/>
5757

58+
<localInspection
59+
id="QuteLSPLocalInspectionTool"
60+
language="Qute_"
61+
bundle="messages.QuteBundle"
62+
groupName="Qute"
63+
displayName="Templates"
64+
enabledByDefault="true"
65+
implementationClass="com.redhat.devtools.intellij.qute.psi.core.inspections.QuteLSPLocalInspectionTool"/>
66+
5867
<localInspection
5968
unfair="true"
6069
language="Qute_"

0 commit comments

Comments
 (0)