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

Ability to register language servers for file names instead of extensions #5107 #5156

Merged
merged 12 commits into from
Jul 3, 2017
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@

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.handlers.ProjectHandler;
import org.eclipse.che.api.project.server.type.ProjectTypeDef;
import org.eclipse.che.inject.DynaModule;
import org.eclipse.che.plugin.csharp.languageserver.CSharpLanguageServerLauncher;
import org.eclipse.che.plugin.csharp.projecttype.CSharpProjectType;
import org.eclipse.che.plugin.csharp.projecttype.CreateNetCoreProjectHandler;

import static java.util.Arrays.asList;

/**
* @author Anatolii Bazko
*/
@DynaModule
public class CSharpModule extends AbstractModule {
public static final String LANGUAGE_ID = "csharp";
private static final String[] EXTENSIONS = new String[] { "cs", "csx" };
private static final String MIME_TYPE = "text/x-csharp";

@Override
protected void configure() {
Multibinder<ProjectTypeDef> projectTypeMultibinder = Multibinder.newSetBinder(binder(), ProjectTypeDef.class);
Expand All @@ -35,5 +41,13 @@ protected void configure() {
projectHandlersMultibinder.addBinding().to(CreateNetCoreProjectHandler.class);

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

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@

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.commons.lang.IoUtil;
import org.eclipse.che.plugin.csharp.inject.CSharpModule;
import org.eclipse.lsp4j.jsonrpc.Launcher;
import org.eclipse.lsp4j.services.LanguageClient;
import org.eclipse.lsp4j.services.LanguageServer;
Expand All @@ -26,9 +25,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;

import static java.util.Arrays.asList;


/**
Expand All @@ -37,11 +33,7 @@
@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 LanguageDescription description;


private final Path launchScript;

@Inject
Expand Down Expand Up @@ -89,19 +81,13 @@ protected LanguageServer connectToLanguageServer(final Process languageServerPro
}

@Override
public LanguageDescription getLanguageDescription() {
return description;
public String getLanguageId() {
return CSharpModule.LANGUAGE_ID;
}

@Override
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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,32 @@
*******************************************************************************/
package org.eclipse.che.plugin.json.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.json.languageserver.JsonLanguageServerLauncher;
import org.eclipse.che.api.languageserver.launcher.LanguageServerLauncher;

/**
* @author Anatolii Bazko
*/
@DynaModule
public class JsonModule extends AbstractModule {
public static final String LANGUAGE_ID = "json";
private static final String[] EXTENSIONS = new String[]{"json", "bowerrc", "jshintrc", "jscsrc", "eslintrc",
"babelrc"};
private static final String MIME_TYPE = "application/json";

@Override
protected void configure() {
Multibinder.newSetBinder(binder(), LanguageServerLauncher.class).addBinding().to(JsonLanguageServerLauncher.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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.che.api.languageserver.launcher.LanguageServerLauncherTemplate;
import org.eclipse.che.api.languageserver.registry.ServerInitializerObserver;
import org.eclipse.che.api.languageserver.shared.model.LanguageDescription;
import org.eclipse.che.plugin.json.inject.JsonModule;
import org.eclipse.lsp4j.ServerCapabilities;
import org.eclipse.lsp4j.jsonrpc.Endpoint;
import org.eclipse.lsp4j.jsonrpc.Launcher;
Expand All @@ -30,33 +31,23 @@
import java.util.HashMap;
import java.util.Map;

import static java.util.Arrays.asList;

/**
* @author Evgen Vidolob
* @author Anatolii Bazko
*/
@Singleton
public class JsonLanguageServerLauncher extends LanguageServerLauncherTemplate implements ServerInitializerObserver {

private static final String LANGUAGE_ID = "json";
private static final String[] EXTENSIONS = new String[]{"json", "bowerrc", "jshintrc", "jscsrc", "eslintrc",
"babelrc"};
private static final String[] MIME_TYPES = new String[]{"application/json"};
private static final LanguageDescription description;

private final Path launchScript;

private LanguageClient client;

@Inject
public JsonLanguageServerLauncher() {
launchScript = Paths.get(System.getenv("HOME"), "che/ls-json/launch.sh");
}

@Override
public LanguageDescription getLanguageDescription() {
return description;
public String getLanguageId() {
return JsonModule.LANGUAGE_ID;
}

@Override
Expand All @@ -65,7 +56,6 @@ public boolean isAbleToLaunch() {
}

protected LanguageServer connectToLanguageServer(final Process languageServerProcess, LanguageClient client) {
this.client = client;
Launcher<LanguageServer> launcher = Launcher.createLauncher(client, LanguageServer.class,
languageServerProcess.getInputStream(),
languageServerProcess.getOutputStream());
Expand All @@ -84,13 +74,6 @@ protected Process startLanguageServerProcess(String projectPath) throws Language
}
}

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

@Override
public void onServerInitialized(LanguageServer server, ServerCapabilities capabilities, LanguageDescription languageDescription, String projectPath) {
Endpoint endpoint = ServiceEndpoints.toEndpoint(server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<version>${project.version}</version>
<executions>
<execution>
<phase>process-sources</phase>
<phase>generate-sources</phase>
Copy link
Contributor

Choose a reason for hiding this comment

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

last time we are not able to release with <phase>generate-sources</phase> I think there is a compilation issue in this phase. Why do you want to change it? Can you compile this artifact in offline mode if you local is empty or doesn't contains che-plugin-languageserver-ide artifact

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The maven generator plugin is using compiled dependencies to generate the dto classes. Since no dto's are generated from classes in the project itself, this should be fine. In the core.api.languageserver project, there used to be a precompile step in order to be able to generate from classes in the project itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Have you checked that I've asked? Because we had troubles with this last time during release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's impossible to build in offline mode when the local maven cache is empty. I can remove che stuff from the cache, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's impossible to build in offline mode when the local maven cache is empty

Ok. I wasn't really clear. I mean remove only org.eclipse.che artifacts or to be more precise che-plugin-languageserver-ide and when rebuilt che-plugin-languageserver-ide in offline mode. It's should be possible. Same situation we have when maven release plugin is releasing.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok. I've checked looks like it's working

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thx. I was having trouble building from scratch all last week (some tests failing in unrelated projects)

<goals>
<goal>generate</goal>
</goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;

import org.eclipse.che.api.promises.client.Operation;
import org.eclipse.che.api.promises.client.OperationException;
import org.eclipse.che.ide.api.action.ActionManager;
Expand All @@ -34,6 +33,7 @@
import org.eclipse.che.plugin.languageserver.ide.navigation.references.FindReferencesAction;
import org.eclipse.che.plugin.languageserver.ide.navigation.symbol.GoToSymbolAction;
import org.eclipse.che.plugin.languageserver.ide.navigation.workspace.FindSymbolAction;
import org.eclipse.che.plugin.languageserver.ide.registry.LanguageServerRegistry;
import org.eclipse.che.plugin.languageserver.ide.service.TextDocumentServiceClient;
import org.eclipse.lsp4j.DidCloseTextDocumentParams;
import org.eclipse.lsp4j.DidOpenTextDocumentParams;
Expand Down Expand Up @@ -91,20 +91,20 @@ protected void registerAction(ActionManager actionManager,
protected void registerFileEventHandler(final EventBus eventBus,
final TextDocumentServiceClient serviceClient,
final DtoFactory dtoFactory,
final LanguageServerFileTypeRegister fileTypeRegister) {
final LanguageServerRegistry lsRegistry) {
eventBus.addHandler(FileEvent.TYPE, new FileEvent.FileEventHandler() {

@Override
public void onFileOperation(final FileEvent event) {
Path location = event.getFile().getLocation();
if (location.getFileExtension() == null || !fileTypeRegister.hasLSForExtension(location.getFileExtension())) {
if (lsRegistry.getLanguageDescription(event.getFile()) == null) {
return;
}
final TextDocumentIdentifier documentId = dtoFactory.createDto(TextDocumentIdentifier.class);
documentId.setUri(location.toString());
switch (event.getOperationType()) {
case OPEN:
onOpen(event, dtoFactory, serviceClient, fileTypeRegister);
onOpen(event, dtoFactory, serviceClient, lsRegistry);
break;
case CLOSE:
onClose(documentId, dtoFactory, serviceClient);
Expand Down Expand Up @@ -136,15 +136,15 @@ private void onClose(TextDocumentIdentifier documentId,
private void onOpen(final FileEvent event,
final DtoFactory dtoFactory,
final TextDocumentServiceClient serviceClient,
final LanguageServerFileTypeRegister fileTypeRegister) {
final LanguageServerRegistry lsRegistry) {
event.getFile().getContent().then(new Operation<String>() {
@Override
public void apply(String text) throws OperationException {
TextDocumentItem documentItem = dtoFactory.createDto(TextDocumentItem.class);
documentItem.setUri(event.getFile().getLocation().toString());
documentItem.setVersion(LanguageServerEditorConfiguration.INITIAL_DOCUMENT_VERSION);
documentItem.setText(text);
documentItem.setLanguageId(fileTypeRegister.findLangId(event.getFile().getLocation().getFileExtension()));
documentItem.setLanguageId(lsRegistry.getLanguageDescription(event.getFile()).getLanguageId());

DidOpenTextDocumentParams openEvent = dtoFactory.createDto(DidOpenTextDocumentParams.class);
openEvent.setTextDocument(documentItem);
Expand Down
Loading