Skip to content

Commit 5ba1378

Browse files
committed
Add a first POC for bnd autocompletion on pom files
Signed-off-by: Christoph Läubrich <[email protected]>
1 parent b9662aa commit 5ba1378

File tree

8 files changed

+248
-0
lines changed

8 files changed

+248
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
<attribute name="optional" value="true"/>
13+
</attributes>
14+
</classpathentry>
15+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
16+
<attributes>
17+
<attribute name="test" value="true"/>
18+
<attribute name="optional" value="true"/>
19+
<attribute name="maven.pomderived" value="true"/>
20+
</attributes>
21+
</classpathentry>
22+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
23+
<attributes>
24+
<attribute name="test" value="true"/>
25+
<attribute name="maven.pomderived" value="true"/>
26+
<attribute name="optional" value="true"/>
27+
</attributes>
28+
</classpathentry>
29+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
30+
<attributes>
31+
<attribute name="module" value="true"/>
32+
<attribute name="maven.pomderived" value="true"/>
33+
</attributes>
34+
</classpathentry>
35+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
36+
<attributes>
37+
<attribute name="maven.pomderived" value="true"/>
38+
</attributes>
39+
</classpathentry>
40+
<classpathentry kind="output" path="target/classes"/>
41+
</classpath>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>org.eclipse.m2e.lemminx.bnd</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
22+
</natures>
23+
</projectDescription>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
3+
org.eclipse.jdt.core.compiler.compliance=17
4+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
5+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
7+
org.eclipse.jdt.core.compiler.release=enabled
8+
org.eclipse.jdt.core.compiler.source=17
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<!-- <parent>-->
6+
<!-- <groupId>org.eclipse.m2e</groupId>-->
7+
<!-- <artifactId>m2e-core</artifactId>-->
8+
<!-- <version>2.1.0-SNAPSHOT</version>-->
9+
<!-- </parent>-->
10+
<groupId>org.eclipse.m2e.lemminx.bnd</groupId>
11+
<artifactId>org.eclipse.m2e.lemminx.bnd</artifactId>
12+
<version>2.1.0-SNAPSHOT</version>
13+
<name>M2E bnd lemminx extension</name>
14+
15+
<properties>
16+
<java.version>17</java.version>
17+
<maven.compiler.release>${java.version}</maven.compiler.release>
18+
</properties>
19+
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.eclipse.lemminx</groupId>
24+
<artifactId>org.eclipse.lemminx</artifactId>
25+
<version>0.28.0</version>
26+
<scope>provided</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>biz.aQute.bnd</groupId>
30+
<artifactId>biz.aQute.bndlib</artifactId>
31+
<version>7.0.0</version>
32+
</dependency>
33+
</dependencies>
34+
35+
<repositories>
36+
<repository>
37+
<id>lemminx-releases</id>
38+
<url>https://repo.eclipse.org/content/repositories/lemminx-releases/</url>
39+
<snapshots>
40+
<enabled>false</enabled>
41+
</snapshots>
42+
<releases>
43+
<enabled>true</enabled>
44+
</releases>
45+
</repository>
46+
</repositories>
47+
</project>
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Christoph Läubrich
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Christoph Läubrich - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.m2e.lemminx.bnd;
14+
15+
import java.util.logging.Level;
16+
import java.util.logging.Logger;
17+
18+
import org.eclipse.lemminx.dom.DOMDocument;
19+
import org.eclipse.lemminx.dom.DOMNode;
20+
import org.eclipse.lemminx.services.extensions.IXMLExtension;
21+
import org.eclipse.lemminx.services.extensions.XMLExtensionsRegistry;
22+
import org.eclipse.lemminx.services.extensions.completion.ICompletionParticipant;
23+
import org.eclipse.lemminx.services.extensions.completion.ICompletionRequest;
24+
import org.eclipse.lemminx.services.extensions.completion.ICompletionResponse;
25+
import org.eclipse.lemminx.services.extensions.save.ISaveContext;
26+
import org.eclipse.lsp4j.CompletionItem;
27+
import org.eclipse.lsp4j.InitializeParams;
28+
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
29+
30+
import aQute.bnd.help.Syntax;
31+
32+
public class BndLemminxPlugin implements IXMLExtension {
33+
34+
// TODO LemminxClasspathExtensionProvider that puts our jar on the classpath +
35+
// bnd dependencies!
36+
37+
@Override
38+
public void start(InitializeParams params, XMLExtensionsRegistry registry) {
39+
Logger logger = Logger.getLogger("bnd");
40+
logger.log(Level.INFO, "Hello From BND Extension");
41+
registry.registerCompletionParticipant(new ICompletionParticipant() {
42+
43+
@Override
44+
public void onAttributeName(boolean arg0, ICompletionRequest arg1, ICompletionResponse arg2,
45+
CancelChecker arg3) throws Exception {
46+
}
47+
48+
@Override
49+
public void onAttributeValue(String arg0, ICompletionRequest arg1, ICompletionResponse arg2,
50+
CancelChecker arg3) throws Exception {
51+
}
52+
53+
@Override
54+
public void onDTDSystemId(String arg0, ICompletionRequest arg1, ICompletionResponse arg2,
55+
CancelChecker arg3) throws Exception {
56+
}
57+
58+
@Override
59+
public void onTagOpen(ICompletionRequest arg0, ICompletionResponse arg1, CancelChecker arg2)
60+
throws Exception {
61+
}
62+
63+
@Override
64+
public void onXMLContent(ICompletionRequest completionRequest, ICompletionResponse response,
65+
CancelChecker checker) throws Exception {
66+
try {
67+
// FIXME CDATA do not trigger completion:
68+
// https://github.com/eclipse/lemminx/issues/1694
69+
DOMDocument xmlDocument = completionRequest.getXMLDocument();
70+
DOMNode node = xmlDocument.findNodeBefore(completionRequest.getOffset());
71+
if (isBndNode(node)) {
72+
// FIXME get the text to give better completion proposals, see:
73+
// https://github.com/eclipse/lemminx/issues/1695
74+
// if (node != null && node.getNodeName().equals("bnd")) {
75+
// logger.log(Level.INFO, "text content=" + node.getTextContent());
76+
// String substring = xmlDocument.getText().substring(node.getStart(), node.getEnd());
77+
// logger.log(Level.INFO, "substring=" + substring);
78+
// } else {
79+
// logger.log(Level.INFO,
80+
// "node=" + node + ", start=" + node.getStart() + ", end=" + node.getEnd()
81+
// + " --> text content=" + node.getTextContent());
82+
//
83+
// // Syntax.HELP.values().stream().map(syntax -> {
84+
// }
85+
Syntax.HELP.values().stream().forEach(syntax -> {
86+
CompletionItem item = new CompletionItem();
87+
item.setLabel(syntax.getHeader());
88+
item.setInsertText(syntax.getHeader() + ": ");
89+
response.addCompletionItem(item);
90+
});
91+
}
92+
} catch (Exception e) {
93+
logger.log(Level.INFO, "err=" + e);
94+
}
95+
}
96+
97+
private boolean isBndNode(DOMNode node) {
98+
if (node != null) {
99+
if (node.getNodeName().equals("bnd")) {
100+
return true;
101+
}
102+
return isBndNode(node.getParentNode());
103+
}
104+
return false;
105+
}
106+
107+
});
108+
}
109+
110+
@Override
111+
public void stop(XMLExtensionsRegistry registry) {
112+
// TODO Auto-generated method stub
113+
114+
}
115+
116+
@Override
117+
public void doSave(ISaveContext context) {
118+
// TODO Auto-generated method stub
119+
IXMLExtension.super.doSave(context);
120+
}
121+
122+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.eclipse.m2e.lemminx.bnd.BndLemminxPlugin

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
<module>org.eclipse.m2e.apt.core</module>
6565
<module>org.eclipse.m2e.apt.ui</module>
6666
<module>org.eclipse.m2e.mavenarchiver</module>
67+
<module>org.eclipse.m2e.bnd.ui</module>
68+
<module>org.eclipse.m2e.lemminx.bnd</module>
6769

6870
<!-- common test helpers -->
6971
<module>org.eclipse.m2e.tests.common</module>

0 commit comments

Comments
 (0)