Skip to content

Commit

Permalink
3656 Port Languages Server Support to lsp4j (#4765)
Browse files Browse the repository at this point in the history
* Initial import from #4160

* Added formatting for changed files

* Organize imports

* Added missing logback and removed unused dependency

* Fix plugin-languageserver compilation issue

* Move lsp4j dependency to lsp plugin
  • Loading branch information
skabashnyuk authored and Vitalii Parfonov committed Apr 19, 2017
1 parent 4f4c452 commit b016d61
Show file tree
Hide file tree
Showing 183 changed files with 3,628 additions and 3,835 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import org.eclipse.che.dto.server.DtoFactoryVisitor;
import org.eclipse.che.dto.shared.DTO;

import org.eclipse.che.dto.shared.DTOImpl;
import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
Expand Down Expand Up @@ -50,10 +49,41 @@ public class DtoGenerator {
/** Flag: A pattern we can use to search an absolute path and find the start of the package definition.") */
private String packageBase = "java.";

public static void main(String[] args) {
DtoGenerator generator = new DtoGenerator();
for (String arg : args) {
if (arg.startsWith("--dto_packages=")) {
generator.setDtoPackages(arg.substring("--dto_packages=".length()));
} else if (arg.startsWith("--gen_file_name=")) {
generator.setGenFileName(arg.substring("--gen_file_name=".length()));
} else if (arg.startsWith("--impl=")) {
generator.setImpl(arg.substring("--impl=".length()));
} else if (arg.startsWith("--package_base=")) {
generator.setPackageBase(arg.substring("--package_base=".length()));
} else {
throw new RuntimeException("Unknown flag: " + arg);
//System.exit(1);
}
}
generator.generate();
}

private static Set<URL> getClasspathForPackages(String[] packages) {
Set<URL> urls = new HashSet<>();
for (String pack : packages) {
urls.addAll(ClasspathHelper.forPackage(pack));
}
return urls;
}

public String[] getDtoPackages() {
return dtoPackages;
}

private void setDtoPackages(String packagesParam) {
setDtoPackages(packagesParam.split(","));
}

public void setDtoPackages(String[] dtoPackages) {
this.dtoPackages = new String[dtoPackages.length];
System.arraycopy(dtoPackages, 0, this.dtoPackages, 0, this.dtoPackages.length);
Expand Down Expand Up @@ -83,29 +113,6 @@ public void setPackageBase(String packageBase) {
this.packageBase = packageBase;
}

public static void main(String[] args) {
DtoGenerator generator = new DtoGenerator();
for (String arg : args) {
if (arg.startsWith("--dto_packages=")) {
generator.setDtoPackages(arg.substring("--dto_packages=".length()));
} else if (arg.startsWith("--gen_file_name=")) {
generator.setGenFileName(arg.substring("--gen_file_name=".length()));
} else if (arg.startsWith("--impl=")) {
generator.setImpl(arg.substring("--impl=".length()));
} else if (arg.startsWith("--package_base=")) {
generator.setPackageBase(arg.substring("--package_base=".length()));
} else {
System.err.println("Unknown flag: " + arg);
System.exit(1);
}
}
generator.generate();
}

private void setDtoPackages(String packagesParam) {
setDtoPackages(packagesParam.split(","));
}

public void generate() {

Set<URL> urls = getClasspathForPackages(dtoPackages);
Expand All @@ -129,8 +136,9 @@ public void generate() {

try {
DtoTemplate dtoTemplate = new DtoTemplate(packageName, className, impl);
Reflections reflection = new Reflections(new ConfigurationBuilder().setUrls(urls).setScanners(new SubTypesScanner(), new TypeAnnotationsScanner()));

Reflections reflection = new Reflections(
new ConfigurationBuilder().setUrls(urls).setScanners(new SubTypesScanner(), new TypeAnnotationsScanner()));

List<Class<?>> dtos = new ArrayList<>(reflection.getTypesAnnotatedWith(DTO.class));

// We sort alphabetically to ensure deterministic order of routing types.
Expand All @@ -145,7 +153,8 @@ public void generate() {
}

reflection = new Reflections(
new ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader()).setScanners(new SubTypesScanner(), new TypeAnnotationsScanner()));
new ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader())
.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner()));
List<Class<?>> dtosDependencies = new ArrayList<>(reflection.getTypesAnnotatedWith(DTO.class));
dtosDependencies.removeAll(dtos);

Expand All @@ -156,11 +165,11 @@ public void generate() {
for (Class impl : reflection.getSubTypesOf(clazz)) {
if (!(impl.isInterface() || urls.contains(impl.getProtectionDomain().getCodeSource().getLocation()))) {
if ("client".equals(dtoTemplate.getImplType())) {
if (isClientImpl(impl)) {
dtoTemplate.addImplementation(clazz, impl);
}
if (isClientImpl(impl)) {
dtoTemplate.addImplementation(clazz, impl);
}
} else if ("server".equals(dtoTemplate.getImplType())) {
if (isServerImpl(impl)) {
if (isServerImpl(impl)) {
dtoTemplate.addImplementation(clazz, impl);
}
}
Expand Down Expand Up @@ -197,18 +206,10 @@ private boolean isServerImpl(Class<?> impl) {
return a != null && "server".equals(a.value());
}

private static Set<URL> getClasspathForPackages(String[] packages) {
Set<URL> urls = new HashSet<>();
for (String pack : packages) {
urls.addAll(ClasspathHelper.forPackage(pack));
}
return urls;
}

private static class ClassesComparator implements Comparator<Class> {
@Override
public int compare(Class o1, Class o2) {
return o1.getName().compareTo(o2.getName());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@

import static org.eclipse.che.ide.filters.Matcher.MatcherUtil.or;


/**
* Fuzzy logic to match some string
*
* @author Evgen Vidolob
*/
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
/**
* Matcher the wey to match some string.
* S
*
* @author Evgen Vidolob
*/
public interface Matcher {

@Nullable
List<Match> match(String word, String wordToMatch);

class MatcherUtil{
public static Matcher or(final Matcher... matchers) {
class MatcherUtil {
public static Matcher or(final Matcher... matchers) {
return new Matcher() {
@Override
public List<Match> match(String word, String wordToMatch) {
Expand All @@ -42,7 +43,7 @@ public List<Match> match(String word, String wordToMatch) {
};
}

public static Matcher and(final Matcher... matchers) {
public static Matcher and(final Matcher... matchers) {
return new Matcher() {
@Override
public List<Match> match(String word, String wordToMatch) {
Expand Down
12 changes: 8 additions & 4 deletions plugins/plugin-csharp/che-plugin-csharp-lang-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
</dependency>
<dependency>
<groupId>io.typefox.lsapi</groupId>
<artifactId>io.typefox.lsapi.services</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-core</artifactId>
Expand Down Expand Up @@ -68,6 +64,14 @@
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-csharp-lang-shared</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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
*******************************************************************************/
package org.eclipse.che.plugin.csharp.languageserver;

import io.typefox.lsapi.services.json.JsonBasedLanguageServer;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.eclipse.che.api.languageserver.exception.LanguageServerException;
import org.eclipse.che.api.languageserver.launcher.LanguageServerLauncherTemplate;
import org.eclipse.che.api.languageserver.shared.model.LanguageDescription;
import org.eclipse.che.api.languageserver.shared.model.impl.LanguageDescriptionImpl;
import org.eclipse.che.commons.lang.IoUtil;
import org.eclipse.lsp4j.jsonrpc.Launcher;
import org.eclipse.lsp4j.services.LanguageClient;
import org.eclipse.lsp4j.services.LanguageServer;

import java.io.File;
import java.io.IOException;
Expand All @@ -30,26 +30,20 @@

import static java.util.Arrays.asList;


/**
* @author Evgen Vidolob
*/
@Singleton
public class CSharpLanguageServerLauncher extends LanguageServerLauncherTemplate {

private static final String LANGUAGE_ID = "csharp";
private static final String[] EXTENSIONS = new String[] {"cs", "csx"};
private static final String[] MIME_TYPES = new String[] {"text/x-csharp"};
private static final LanguageDescriptionImpl description;
private static final String[] EXTENSIONS = new String[]{"cs", "csx"};
private static final String[] MIME_TYPES = new String[]{"text/x-csharp"};
private static final LanguageDescription description;

private final Path launchScript;

static {
description = new LanguageDescriptionImpl();
description.setFileExtensions(asList(EXTENSIONS));
description.setLanguageId(LANGUAGE_ID);
description.setMimeTypes(Arrays.asList(MIME_TYPES));
}

@Inject
public CSharpLanguageServerLauncher() {
launchScript = Paths.get(System.getenv("HOME"), "che/ls-csharp/launch.sh");
Expand Down Expand Up @@ -87,10 +81,11 @@ private void restoreDependencies(String projectPath) throws LanguageServerExcept
}

@Override
protected JsonBasedLanguageServer connectToLanguageServer(Process languageServerProcess) {
JsonBasedLanguageServer languageServer = new JsonBasedLanguageServer();
languageServer.connect(languageServerProcess.getInputStream(), languageServerProcess.getOutputStream());
return languageServer;
protected LanguageServer connectToLanguageServer(final Process languageServerProcess, LanguageClient client) {
Launcher<LanguageServer> launcher = Launcher.createLauncher(client, LanguageServer.class, languageServerProcess.getInputStream(),
languageServerProcess.getOutputStream());
launcher.startListening();
return launcher.getRemoteProxy();
}

@Override
Expand All @@ -102,4 +97,11 @@ public LanguageDescription getLanguageDescription() {
public boolean isAbleToLaunch() {
return Files.exists(launchScript);
}

static {
description = new LanguageDescription();
description.setFileExtensions(asList(EXTENSIONS));
description.setLanguageId(LANGUAGE_ID);
description.setMimeTypes(Arrays.asList(MIME_TYPES));
}
}
16 changes: 8 additions & 8 deletions plugins/plugin-json/che-plugin-json-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
</dependency>
<dependency>
<groupId>io.typefox.lsapi</groupId>
<artifactId>io.typefox.lsapi</artifactId>
</dependency>
<dependency>
<groupId>io.typefox.lsapi</groupId>
<artifactId>io.typefox.lsapi.services</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-languageserver</artifactId>
Expand All @@ -52,5 +44,13 @@
<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>

This file was deleted.

Loading

0 comments on commit b016d61

Please sign in to comment.