Skip to content

Commit

Permalink
Update lsp4J lib to newer version. (eclipse-che#5292)
Browse files Browse the repository at this point in the history
* eclipse-che#5360 Upgrade LSP4J library version to 0.2.0
Signed-off-by: Yevhen Vydolob <evidolob@codenvy.com>
  • Loading branch information
AndrienkoAleksandr authored and evidolob committed Jul 14, 2017
1 parent 1c161ca commit d14d062
Show file tree
Hide file tree
Showing 16 changed files with 208 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ else
fi


#####################
### Install C# LS ###
#####################
#######################
### Install Json LS ###
#######################

curl -s ${AGENT_BINARIES_URI} | tar xzf - -C ${LS_DIR}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.lsp4j</groupId>
<artifactId>org.eclipse.lsp4j.jsonrpc</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext.xbase.lib.gwt</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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 Down Expand Up @@ -114,9 +115,14 @@ public void onFileOperation(final FileEvent event) {
break;
}
}
// onOpen(event.getEditor(), event.getFile(), dtoFactory, serviceClient, fileTypeRegister);
});
}

// private boolean checkIsLSExist(Path location, LanguageServerFileTypeRegister fileTypeRegister){
// return !(location.getFileExtension() == null || !fileTypeRegister.hasLSForExtension(location.getFileExtension()));
// }

