Skip to content

Commit

Permalink
eclipse-che#1287 PHP Language Server
Browse files Browse the repository at this point in the history
Registers a language server for the PHP editor.

Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com>
  • Loading branch information
kaloyan-raev committed Aug 31, 2016
1 parent 46e006b commit 46df188
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void apply(Instance machine) throws MachineException {
}

apply(machine, AgentKeyImpl.of("org.eclipse.che.ls.json"), agentsCompleted, agentsInProgress);
apply(machine, AgentKeyImpl.of("org.eclipse.che.ls.php"), agentsCompleted, agentsInProgress);
apply(machine, AgentKeyImpl.of("org.eclipse.che.ls.csharp"), agentsCompleted, agentsInProgress);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.che.plugin.languageserver.server.launcher.CSharpLanguageServerLauncher;
import org.eclipse.che.plugin.languageserver.server.launcher.JsonLanguageServerLauncher;
import org.eclipse.che.plugin.languageserver.server.launcher.LanguageServerLauncher;
import org.eclipse.che.plugin.languageserver.server.launcher.PhpLanguageServerLauncher;
import org.eclipse.che.plugin.languageserver.server.messager.InitializeEventMessenger;
import org.eclipse.che.plugin.languageserver.server.messager.PublishDiagnosticsParamsMessenger;
import org.eclipse.che.plugin.languageserver.server.registry.LanguageServerRegistry;
Expand All @@ -33,6 +34,7 @@ public class LanguageServerModule extends AbstractModule {
@Override
protected void configure() {
Multibinder.newSetBinder(binder(), LanguageServerLauncher.class).addBinding().to(JsonLanguageServerLauncher.class);
Multibinder.newSetBinder(binder(), LanguageServerLauncher.class).addBinding().to(PhpLanguageServerLauncher.class);
Multibinder.newSetBinder(binder(), LanguageServerLauncher.class).addBinding().to(CSharpLanguageServerLauncher.class);

bind(LanguageServerRegistry.class).to(LanguageServerRegistryImpl.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* 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:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.plugin.languageserver.server.launcher;

import io.typefox.lsapi.LanguageDescription;
import io.typefox.lsapi.impl.LanguageDescriptionImpl;
import io.typefox.lsapi.services.json.JsonBasedLanguageServer;

import com.google.inject.Singleton;

import org.eclipse.che.plugin.languageserver.server.exception.LanguageServerException;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

import static java.util.Arrays.asList;

/**
* @author Evgen Vidolob
* @author Anatolii Bazko
* @author Kaloyan Raev
*/
@Singleton
public class PhpLanguageServerLauncher extends LanguageServerLauncherTemplate {

public static final String LANGUAGE_ID = "php";
public static final String[] EXTENSIONS = new String[] {"php"};
public static final String[] MIME_TYPES = new String[] {"text/x-php"};

private static final LanguageDescriptionImpl description;

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

@Override
public LanguageDescription getLanguageDescription() {
return description;
}

protected JsonBasedLanguageServer connectToLanguageServer(Process languageServerProcess) {
JsonBasedLanguageServer languageServer = new JsonBasedLanguageServer();
languageServer.connect(languageServerProcess.getInputStream(), languageServerProcess.getOutputStream());
return languageServer;
}

protected Process startLanguageServerProcess(String projectPath) throws LanguageServerException {
Path launchFile = Paths.get(System.getenv("HOME"), "che-agents/ls-php/launch.sh");

ProcessBuilder processBuilder = new ProcessBuilder(launchFile.toString());
processBuilder.redirectInput(ProcessBuilder.Redirect.PIPE);
processBuilder.redirectOutput(ProcessBuilder.Redirect.PIPE);
try {
return processBuilder.start();
} catch (IOException e) {
throw new LanguageServerException("Can't start PHP language server", e);
}
}
}

0 comments on commit 46df188

Please sign in to comment.