Skip to content

Commit

Permalink
#1800 use oun LanguageDescription class instead of removed from ls-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgen Vidolob committed Sep 8, 2016
1 parent 8a2e7b7 commit e0e6a39
Show file tree
Hide file tree
Showing 22 changed files with 216 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package org.eclipse.che.plugin.languageserver.ide.registry;

import io.typefox.lsapi.InitializeResult;
import io.typefox.lsapi.LanguageDescription;
import io.typefox.lsapi.ServerCapabilities;

import com.google.gwt.core.client.Callback;
Expand Down Expand Up @@ -41,6 +40,7 @@
import org.eclipse.che.plugin.languageserver.shared.ProjectExtensionKey;
import org.eclipse.che.plugin.languageserver.shared.event.LanguageServerInitializeEventDto;
import org.eclipse.che.plugin.languageserver.shared.lsapi.InitializeResultDTO;
import org.eclipse.che.plugin.languageserver.shared.model.LanguageDescription;
import org.eclipse.che.plugin.languageserver.shared.model.impl.InitializeResultImpl;

import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import io.typefox.lsapi.CompletionOptions;
import io.typefox.lsapi.DocumentOnTypeFormattingOptions;
import io.typefox.lsapi.InitializeResult;
import io.typefox.lsapi.LanguageDescription;
import io.typefox.lsapi.ServerCapabilities;
import io.typefox.lsapi.SignatureHelpOptions;

Expand All @@ -27,9 +26,7 @@
import org.eclipse.che.plugin.languageserver.shared.lsapi.LanguageDescriptionDTO;
import org.eclipse.che.plugin.languageserver.shared.lsapi.ServerCapabilitiesDTO;
import org.eclipse.che.plugin.languageserver.shared.lsapi.SignatureHelpOptionsDTO;

import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.che.plugin.languageserver.shared.model.LanguageDescription;

import static org.eclipse.che.dto.server.DtoFactory.newDto;