private void onSave(TextDocumentIdentifier documentId,
DtoFactory dtoFactory,
TextDocumentServiceClient serviceClient) {
Expand All @@ -137,22 +143,19 @@ private void onOpen(final FileEvent event,
final DtoFactory dtoFactory,
final TextDocumentServiceClient serviceClient,
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(lsRegistry.getLanguageDescription(event.getFile()).getLanguageId());

DidOpenTextDocumentParams openEvent = dtoFactory.createDto(DidOpenTextDocumentParams.class);
openEvent.setTextDocument(documentItem);
openEvent.getTextDocument().setUri(event.getFile().getLocation().toString());
openEvent.setText(text);

serviceClient.didOpen(openEvent);
}
event.getFile().getContent().then(text -> {
TextDocumentItem documentItem = dtoFactory.createDto(TextDocumentItem.class);
documentItem.setUri(event.getFile().getLocation().toString());
documentItem.setVersion(LanguageServerEditorConfiguration.INITIAL_DOCUMENT_VERSION);
documentItem.setText(text);
documentItem.setLanguageId(lsRegistry.getLanguageDescription(event.getFile()).getLanguageId());

DidOpenTextDocumentParams openEvent = dtoFactory.createDto(DidOpenTextDocumentParams.class);
openEvent.setTextDocument(documentItem);
openEvent.getTextDocument().setUri(event.getFile().getLocation().toString());
openEvent.setText(text);

serviceClient.didOpen(openEvent);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.eclipse.che.plugin.languageserver.ide.editor.sync.TextDocumentSynchronizeFactory;
import org.eclipse.lsp4j.ServerCapabilities;
import org.eclipse.lsp4j.TextDocumentSyncKind;
import org.eclipse.lsp4j.TextDocumentSyncOptions;
import org.eclipse.lsp4j.jsonrpc.messages.Either;

/**
* Responsible for document synchronization
Expand All @@ -38,7 +40,14 @@ public class LanguageServerReconcileStrategy implements ReconcilingStrategy {
public LanguageServerReconcileStrategy(TextDocumentSynchronizeFactory synchronizeFactory,
@Assisted ServerCapabilities serverCapabilities) {

TextDocumentSyncKind documentSync = serverCapabilities.getTextDocumentSync();
Either<TextDocumentSyncKind, TextDocumentSyncOptions> sync = serverCapabilities.getTextDocumentSync();
TextDocumentSyncKind documentSync;
if(sync.isLeft()){
documentSync = sync.getLeft();
} else {
documentSync = sync.getRight().getChange();
}

synchronize = synchronizeFactory.getSynchronize(documentSync);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
import com.google.inject.assistedinject.Assisted;

import org.eclipse.che.api.languageserver.shared.model.ExtendedCompletionItem;
import org.eclipse.che.api.languageserver.shared.model.ExtendedCompletionList;
import org.eclipse.che.api.promises.client.Operation;
import org.eclipse.che.api.promises.client.OperationException;
import org.eclipse.che.api.promises.client.PromiseError;
import org.eclipse.che.ide.api.editor.codeassist.CodeAssistCallback;
import org.eclipse.che.ide.api.editor.codeassist.CodeAssistProcessor;
import org.eclipse.che.ide.api.editor.codeassist.CompletionProposal;
Expand Down Expand Up @@ -81,17 +77,11 @@ public void computeCompletionProposals(TextEditor editor, final int offset, fina
// no need to send new completion request
computeProposals(currentWord, offset - latestCompletionResult.getOffset(), callback);
} else {
documentServiceClient.completion(documentPosition).then(new Operation<ExtendedCompletionList>() {
@Override
public void apply(ExtendedCompletionList list) throws OperationException {
latestCompletionResult.update(documentId, offset, currentWord, list);
computeProposals(currentWord, 0, callback);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
lastErrorMessage = error.getMessage();
}
documentServiceClient.completion(documentPosition).then(list -> {
latestCompletionResult.update(documentId, offset, currentWord, list);
computeProposals(currentWord, 0, callback);
}).catchError(error -> {
lastErrorMessage = error.getMessage();
});
}
}
Expand Down Expand Up @@ -133,7 +123,7 @@ private List<Match> filter(String word, String label, String filterText) {
// return the highlights based on the label
List<Match> highlights = fuzzyMatches.fuzzyMatch(word, label);
// return empty list of highlights if nothing matches the label
return (highlights == null) ? new ArrayList<Match>() : highlights;
return (highlights == null) ? new ArrayList<>() : highlights;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class LatestCompletionResult {
private TextDocumentIdentifier documentId;
private int offset;
private String word;
private ExtendedCompletionList completionList;
private ExtendedCompletionList completionList;

/**
* Returns the identifier of document used to compute the latest completion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.eclipse.che.api.promises.client.Function;
import org.eclipse.che.api.promises.client.FunctionException;
import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.api.promises.client.js.JsPromise;
import org.eclipse.che.ide.api.editor.EditorAgent;
Expand All @@ -30,7 +28,9 @@
import org.eclipse.che.plugin.languageserver.ide.service.TextDocumentServiceClient;
import org.eclipse.che.plugin.languageserver.ide.util.DtoBuildHelper;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.MarkedString;
import org.eclipse.lsp4j.TextDocumentPositionParams;
import org.eclipse.lsp4j.jsonrpc.messages.Either;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -76,31 +76,33 @@ public JsPromise<OrionHoverOverlay> computeHover(OrionHoverContextOverlay contex
TextDocumentPositionParams paramsDTO = helper.createTDPP(document, context.getOffset());

Promise<Hover> promise = client.hover(paramsDTO);
Promise<OrionHoverOverlay> then = promise.then(new Function<Hover, OrionHoverOverlay>() {
@Override
public OrionHoverOverlay apply(Hover arg) throws FunctionException {
OrionHoverOverlay hover = OrionHoverOverlay.create();
hover.setType("markdown");
String content = renderContent(arg);
// do not show hover with only white spaces
if (StringUtils.isNullOrWhitespace(content)) {
return null;
}
hover.setContent(content);

return hover;
Promise<OrionHoverOverlay> then = promise.then((Hover arg) -> {
OrionHoverOverlay hover = OrionHoverOverlay.create();
hover.setType("markdown");
String content = renderContent(arg);
// do not show hover with only white spaces
if (StringUtils.isNullOrWhitespace(content)) {
return null;
}
hover.setContent(content);

private String renderContent(Hover hover) {
List<String> contents = new ArrayList<String>();
for (String dto : hover.getContents()) {
// plain markdown text
contents.add(dto);
}
return Joiner.on("\n\n").join(contents);
}
return hover;
});
return (JsPromise<OrionHoverOverlay>)then;

}

private String renderContent(Hover hover) {
List<String> contents = new ArrayList<>();
for (Either<String, MarkedString> dto : hover.getContents()) {
if (dto.isLeft()) {
// plain markdown text
contents.add(dto.getLeft());
} else {
contents.add(dto.getRight().getLanguage());
contents.add(dto.getRight().getValue());
}
}
return Joiner.on("\n\n").join(contents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static Type getRightDisjointType(Type type) {
private static Type getDisjointType(Type type, int index) {
if (type instanceof ParameterizedType) {
final ParameterizedType parameterizedType = (ParameterizedType)type;
return parameterizedType.getActualTypeArguments()[0];
return parameterizedType.getActualTypeArguments()[index];
}
if (type instanceof Class) {
final Class<?> cls = (Class<?>)type;
Expand Down
4 changes: 4 additions & 0 deletions wsagent/che-core-api-languageserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
<groupId>org.eclipse.lsp4j</groupId>
<artifactId>org.eclipse.lsp4j</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.lsp4j</groupId>
<artifactId>org.eclipse.lsp4j.jsonrpc</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface LanguageServerLauncher {

/**
* Initializes and starts a language server.
*
*
* @param projectPath
* absolute path to the project
* @param client
Expand All @@ -36,7 +36,7 @@ public interface LanguageServerLauncher {
LanguageServerDescription getDescription();

/**
* Indicates if language server is installed and is ready to be started.
* Indicates if language server is installed and is ready to be started.
*/
boolean isAbleToLaunch();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.eclipse.che.api.core.notification.EventService;
import org.eclipse.che.api.languageserver.shared.model.ExtendedPublishDiagnosticsParams;
import org.eclipse.lsp4j.MessageActionItem;
import org.eclipse.lsp4j.MessageParams;
import org.eclipse.lsp4j.PublishDiagnosticsParams;
import org.eclipse.lsp4j.ShowMessageRequestParams;
Expand Down Expand Up @@ -44,7 +45,7 @@ public void telemetryEvent(Object object) {
}

@Override
public CompletableFuture<Void> showMessageRequest(ShowMessageRequestParams requestParams) {
public CompletableFuture<MessageActionItem> showMessageRequest(ShowMessageRequestParams requestParams) {
return CompletableFuture.completedFuture(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
package org.eclipse.che.api.languageserver.registry;

import com.google.common.base.Function;

import org.eclipse.lsp4j.CodeLensOptions;
import org.eclipse.lsp4j.CompletionOptions;
import org.eclipse.lsp4j.DocumentOnTypeFormattingOptions;
import org.eclipse.lsp4j.ServerCapabilities;
import org.eclipse.lsp4j.SignatureHelpOptions;
import org.eclipse.lsp4j.TextDocumentSyncKind;
import org.eclipse.lsp4j.TextDocumentSyncOptions;
import org.eclipse.lsp4j.jsonrpc.messages.Either;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -113,11 +116,13 @@ public SignatureHelpOptions getSignatureHelpProvider() {
return result;
}

public TextDocumentSyncKind getTextDocumentSync() {
public Either<TextDocumentSyncKind, TextDocumentSyncOptions> getTextDocumentSync() {
return mergeTextDocumentSync(left.getTextDocumentSync(), right.getTextDocumentSync());
}

private TextDocumentSyncKind mergeTextDocumentSync(TextDocumentSyncKind left, TextDocumentSyncKind right) {
private Either<TextDocumentSyncKind, TextDocumentSyncOptions> mergeTextDocumentSync(
Either<TextDocumentSyncKind, TextDocumentSyncOptions> left,
Either<TextDocumentSyncKind, TextDocumentSyncOptions> right) {
if (left == null) {
return right;
}
Expand All @@ -127,16 +132,42 @@ private TextDocumentSyncKind mergeTextDocumentSync(TextDocumentSyncKind left, Te
if (left.equals(right)) {
return left;
}
if (left == TextDocumentSyncKind.Full) {

if (left.isLeft() && left.getLeft() == TextDocumentSyncKind.Full) {
return left;
}
if (left == TextDocumentSyncKind.Incremental) {
if (right == TextDocumentSyncKind.Full) {
return TextDocumentSyncKind.Full;

if (left.isLeft() && left.getLeft() == TextDocumentSyncKind.Incremental) {
if (right.isLeft() && right.getLeft() == TextDocumentSyncKind.Full) {
return right;
} else {
return TextDocumentSyncKind.Incremental;
return left;
}
}

if (left.isRight() && right.isRight()) {
TextDocumentSyncOptions leftRight = left.getRight();
TextDocumentSyncOptions rightRight = right.getRight();
if (leftRight.getChange() == TextDocumentSyncKind.Full) {
return left;
}

if (leftRight.getChange() == TextDocumentSyncKind.Incremental) {
if (rightRight.getChange() == TextDocumentSyncKind.Full) {
return right;
} else {
return left;
}
}
}

if (left.isLeft() && right.isRight()) {
return right;
}

if (left.isRight() && right.isLeft()) {
return left;
}
return right;
}

Expand Down
Loading

0 comments on commit d14d062

Please sign in to comment.