Search in sources :

Example 11 with LanguageServer

use of io.typefox.lsapi.services.LanguageServer in project che by eclipse.

the class ServerInitializerImpl method initialize.

@Override
public LanguageServer initialize(LanguageServerLauncher launcher, String projectPath) throws LanguageServerException {
    String languageId = launcher.getLanguageDescription().getLanguageId();
    synchronized (launcher) {
        LanguageServer server = languageIdToServers.get(languageId);
        if (server != null) {
            server = doInitialize(launcher, projectPath);
        } else {
            server = doInitialize(launcher, projectPath);
            languageIdToServers.put(languageId, server);
        }
        onServerInitialized(server, serversToInitResult.get(server).getInitializeResult().getCapabilities(), launcher.getLanguageDescription(), projectPath);
        return server;
    }
}
Also used : LanguageServer(io.typefox.lsapi.services.LanguageServer)

Example 12 with LanguageServer

use of io.typefox.lsapi.services.LanguageServer in project che by eclipse.

the class TextDocumentService method documentHighlight.

@POST
@Path("documentHighlight")
@Consumes(MediaType.APPLICATION_JSON)
public DocumentHighlight documentHighlight(TextDocumentPositionParamsDTO positionParams) throws LanguageServerException, InterruptedException, ExecutionException {
    positionParams.getTextDocument().setUri(prefixURI(positionParams.getTextDocument().getUri()));
    LanguageServer server = getServer(positionParams.getTextDocument().getUri());
    if (server != null) {
        return server.getTextDocumentService().documentHighlight(positionParams).get();
    }
    return null;
}
Also used : LanguageServer(io.typefox.lsapi.services.LanguageServer) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 13 with LanguageServer

use of io.typefox.lsapi.services.LanguageServer in project che by eclipse.

the class LanguageServerRegistryImpl method findServer.

@Nullable
protected LanguageServer findServer(String extension, String projectPath) throws LanguageServerException {
    ProjectExtensionKey projectKey = createProjectKey(projectPath, extension);
    for (LanguageServerLauncher launcher : extensionToLauncher.get(extension)) {
        if (!projectToServer.containsKey(projectKey)) {
            synchronized (launcher) {
                if (!projectToServer.containsKey(projectKey)) {
                    LanguageServer server = initializer.initialize(launcher, projectPath);
                    projectToServer.put(projectKey, server);
                }
            }
        }
        return projectToServer.get(projectKey);
    }
    return null;
}
Also used : LanguageServer(io.typefox.lsapi.services.LanguageServer) ProjectExtensionKey(org.eclipse.che.api.languageserver.shared.ProjectExtensionKey) LanguageServerLauncher(org.eclipse.che.api.languageserver.launcher.LanguageServerLauncher) Nullable(org.eclipse.che.commons.annotation.Nullable)

Example 14 with LanguageServer

use of io.typefox.lsapi.services.LanguageServer in project che by eclipse.

the class ServerInitializerImpl method shutdown.

@PreDestroy
protected void shutdown() {
    for (LanguageServer server : serversToInitResult.keySet()) {
        server.shutdown();
        server.exit();
    }
}
Also used : LanguageServer(io.typefox.lsapi.services.LanguageServer) PreDestroy(javax.annotation.PreDestroy)

Example 15 with LanguageServer

use of io.typefox.lsapi.services.LanguageServer in project che by eclipse.

the class ServerInitializerImpl method doInitialize.

protected LanguageServer doInitialize(LanguageServerLauncher launcher, String projectPath) throws LanguageServerException {
    String languageId = launcher.getLanguageDescription().getLanguageId();
    InitializeParamsImpl initializeParams = prepareInitializeParams(projectPath);
    LanguageServer server;
    try {
        server = launcher.launch(projectPath);
    } catch (LanguageServerException e) {
        throw new LanguageServerException("Can't initialize Language Server " + languageId + " on " + projectPath + ". " + e.getMessage(), e);
    }
    registerCallbacks(server);
    CompletableFuture<InitializeResult> completableFuture = server.initialize(initializeParams);
    try {
        InitializeResult initializeResult = completableFuture.get();
        serversToInitResult.put(server, new LanguageServerDescription(initializeResult, launcher.getLanguageDescription()));
    } catch (InterruptedException | ExecutionException e) {
        server.shutdown();
        server.exit();
        throw new LanguageServerException("Error fetching server capabilities " + languageId + ". " + e.getMessage(), e);
    }
    LOG.info("Initialized Language Server {} on project {}", languageId, projectPath);
    return server;
}
Also used : LanguageServer(io.typefox.lsapi.services.LanguageServer) LanguageServerException(org.eclipse.che.api.languageserver.exception.LanguageServerException) InitializeResult(io.typefox.lsapi.InitializeResult) InitializeParamsImpl(io.typefox.lsapi.impl.InitializeParamsImpl) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

LanguageServer (io.typefox.lsapi.services.LanguageServer)21 Consumes (javax.ws.rs.Consumes)15 POST (javax.ws.rs.POST)15 Path (javax.ws.rs.Path)15 Produces (javax.ws.rs.Produces)10 LocationImpl (io.typefox.lsapi.impl.LocationImpl)3 InitializeResult (io.typefox.lsapi.InitializeResult)2 Test (org.testng.annotations.Test)2 InitializeParams (io.typefox.lsapi.InitializeParams)1 Location (io.typefox.lsapi.Location)1 ServerCapabilities (io.typefox.lsapi.ServerCapabilities)1 InitializeParamsImpl (io.typefox.lsapi.impl.InitializeParamsImpl)1 ExecutionException (java.util.concurrent.ExecutionException)1 PreDestroy (javax.annotation.PreDestroy)1 LanguageServerException (org.eclipse.che.api.languageserver.exception.LanguageServerException)1 LanguageServerLauncher (org.eclipse.che.api.languageserver.launcher.LanguageServerLauncher)1 ProjectExtensionKey (org.eclipse.che.api.languageserver.shared.ProjectExtensionKey)1 Nullable (org.eclipse.che.commons.annotation.Nullable)1