Expand All @@ -39,14 +36,14 @@
public class DtoConverter {

public static InitializeResultDTO asDto(InitializeResult initializeResult) {
List<LanguageDescriptionDTO> languageDescriptionDTOs = initializeResult.getSupportedLanguages()
.stream()
.map(DtoConverter::asDto)
.collect(Collectors.toList());
// List<LanguageDescriptionDTO> languageDescriptionDTOs = initializeResult.getSupportedLanguages()
// .stream()
// .map(DtoConverter::asDto)
// .collect(Collectors.toList());

InitializeResultDTO initializeResultDTO = newDto(InitializeResultDTO.class);
initializeResultDTO.setCapabilities(asDto(initializeResult.getCapabilities()));
initializeResultDTO.setSupportedLanguages(languageDescriptionDTOs);
// initializeResultDTO.setSupportedLanguages(languageDescriptionDTOs);
return initializeResultDTO;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
*******************************************************************************/
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.apache.commons.io.IOUtils;
import org.eclipse.che.plugin.languageserver.server.exception.LanguageServerException;
import org.eclipse.che.plugin.languageserver.shared.model.LanguageDescription;
import org.eclipse.che.plugin.languageserver.shared.model.impl.LanguageDescriptionImpl;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
*******************************************************************************/
package org.eclipse.che.plugin.languageserver.server.launcher;

import io.typefox.lsapi.LanguageDescription;
import io.typefox.lsapi.services.LanguageServer;
import io.typefox.lsapi.services.json.JsonBasedLanguageServer;

import com.google.inject.Singleton;

import org.eclipse.che.plugin.languageserver.shared.model.LanguageDescription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
*******************************************************************************/
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 org.eclipse.che.plugin.languageserver.shared.model.LanguageDescription;
import org.eclipse.che.plugin.languageserver.shared.model.impl.LanguageDescriptionImpl;

import java.io.IOException;
import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
*******************************************************************************/
package org.eclipse.che.plugin.languageserver.server.launcher;

import io.typefox.lsapi.LanguageDescription;
import io.typefox.lsapi.services.LanguageServer;

import org.eclipse.che.plugin.languageserver.server.exception.LanguageServerException;
import org.eclipse.che.plugin.languageserver.shared.model.LanguageDescription;

/**
* @author Anatoliy Bazko
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
*******************************************************************************/
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 org.eclipse.che.plugin.languageserver.shared.model.LanguageDescription;
import org.eclipse.che.plugin.languageserver.shared.model.impl.LanguageDescriptionImpl;

import java.io.IOException;
import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.che.plugin.languageserver.server.messager;

import io.typefox.lsapi.LanguageDescription;
import io.typefox.lsapi.ServerCapabilities;
import io.typefox.lsapi.services.LanguageServer;

Expand All @@ -20,6 +19,7 @@
import org.eclipse.che.plugin.languageserver.server.registry.ServerInitializer;
import org.eclipse.che.plugin.languageserver.server.registry.ServerInitializerObserver;
import org.eclipse.che.plugin.languageserver.shared.event.LanguageServerInitializeEventDto;
import org.eclipse.che.plugin.languageserver.shared.model.LanguageDescription;
import org.everrest.websockets.WSConnectionContext;
import org.everrest.websockets.message.ChannelBroadcastMessage;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*******************************************************************************
* 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.registry;

import io.typefox.lsapi.InitializeResult;

import org.eclipse.che.plugin.languageserver.shared.model.LanguageDescription;

/**
* Simple container for {@link InitializeResult} and {@link LanguageDescription}
*
* @author Evgen Vidolob
*/
public class LanguageServerDescription {
private final InitializeResult initializeResult;
private final LanguageDescription languageDescription;

public LanguageServerDescription(InitializeResult initializeResult,
LanguageDescription languageDescription) {
this.initializeResult = initializeResult;
this.languageDescription = languageDescription;
}

public InitializeResult getInitializeResult() {
return initializeResult;
}

public LanguageDescription getLanguageDescription() {
return languageDescription;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
*******************************************************************************/
package org.eclipse.che.plugin.languageserver.server.registry;

import io.typefox.lsapi.InitializeResult;
import io.typefox.lsapi.LanguageDescription;
import io.typefox.lsapi.services.LanguageServer;

import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.plugin.languageserver.server.exception.LanguageServerException;
import org.eclipse.che.plugin.languageserver.shared.ProjectExtensionKey;
import org.eclipse.che.plugin.languageserver.shared.model.LanguageDescription;

import java.util.List;
import java.util.Map;
Expand All @@ -36,5 +35,5 @@ public interface LanguageServerRegistry {
*/
List<LanguageDescription> getSupportedLanguages();

Map<ProjectExtensionKey, InitializeResult> getInitializedLanguages();
Map<ProjectExtensionKey, LanguageServerDescription> getInitializedLanguages();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.che.plugin.languageserver.server.registry;

import io.typefox.lsapi.InitializeResult;
import io.typefox.lsapi.LanguageDescription;
import io.typefox.lsapi.ServerCapabilities;
import io.typefox.lsapi.services.LanguageServer;

Expand All @@ -26,6 +24,7 @@
import org.eclipse.che.plugin.languageserver.server.exception.LanguageServerException;
import org.eclipse.che.plugin.languageserver.server.launcher.LanguageServerLauncher;
import org.eclipse.che.plugin.languageserver.shared.ProjectExtensionKey;
import org.eclipse.che.plugin.languageserver.shared.model.LanguageDescription;

import java.net.URI;
import java.util.ArrayList;
Expand Down Expand Up @@ -114,8 +113,8 @@ public List<LanguageDescription> getSupportedLanguages() {
}

@Override
public Map<ProjectExtensionKey, InitializeResult> getInitializedLanguages() {
Map<LanguageServer, InitializeResult> initializedServers = initializer.getInitializedServers();
public Map<ProjectExtensionKey, LanguageServerDescription> getInitializedLanguages() {
Map<LanguageServer, LanguageServerDescription> initializedServers = initializer.getInitializedServers();
return projectToServer.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> initializedServers.get(e.getValue())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

package org.eclipse.che.plugin.languageserver.server.registry;

import io.typefox.lsapi.InitializeResult;
import io.typefox.lsapi.services.LanguageServer;

import org.eclipse.che.plugin.languageserver.server.exception.LanguageServerException;
Expand All @@ -35,5 +34,5 @@ public interface ServerInitializer extends ServerInitializerObservable {
/**
* Returns initialized servers.
*/
Map<LanguageServer, InitializeResult> getInitializedServers();
Map<LanguageServer, LanguageServerDescription> getInitializedServers();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
package org.eclipse.che.plugin.languageserver.server.registry;

import io.typefox.lsapi.InitializeResult;
import io.typefox.lsapi.LanguageDescription;
import io.typefox.lsapi.ServerCapabilities;
import io.typefox.lsapi.impl.InitializeParamsImpl;
import io.typefox.lsapi.impl.InitializeResultImpl;
import io.typefox.lsapi.impl.LanguageDescriptionImpl;
import io.typefox.lsapi.services.LanguageServer;

import com.google.inject.Inject;
Expand All @@ -26,6 +23,7 @@
import org.eclipse.che.plugin.languageserver.server.exception.LanguageServerException;
import org.eclipse.che.plugin.languageserver.server.launcher.LanguageServerLauncher;
import org.eclipse.che.plugin.languageserver.server.messager.PublishDiagnosticsParamsMessenger;
import org.eclipse.che.plugin.languageserver.shared.model.LanguageDescription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -53,7 +51,7 @@ public class ServerInitializerImpl implements ServerInitializer {
private final PublishDiagnosticsParamsMessenger publishDiagnosticsParamsMessenger;

private final ConcurrentHashMap<String, LanguageServer> languageIdToServers;
private final ConcurrentHashMap<LanguageServer, InitializeResult> serversToInitResult;
private final ConcurrentHashMap<LanguageServer, LanguageServerDescription> serversToInitResult;

@Inject
public ServerInitializerImpl(PublishDiagnosticsParamsMessenger publishDiagnosticsParamsMessenger) {
Expand Down Expand Up @@ -95,26 +93,26 @@ public LanguageServer initialize(LanguageServerLauncher launcher, String project
synchronized (launcher) {
LanguageServer server = languageIdToServers.get(languageId);
if (server != null) {
InitializeResult initializeResult = serversToInitResult.get(server);
// LanguageServerDescription initializeResult = serversToInitResult.get(server);
// if (!initializeResult.getCapabilities().isMultiplyProjectsProvider()) {
server = doInitialize(launcher, projectPath);
// }
} else {
server = doInitialize(launcher, projectPath);
languageIdToServers.put(languageId, server);
}
InitializeResult initializeResult = serversToInitResult.get(server);
if (initializeResult instanceof InitializeResultImpl) {
((InitializeResultImpl)initializeResult)
.setSupportedLanguages(Collections.singletonList((LanguageDescriptionImpl)launcher.getLanguageDescription()));
}
onServerInitialized(server, serversToInitResult.get(server).getCapabilities(), launcher.getLanguageDescription(), projectPath);
// InitializeResult initializeResult = serversToInitResult.get(server);
// if (initializeResult instanceof InitializeResultImpl) {
// ((InitializeResultImpl)initializeResult)
// .setSupportedLanguages(Collections.singletonList((LanguageDescriptionImpl)launcher.getLanguageDescription()));
// }
onServerInitialized(server, serversToInitResult.get(server).getInitializeResult().getCapabilities(), launcher.getLanguageDescription(), projectPath);
return server;
}
}

@Override
public Map<LanguageServer, InitializeResult> getInitializedServers() {
public Map<LanguageServer, LanguageServerDescription> getInitializedServers() {
return Collections.unmodifiableMap(serversToInitResult);
}

Expand All @@ -134,7 +132,7 @@ protected LanguageServer doInitialize(LanguageServerLauncher launcher, String pr
CompletableFuture<InitializeResult> completableFuture = server.initialize(initializeParams);
try {
InitializeResult initializeResult = completableFuture.get();
serversToInitResult.put(server, initializeResult);
serversToInitResult.put(server, new LanguageServerDescription(initializeResult, launcher.getLanguageDescription()));
} catch (InterruptedException | ExecutionException e) {
server.shutdown();
server.exit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@

package org.eclipse.che.plugin.languageserver.server.registry;

import io.typefox.lsapi.LanguageDescription;
import io.typefox.lsapi.ServerCapabilities;
import io.typefox.lsapi.services.LanguageServer;

import org.eclipse.che.plugin.languageserver.shared.model.LanguageDescription;

/**
* @author Anatoliy Bazko
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
*******************************************************************************/
package org.eclipse.che.plugin.languageserver.server.service;

import io.typefox.lsapi.InitializeResult;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.eclipse.che.plugin.languageserver.server.DtoConverter;
import org.eclipse.che.plugin.languageserver.server.exception.LanguageServerException;
import org.eclipse.che.plugin.languageserver.server.registry.LanguageServerDescription;
import org.eclipse.che.plugin.languageserver.server.registry.LanguageServerRegistry;
import org.eclipse.che.plugin.languageserver.server.registry.LanguageServerRegistryImpl;
import org.eclipse.che.plugin.languageserver.shared.ProjectExtensionKey;
Expand All @@ -29,6 +28,7 @@
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.Collections;
import java.util.List;

import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -65,18 +65,15 @@ public List<InitializeResultDTO> getRegisteredLanguages() {
.stream()
.map(entry -> {
ProjectExtensionKey projectExtensionKey = entry.getKey();
InitializeResult initializeResult = entry.getValue();
LanguageServerDescription serverDescription = entry.getValue();

List<LanguageDescriptionDTO> languageDescriptionDTOs
= initializeResult.getSupportedLanguages()
.stream()
.map(DtoConverter::asDto)
.collect(toList());
= Collections.singletonList(asDto(serverDescription.getLanguageDescription()));

InitializeResultDTO dto = newDto(InitializeResultDTO.class);
dto.setProject(projectExtensionKey.getProject().substring(LanguageServerRegistryImpl.PROJECT_FOLDER_PATH.length()));
dto.setSupportedLanguages(languageDescriptionDTOs);
dto.setCapabilities(asDto(initializeResult.getCapabilities()));
dto.setCapabilities(asDto(serverDescription.getInitializeResult().getCapabilities()));
return dto;
})
.collect(toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

import io.typefox.lsapi.InitializeParams;
import io.typefox.lsapi.InitializeResult;
import io.typefox.lsapi.LanguageDescription;
import io.typefox.lsapi.ServerCapabilities;
import io.typefox.lsapi.services.LanguageServer;
import io.typefox.lsapi.services.TextDocumentService;
import io.typefox.lsapi.services.WindowService;

import org.eclipse.che.plugin.languageserver.server.launcher.JsonLanguageServerLauncher;
import org.eclipse.che.plugin.languageserver.server.launcher.LanguageServerLauncher;
import org.eclipse.che.plugin.languageserver.shared.model.LanguageDescription;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.annotations.BeforeMethod;
Expand Down
Loading

0 comments on commit e0e6a39

Please sign in to comment.