Search in sources :

Example 1 with InitializeResult

use of io.typefox.lsapi.InitializeResult in project che by eclipse.

the class LanguageServerRegistry method register.

/**
     * Registers language server description and capabilities.
     */
protected void register(String projectPath, LanguageDescription languageDescription, ServerCapabilities capabilities) {
    InitializeResult initializeResult = new InitializeResultImpl(capabilities, languageDescription);
    for (String ext : languageDescription.getFileExtensions()) {
        ProjectExtensionKey key = createProjectKey(projectPath, ext);
        projectToInitResult.put(key, initializeResult);
        if (callbackMap.containsKey(key)) {
            Callback<InitializeResult, Throwable> callback = callbackMap.remove(key);
            callback.onSuccess(initializeResult);
        }
    }
}
Also used : InitializeResult(io.typefox.lsapi.InitializeResult) ProjectExtensionKey(org.eclipse.che.api.languageserver.shared.ProjectExtensionKey) InitializeResultImpl(org.eclipse.che.api.languageserver.shared.model.impl.InitializeResultImpl)

Example 2 with InitializeResult

use of io.typefox.lsapi.InitializeResult in project che by eclipse.

the class LanguageServerEditorProvider method createEditor.

@Override
public Promise<EditorPartPresenter> createEditor(VirtualFile file) {
    if (file instanceof File) {
        File resource = (File) file;
        Promise<InitializeResult> promise = registry.getOrInitializeServer(resource.getRelatedProject().get().getPath(), resource.getExtension(), resource.getLocation().toString());
        final MessageLoader loader = loaderFactory.newLoader("Initializing Language Server for " + resource.getExtension());
        loader.show();
        return promise.thenPromise(new Function<InitializeResult, Promise<EditorPartPresenter>>() {

            @Override
            public Promise<EditorPartPresenter> apply(InitializeResult arg) throws FunctionException {
                loader.hide();
                return Promises.<EditorPartPresenter>resolve(createEditor(editorConfigurationFactory.build(arg.getCapabilities())));
            }
        });
    }
    return null;
}
Also used : Promise(org.eclipse.che.api.promises.client.Promise) InitializeResult(io.typefox.lsapi.InitializeResult) MessageLoader(org.eclipse.che.ide.ui.loaders.request.MessageLoader) FunctionException(org.eclipse.che.api.promises.client.FunctionException) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile)

Example 3 with InitializeResult

use of io.typefox.lsapi.InitializeResult 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

InitializeResult (io.typefox.lsapi.InitializeResult)3 InitializeParamsImpl (io.typefox.lsapi.impl.InitializeParamsImpl)1 LanguageServer (io.typefox.lsapi.services.LanguageServer)1 ExecutionException (java.util.concurrent.ExecutionException)1 LanguageServerException (org.eclipse.che.api.languageserver.exception.LanguageServerException)1 ProjectExtensionKey (org.eclipse.che.api.languageserver.shared.ProjectExtensionKey)1 InitializeResultImpl (org.eclipse.che.api.languageserver.shared.model.impl.InitializeResultImpl)1 FunctionException (org.eclipse.che.api.promises.client.FunctionException)1 Promise (org.eclipse.che.api.promises.client.Promise)1 File (org.eclipse.che.ide.api.resources.File)1 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)1 MessageLoader (org.eclipse.che.ide.ui.loaders.request.MessageLoader)1