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

[WIP] Several improvements to the way remote language servers may be configured through workspace configuration #9387

Merged
merged 12 commits into from
May 18, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ public void withConsumer(Consumer<String> consumer) {
LOGGER.debug("Configuring incoming request binary: consumer for method: " + method);
handlerManager.registerNoneToNone(method, consumer);
}

public void withRunnable(Runnable runnable) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Never called.

Copy link
Author

Choose a reason for hiding this comment

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

Agree

withConsumer(s -> runnable.run());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerManager;
import org.slf4j.Logger;

Expand Down Expand Up @@ -58,4 +59,13 @@ public void withFunction(Function<String, List<R>> function) {

handlerManager.registerNoneToMany(method, rClass, function);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

This is never called. Remove!

Copy link
Author

Choose a reason for hiding this comment

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

Meaningless comment.

/**
* Define a supplier to be applied
*
* @param supplier supplier
*/
public void withSupplier(Supplier<List<R>> supplier) {
withFunction(s -> supplier.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static org.slf4j.LoggerFactory.getLogger;

import java.util.function.Function;
import java.util.function.Supplier;
import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerManager;
import org.slf4j.Logger;

Expand Down Expand Up @@ -56,4 +57,13 @@ public void withFunction(Function<String, R> function) {

handlerManager.registerNoneToOne(method, rClass, function);
}

/**
* Define a supplier to be applied
*
* @param supplier supplier
*/
public void withSupplier(Supplier<R> supplier) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this method is ever called.

Copy link
Author

Choose a reason for hiding this comment

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

Agree

withFunction(s -> supplier.get());
}
}
4 changes: 4 additions & 0 deletions ide/che-core-ide-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-gwt</artifactId>
</dependency>
<dependency>
<groupId>org.vectomatic</groupId>
<artifactId>lib-gwt-svg</artifactId>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ public class FileType {

private String namePattern;

public void setImage(SVGResource image) {
Copy link
Contributor

Choose a reason for hiding this comment

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

These are never called.

Copy link
Author

@dkulieshov dkulieshov Apr 27, 2018

Choose a reason for hiding this comment

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

setNamePattern is called, the other two are added for consistency.

this.image = image;
}

public void setExtension(String extension) {
this.extension = extension;
}

public void setNamePattern(String namePattern) {
this.namePattern = namePattern;
}

public FileType(SVGResource image, String extension) {
this(image, extension, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ public interface FileTypeRegistry {
* @return file type or default file type if no file type's name pattern matches the given file
* name
*/
FileType getFileTypeByNamePattern(String name);
FileType getFileTypeByFileName(String name);
Copy link
Contributor

Choose a reason for hiding this comment

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

Gratuitous rename, if anything should have fixed the javadoc.

Copy link
Author

Choose a reason for hiding this comment

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

Javadoc is correct, method name was inappropriate

Copy link
Contributor

Choose a reason for hiding this comment

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

So it's not a pattern?

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public List<FileType> getRegisteredFileTypes() {

@Override
public FileType getFileTypeByFile(VirtualFile file) {
FileType fileType = getFileTypeByNamePattern(file.getName());
FileType fileType = getFileTypeByFileName(file.getName());
if (fileType == unknownFileType) {
fileType = getFileTypeByExtension(getFileExtension(file.getName()));
}
Expand All @@ -72,7 +72,7 @@ public FileType getFileTypeByExtension(String extension) {
}

@Override
public FileType getFileTypeByNamePattern(String name) {
public FileType getFileTypeByFileName(String name) {
if (!Strings.isNullOrEmpty(name)) {
for (FileType type : fileTypes) {
if (type.getNamePattern() != null) {
Expand Down
20 changes: 4 additions & 16 deletions plugins/plugin-camel/che-plugin-camel-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<findbugs.failonerror>false</findbugs.failonerror>
</properties>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
Expand All @@ -36,29 +40,13 @@
<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>
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,23 @@
*/
package org.eclipse.che.plugin.camel.server.inject;

import static java.util.Arrays.asList;
import static com.google.inject.multibindings.MapBinder.newMapBinder;

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.languageserver.LanguageServerConfig;
import org.eclipse.che.inject.DynaModule;
import org.eclipse.che.plugin.camel.server.languageserver.CamelLanguageServerLauncher;
import org.eclipse.che.plugin.camel.server.languageserver.CamelLanguageServerConfig;

/** 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);
newMapBinder(binder(), String.class, LanguageServerConfig.class)
.addBinding("org.eclipse.che.plugin.camel.server.languageserver")
.to(CamelLanguageServerConfig.class)
.asEagerSingleton();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.eclipse.che.api.languageserver.DefaultInstanceProvider;
import org.eclipse.che.api.languageserver.LanguageServerConfig;
import org.eclipse.che.api.languageserver.ProcessCommunicationProvider;
import org.eclipse.che.plugin.camel.server.inject.CamelModule;

/** Launcher for Apache Camel Language Server */
@Singleton
public class CamelLanguageServerConfig implements LanguageServerConfig {
private static final String REGEX = ".*\\.(xml)";

private final Path launchScript;

@Inject
public CamelLanguageServerConfig() {

this.launchScript = Paths.get(System.getenv("HOME"), "che/ls-camel/launch.sh");
}

@Override
public RegexProvider getRegexpProvider() {
return new RegexProvider() {
@Override
public Map<String, String> getLanguageRegexes() {
return ImmutableMap.of(CamelModule.LANGUAGE_ID, REGEX);
}

@Override
public Set<String> getFileWatchPatterns() {
return ImmutableSet.of();
}
};
}

@Override
public CommunicationProvider getCommunicationProvider() {
ProcessBuilder processBuilder = new ProcessBuilder(launchScript.toString());
processBuilder.redirectInput(ProcessBuilder.Redirect.PIPE);
processBuilder.redirectOutput(ProcessBuilder.Redirect.PIPE);

return new ProcessCommunicationProvider(processBuilder, CamelModule.LANGUAGE_ID);
}

@Override
public InstanceProvider getInstanceProvider() {
return DefaultInstanceProvider.getInstance();
}

@Override
public InstallerStatusProvider getInstallerStatusProvider() {
return new InstallerStatusProvider() {
@Override
public boolean isSuccessfullyInstalled() {
return launchScript.toFile().exists();
}

@Override
public String getCause() {
return isSuccessfullyInstalled() ? null : "Launch script file does not exist";
}
};
}
}

This file was deleted.

Loading