-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Apache Camel LSP support (#8648)
* Provide Camel Language Server Agent Signed-off-by: Aurélien Pupier <apupier@redhat.com>
- Loading branch information
Showing
12 changed files
with
351 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,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2012-2018 Red Hat, Inc. | ||
All rights reserved. This program and the accompanying materials | ||
are made available under the terms of the Eclipse Public License v1.0 | ||
which accompanies this distribution, and is available at | ||
http://www.eclipse.org/legal/epl-v10.html | ||
Contributors: | ||
Red Hat, Inc. - initial API and implementation | ||
--> | ||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>che-agents-parent</artifactId> | ||
<groupId>org.eclipse.che</groupId> | ||
<version>6.1.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>ls-camel-agent</artifactId> | ||
<name>Language Server Apache Camel Agent</name> | ||
</project> |
8 changes: 8 additions & 0 deletions
8
agents/ls-camel/src/main/resources/installers/1.0.0/org.eclipse.che.ls.camel.json
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 @@ | ||
{ | ||
"id": "org.eclipse.che.ls.camel", | ||
"version": "1.0.0", | ||
"name": "Apache Camel language server", | ||
"description": "Apache Camel intellisense", | ||
"dependencies": [], | ||
"properties": {} | ||
} |
61 changes: 61 additions & 0 deletions
61
agents/ls-camel/src/main/resources/installers/1.0.0/org.eclipse.che.ls.camel.script.sh
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,61 @@ | ||
# | ||
# Copyright (c) 2012-2018 Red Hat, Inc. | ||
# All rights reserved. This program and the accompanying materials | ||
# are made available under the terms of the Eclipse Public License v1.0 | ||
# which accompanies this distribution, and is available at | ||
# http://www.eclipse.org/legal/epl-v10.html | ||
# | ||
# Contributors: | ||
# Red Hat, Inc. - initial API and implementation | ||
# | ||
|
||
|
||
is_current_user_root() { | ||
test "$(id -u)" = 0 | ||
} | ||
|
||
is_current_user_sudoer() { | ||
sudo -n true > /dev/null 2>&1 | ||
} | ||
|
||
set_sudo_command() { | ||
if is_current_user_sudoer && ! is_current_user_root; then SUDO="sudo -E"; else unset SUDO; fi | ||
} | ||
|
||
set_sudo_command | ||
unset PACKAGES | ||
command -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" tar"; } | ||
command -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" curl"; } | ||
|
||
AGENT_BINARIES_URI=https://github.com/lhein/camel-language-server/releases/download/untagged-d42064681113e838bd59/camel-lsp-server-1.0.0-SNAPSHOT.jar | ||
CHE_DIR=$HOME/che | ||
LS_DIR=${CHE_DIR}/ls-camel | ||
LS_LAUNCHER=${LS_DIR}/launch.sh | ||
|
||
if [ -f /etc/centos-release ]; then | ||
FILE="/etc/centos-release" | ||
LINUX_TYPE=$(cat $FILE | awk '{print $1}') | ||
elif [ -f /etc/redhat-release ]; then | ||
FILE="/etc/redhat-release" | ||
LINUX_TYPE=$(cat $FILE | cut -c 1-8) | ||
else | ||
FILE="/etc/os-release" | ||
LINUX_TYPE=$(cat $FILE | grep ^ID= | tr '[:upper:]' '[:lower:]') | ||
LINUX_VERSION=$(cat $FILE | grep ^VERSION_ID=) | ||
fi | ||
|
||
MACHINE_TYPE=$(uname -m) | ||
|
||
mkdir -p ${CHE_DIR} | ||
mkdir -p ${LS_DIR} | ||
|
||
|
||
############################### | ||
### Install Apache Camel LS ### | ||
############################### | ||
|
||
curl -L -s ${AGENT_BINARIES_URI} -o ${LS_DIR}/camel-lsp-server.jar | ||
|
||
touch ${LS_LAUNCHER} | ||
chmod +x ${LS_LAUNCHER} | ||
echo "java -jar ${LS_DIR}/camel-lsp-server.jar" > ${LS_LAUNCHER} |
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
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
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
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,64 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2012-2018 Red Hat, Inc. | ||
All rights reserved. This program and the accompanying materials | ||
are made available under the terms of the Eclipse Public License v1.0 | ||
which accompanies this distribution, and is available at | ||
http://www.eclipse.org/legal/epl-v10.html | ||
Contributors: | ||
Red Hat, Inc. - initial API and implementation | ||
--> | ||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>che-plugin-camel-parent</artifactId> | ||
<groupId>org.eclipse.che.plugin</groupId> | ||
<version>6.1.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>che-plugin-camel-server</artifactId> | ||
<name>Che Plugin :: Apache Camel :: Server</name> | ||
<properties> | ||
<findbugs.failonerror>false</findbugs.failonerror> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.inject</groupId> | ||
<artifactId>guice</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.inject.extensions</groupId> | ||
<artifactId>guice-multibindings</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.inject</groupId> | ||
<artifactId>javax.inject</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-api-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-api-languageserver</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-api-languageserver-shared</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-commons-inject</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.lsp4j</groupId> | ||
<artifactId>org.eclipse.lsp4j</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.lsp4j</groupId> | ||
<artifactId>org.eclipse.lsp4j.jsonrpc</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
42 changes: 42 additions & 0 deletions
42
...in-camel-server/src/main/java/org/eclipse/che/plugin/camel/server/inject/CamelModule.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,42 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.plugin.camel.server.inject; | ||
|
||
import static java.util.Arrays.asList; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.google.inject.multibindings.Multibinder; | ||
import org.eclipse.che.api.languageserver.launcher.LanguageServerLauncher; | ||
import org.eclipse.che.api.languageserver.shared.model.LanguageDescription; | ||
import org.eclipse.che.inject.DynaModule; | ||
import org.eclipse.che.plugin.camel.server.languageserver.CamelLanguageServerLauncher; | ||
|
||
/** Apache Camel module for server side of Camel Language Server */ | ||
@DynaModule | ||
public class CamelModule extends AbstractModule { | ||
public static final String LANGUAGE_ID = "LANGUAGE_ID_APACHE_CAMEL"; | ||
private static final String[] EXTENSIONS = new String[] {"xml"}; | ||
private static final String MIME_TYPE = "text/xml"; | ||
|
||
@Override | ||
protected void configure() { | ||
Multibinder.newSetBinder(binder(), LanguageServerLauncher.class) | ||
.addBinding() | ||
.to(CamelLanguageServerLauncher.class); | ||
LanguageDescription description = new LanguageDescription(); | ||
description.setFileExtensions(asList(EXTENSIONS)); | ||
description.setLanguageId(LANGUAGE_ID); | ||
description.setMimeType(MIME_TYPE); | ||
Multibinder.newSetBinder(binder(), LanguageDescription.class) | ||
.addBinding() | ||
.toInstance(description); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
.../java/org/eclipse/che/plugin/camel/server/languageserver/CamelLanguageServerLauncher.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,105 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.plugin.camel.server.languageserver; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Arrays; | ||
import javax.inject.Named; | ||
import org.eclipse.che.api.core.rest.HttpJsonRequestFactory; | ||
import org.eclipse.che.api.languageserver.exception.LanguageServerException; | ||
import org.eclipse.che.api.languageserver.launcher.LanguageServerLauncher; | ||
import org.eclipse.che.api.languageserver.launcher.LanguageServerLauncherTemplate; | ||
import org.eclipse.che.api.languageserver.registry.DocumentFilter; | ||
import org.eclipse.che.api.languageserver.registry.LanguageServerDescription; | ||
import org.eclipse.che.api.languageserver.registry.ServerInitializerObserver; | ||
import org.eclipse.che.plugin.camel.server.inject.CamelModule; | ||
import org.eclipse.lsp4j.ServerCapabilities; | ||
import org.eclipse.lsp4j.jsonrpc.Launcher; | ||
import org.eclipse.lsp4j.services.LanguageClient; | ||
import org.eclipse.lsp4j.services.LanguageServer; | ||
|
||
/** Launcher for Apache Camel Language Server */ | ||
@Singleton | ||
public class CamelLanguageServerLauncher extends LanguageServerLauncherTemplate | ||
implements ServerInitializerObserver { | ||
|
||
private static final String REGEX = ".*\\.(xml)"; | ||
private static final LanguageServerDescription DESCRIPTION = createServerDescription(); | ||
private static LanguageServer camelLanguageServer; | ||
private final Path launchScript; | ||
|
||
@Inject | ||
public CamelLanguageServerLauncher( | ||
@Named("che.api") String apiUrl, HttpJsonRequestFactory requestFactory) { | ||
launchScript = Paths.get(System.getenv("HOME"), "che/ls-camel/launch.sh"); | ||
} | ||
|
||
@Override | ||
public boolean isAbleToLaunch() { | ||
return Files.exists(launchScript); | ||
} | ||
|
||
protected LanguageServer connectToLanguageServer( | ||
final Process languageServerProcess, LanguageClient client) { | ||
Launcher<LanguageServer> launcher = | ||
Launcher.createLauncher( | ||
client, | ||
LanguageServer.class, | ||
languageServerProcess.getInputStream(), | ||
languageServerProcess.getOutputStream()); | ||
launcher.startListening(); | ||
setCamelLanguageServer(launcher.getRemoteProxy()); | ||
return launcher.getRemoteProxy(); | ||
} | ||
|
||
protected Process startLanguageServerProcess(String projectPath) throws LanguageServerException { | ||
ProcessBuilder processBuilder = new ProcessBuilder(launchScript.toString()); | ||
processBuilder.redirectInput(ProcessBuilder.Redirect.PIPE); | ||
processBuilder.redirectOutput(ProcessBuilder.Redirect.PIPE); | ||
try { | ||
return processBuilder.start(); | ||
} catch (IOException e) { | ||
throw new LanguageServerException("Can't start Apache Camel language server", e); | ||
} | ||
} | ||
|
||
protected static LanguageServer getCamelLanguageServer() { | ||
return camelLanguageServer; | ||
} | ||
|
||
protected static void setCamelLanguageServer(LanguageServer camelLanguageServer) { | ||
CamelLanguageServerLauncher.camelLanguageServer = camelLanguageServer; | ||
} | ||
|
||
public LanguageServerDescription getDescription() { | ||
return DESCRIPTION; | ||
} | ||
|
||
private static LanguageServerDescription createServerDescription() { | ||
LanguageServerDescription description = | ||
new LanguageServerDescription( | ||
"org.eclipse.che.plugin.camel.server.languageserver", | ||
null, | ||
Arrays.asList(new DocumentFilter(CamelModule.LANGUAGE_ID, REGEX, null))); | ||
return description; | ||
} | ||
|
||
@Override | ||
public void onServerInitialized( | ||
LanguageServerLauncher arg0, LanguageServer arg1, ServerCapabilities arg2, String arg3) { | ||
// nothing to do | ||
} | ||
} |
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,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2012-2018 Red Hat, Inc. | ||
All rights reserved. This program and the accompanying materials | ||
are made available under the terms of the Eclipse Public License v1.0 | ||
which accompanies this distribution, and is available at | ||
http://www.eclipse.org/legal/epl-v10.html | ||
Contributors: | ||
Red Hat, Inc. - initial API and implementation | ||
--> | ||
<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 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>che-plugin-parent</artifactId> | ||
<groupId>org.eclipse.che.plugin</groupId> | ||
<version>6.1.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>che-plugin-camel-parent</artifactId> | ||
<packaging>pom</packaging> | ||
<name>Che Plugin :: Apache Camel :: Parent</name> | ||
<modules> | ||
<module>che-plugin-camel-server</module> | ||
</modules> | ||
</project> |
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
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