-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a first POC for bnd autocompletion on pom files
Signed-off-by: Christoph Läubrich <[email protected]>
- Loading branch information
Showing
8 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="optional" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="test" value="true"/> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> | ||
<attributes> | ||
<attribute name="test" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="optional" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"> | ||
<attributes> | ||
<attribute name="module" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>org.eclipse.m2e.lemminx.bnd</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
8 changes: 8 additions & 0 deletions
8
org.eclipse.m2e.lemminx.bnd/.settings/org.eclipse.jdt.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 | ||
org.eclipse.jdt.core.compiler.compliance=17 | ||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning | ||
org.eclipse.jdt.core.compiler.release=enabled | ||
org.eclipse.jdt.core.compiler.source=17 |
4 changes: 4 additions & 0 deletions
4
org.eclipse.m2e.lemminx.bnd/.settings/org.eclipse.m2e.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<!-- <parent>--> | ||
<!-- <groupId>org.eclipse.m2e</groupId>--> | ||
<!-- <artifactId>m2e-core</artifactId>--> | ||
<!-- <version>2.1.0-SNAPSHOT</version>--> | ||
<!-- </parent>--> | ||
<groupId>org.eclipse.m2e.lemminx.bnd</groupId> | ||
<artifactId>org.eclipse.m2e.lemminx.bnd</artifactId> | ||
<version>2.1.0-SNAPSHOT</version> | ||
<name>M2E bnd lemminx extension</name> | ||
|
||
<properties> | ||
<java.version>17</java.version> | ||
<maven.compiler.release>${java.version}</maven.compiler.release> | ||
</properties> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.lemminx</groupId> | ||
<artifactId>org.eclipse.lemminx</artifactId> | ||
<version>0.28.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>biz.aQute.bnd</groupId> | ||
<artifactId>biz.aQute.bndlib</artifactId> | ||
<version>7.0.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<repositories> | ||
<repository> | ||
<id>lemminx-releases</id> | ||
<url>https://repo.eclipse.org/content/repositories/lemminx-releases/</url> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
</snapshots> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
</repository> | ||
</repositories> | ||
</project> |
122 changes: 122 additions & 0 deletions
122
org.eclipse.m2e.lemminx.bnd/src/main/java/org/eclipse/m2e/lemminx/bnd/BndLemminxPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Christoph Läubrich | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.m2e.lemminx.bnd; | ||
|
||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import org.eclipse.lemminx.dom.DOMDocument; | ||
import org.eclipse.lemminx.dom.DOMNode; | ||
import org.eclipse.lemminx.services.extensions.IXMLExtension; | ||
import org.eclipse.lemminx.services.extensions.XMLExtensionsRegistry; | ||
import org.eclipse.lemminx.services.extensions.completion.ICompletionParticipant; | ||
import org.eclipse.lemminx.services.extensions.completion.ICompletionRequest; | ||
import org.eclipse.lemminx.services.extensions.completion.ICompletionResponse; | ||
import org.eclipse.lemminx.services.extensions.save.ISaveContext; | ||
import org.eclipse.lsp4j.CompletionItem; | ||
import org.eclipse.lsp4j.InitializeParams; | ||
import org.eclipse.lsp4j.jsonrpc.CancelChecker; | ||
|
||
import aQute.bnd.help.Syntax; | ||
|
||
public class BndLemminxPlugin implements IXMLExtension { | ||
|
||
// TODO LemminxClasspathExtensionProvider that puts our jar on the classpath + | ||
// bnd dependencies! | ||
|
||
@Override | ||
public void start(InitializeParams params, XMLExtensionsRegistry registry) { | ||
Logger logger = Logger.getLogger("bnd"); | ||
logger.log(Level.INFO, "Hello From BND Extension"); | ||
registry.registerCompletionParticipant(new ICompletionParticipant() { | ||
|
||
@Override | ||
public void onAttributeName(boolean arg0, ICompletionRequest arg1, ICompletionResponse arg2, | ||
CancelChecker arg3) throws Exception { | ||
} | ||
|
||
@Override | ||
public void onAttributeValue(String arg0, ICompletionRequest arg1, ICompletionResponse arg2, | ||
CancelChecker arg3) throws Exception { | ||
} | ||
|
||
@Override | ||
public void onDTDSystemId(String arg0, ICompletionRequest arg1, ICompletionResponse arg2, | ||
CancelChecker arg3) throws Exception { | ||
} | ||
|
||
@Override | ||
public void onTagOpen(ICompletionRequest arg0, ICompletionResponse arg1, CancelChecker arg2) | ||
throws Exception { | ||
} | ||
|
||
@Override | ||
public void onXMLContent(ICompletionRequest completionRequest, ICompletionResponse response, | ||
CancelChecker checker) throws Exception { | ||
try { | ||
// FIXME CDATA do not trigger completion: | ||
// https://github.com/eclipse/lemminx/issues/1694 | ||
DOMDocument xmlDocument = completionRequest.getXMLDocument(); | ||
DOMNode node = xmlDocument.findNodeBefore(completionRequest.getOffset()); | ||
if (isBndNode(node)) { | ||
// FIXME get the text to give better completion proposals, see: | ||
// https://github.com/eclipse/lemminx/issues/1695 | ||
// if (node != null && node.getNodeName().equals("bnd")) { | ||
// logger.log(Level.INFO, "text content=" + node.getTextContent()); | ||
// String substring = xmlDocument.getText().substring(node.getStart(), node.getEnd()); | ||
// logger.log(Level.INFO, "substring=" + substring); | ||
// } else { | ||
// logger.log(Level.INFO, | ||
// "node=" + node + ", start=" + node.getStart() + ", end=" + node.getEnd() | ||
// + " --> text content=" + node.getTextContent()); | ||
// | ||
// // Syntax.HELP.values().stream().map(syntax -> { | ||
// } | ||
Syntax.HELP.values().stream().forEach(syntax -> { | ||
CompletionItem item = new CompletionItem(); | ||
item.setLabel(syntax.getHeader()); | ||
item.setInsertText(syntax.getHeader() + ": "); | ||
response.addCompletionItem(item); | ||
}); | ||
} | ||
} catch (Exception e) { | ||
logger.log(Level.INFO, "err=" + e); | ||
} | ||
} | ||
|
||
private boolean isBndNode(DOMNode node) { | ||
if (node != null) { | ||
if (node.getNodeName().equals("bnd")) { | ||
return true; | ||
} | ||
return isBndNode(node.getParentNode()); | ||
} | ||
return false; | ||
} | ||
|
||
}); | ||
} | ||
|
||
@Override | ||
public void stop(XMLExtensionsRegistry registry) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void doSave(ISaveContext context) { | ||
// TODO Auto-generated method stub | ||
IXMLExtension.super.doSave(context); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...rc/main/resources/META-INF/services/org.eclipse.lemminx.services.extensions.IXMLExtension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.eclipse.m2e.lemminx.bnd.BndLemminxPlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters