Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClangD support for Eclipse Che #7516

Merged
merged 11 commits into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions agents/ls-clang/pom.xml
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.0.0-M5-SNAPSHOT</version>
</parent>
<artifactId>ls-clang-agent</artifactId>
<name>Language Server Clang Agent</name>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "org.eclipse.che.ls.clangd",
"version": "1.0.0",
"name": "Clangd language server",
"description": "Clangd intellisense for C/C++ projects.",
"dependencies": [],
"properties": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#
# 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"; }
command -v wget >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" wget"; }

CHE_DIR=$HOME/che
LS_DIR=${CHE_DIR}/ls-clangd
LS_LAUNCHER=${LS_DIR}/launch.sh
CLANGD_VERSION=6.0
CLANGD_BINARY=clangd-${CLANGD_VERSION}

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 packages ###
#########################
#
# Red Hat Enterprise Linux 7
############################
if echo ${LINUX_TYPE} | grep -qi "rhel"; then
test "${PACKAGES}" = "" || {
${SUDO} yum install ${PACKAGES};
}

command -v ${CLANGD_BINARY} >/dev/null 2>&1 || {
echo "LLVM / Clang ${CLANGD_VERSION} not supported on Red Hat Enterprise Linux 7.";
exit 1;
}

# Red Hat Enterprise Linux 6
############################
elif echo ${LINUX_TYPE} | grep -qi "Red Hat"; then
test "${PACKAGES}" = "" || {
${SUDO} yum install ${PACKAGES};
}

command -v ${CLANGD_BINARY} >/dev/null 2>&1 || {
echo "LLVM / Clang ${CLANGD_VERSION} not supported on Red Hat Enterprise Linux 6.";
exit 1;
}


# Ubuntu 14.04 16.04 / Linux Mint 17
####################################
elif echo ${LINUX_TYPE} | grep -qi "ubuntu"; then
test "${PACKAGES}" = "" || {
${SUDO} apt-get update;
${SUDO} apt-get -y install ${PACKAGES};
}

command -v ${CLANGD_BINARY} >/dev/null 2>&1 || {
{
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -;
# Fingerprint: 6084 F3CF 814B 57C1 CF12 EFD5 15CF 4D18 AF4F 7421
${SUDO} apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-${CLANGD_VERSION} main";
};

${SUDO} apt-get update;
${SUDO} apt-get install -y clang-tools-${CLANGD_VERSION};
${SUDO} ln -s /usr/bin/clangd-${CLANGD_VERSION} /usr/bin/clangd
}


# Debian 8
##########
elif echo ${LINUX_TYPE} | grep -qi "debian"; then
test "${PACKAGES}" = "" || {
${SUDO} apt-get update;
${SUDO} apt-get -y install ${PACKAGES};
}

command -v ${CLANGD_BINARY} >/dev/null 2>&1 || {
{
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -;
# Fingerprint: 6084 F3CF 814B 57C1 CF12 EFD5 15CF 4D18 AF4F 7421
${SUDO} apt-add-repository "deb http://apt.llvm.org/jessie/ llvm-toolchain-jessie-${CLANGD_VERSION} main";
};

${SUDO} apt-get update;
${SUDO} apt-get install -y clang-tools-${CLANGD_VERSION};
${SUDO} ln -s /usr/bin/clangd-${CLANGD_VERSION} /usr/bin/clangd
}

## Fedora 23
############
elif echo ${LINUX_TYPE} | grep -qi "fedora"; then
test "${PACKAGES}" = "" || {
${SUDO} dnf -y install ${PACKAGES};
}

command -v ${CLANGD_BINARY} >/dev/null 2>&1 || {
echo "LLVM / Clang ${CLANGD_VERSION} not supported on Fedora 23.";
exit 1;
}

## CentOS 7.1 & Oracle Linux 7.1
################################
elif echo ${LINUX_TYPE} | grep -qi "centos"; then
test "${PACKAGES}" = "" || {
${SUDO} yum -y install ${PACKAGES};
}

command -v ${CLANGD_BINARY} >/dev/null 2>&1 || {
echo "LLVM / Clang ${CLANGD_VERSION} not supported on CentOS.";
exit 1;
}

## openSUSE 13.2
################
elif echo ${LINUX_TYPE} | grep -qi "opensuse"; then
test "${PACKAGES}" = "" || {
${SUDO} zypper install -y ${PACKAGES};
}

command -v ${CLANGD_BINARY} >/dev/null 2>&1 || {
echo "LLVM / Clang ${CLANGD_VERSION} not supported on OpenSUSE 13.2.";
exit 1;
}

else
>&2 echo "Unrecognized Linux Type"
>&2 cat $FILE
exit 1
fi


#########################
### Install Clangd LS ###
#########################

touch ${LS_LAUNCHER}
chmod +x ${LS_LAUNCHER}
echo "tee -a /home/user/clangd-input.log | clangd -disable-symbolication -pretty -resource-dir=/usr/include/ -enable-snippets | tee -a /home/user/clangd-output.log" > ${LS_LAUNCHER}
1 change: 1 addition & 0 deletions agents/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@
<module>test-ls</module>
<module>ls-yaml</module>
<module>ls-camel</module>
<module>ls-clang</module>
</modules>
</project>
4 changes: 4 additions & 0 deletions assembly/assembly-wsagent-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-camel-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-clangd-lang-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-composer-server</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions assembly/assembly-wsmaster-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
<groupId>org.eclipse.che</groupId>
<artifactId>ls-camel-agent</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che</groupId>
<artifactId>ls-clang-agent</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che</groupId>
<artifactId>ls-csharp-agent</artifactId>
Expand Down
68 changes: 68 additions & 0 deletions plugins/plugin-clangd/che-plugin-clangd-lang-server/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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-clangd-parent</artifactId>
<groupId>org.eclipse.che.plugin</groupId>
<version>6.0.0-M5-SNAPSHOT</version>
</parent>
<artifactId>che-plugin-clangd-lang-server</artifactId>
<name>Che Plugin :: ClangD C/C++ :: Extension 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>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-api-project</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-inject</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-cpp-lang-server</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>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.plugin.clangd.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.api.project.server.type.ProjectTypeDef;
import org.eclipse.che.inject.DynaModule;
import org.eclipse.che.plugin.cpp.projecttype.CProjectType;
import org.eclipse.che.plugin.cpp.projecttype.CppProjectType;
import org.eclipse.plugin.clangd.languageserver.ClangDLanguageServerLauncher;

/** @author Alexander Andrienko */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like copy/pasted author?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No :)

/** @author Hanno Kolvenbach */
@DynaModule
public class ClangModule extends AbstractModule {
public static final String LANGUAGE_ID = "clangd";
private static final String[] EXTENSIONS =
new String[] {
"c", "h", "cpp", "hpp", "cc", "hh", "hxx", "cxx", "C", "H", "CPP", "HPP", "CC", "HH", "CXX",
"HXX"
};
private static final String MIME_TYPE = "text/x-cpp";

@Override
protected void configure() {
Multibinder<ProjectTypeDef> projectTypeMultibinder =
Multibinder.newSetBinder(binder(), ProjectTypeDef.class);

projectTypeMultibinder.addBinding().to(CProjectType.class);
projectTypeMultibinder.addBinding().to(CppProjectType.class);

Multibinder.newSetBinder(binder(), LanguageServerLauncher.class)
.addBinding()
.to(ClangDLanguageServerLauncher.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);
}
}
Loading