From 0802d4992dba5474a367a218a48f9620f2133f80 Mon Sep 17 00:00:00 2001 From: Ryan Dunn Date: Sun, 23 Feb 2020 15:58:41 -0500 Subject: [PATCH] Adding ResourceOperation toExpectation and fixing NPE on WorkspaceEdit Signed-off-by: Ryan Dunn --- .../testing/AbstractLanguageServerTest.xtend | 24 ++++-- .../testing/AbstractLanguageServerTest.java | 74 ++++++++++++++++--- 2 files changed, 81 insertions(+), 17 deletions(-) diff --git a/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/AbstractLanguageServerTest.xtend b/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/AbstractLanguageServerTest.xtend index e6216f4c6..927d1314e 100644 --- a/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/AbstractLanguageServerTest.xtend +++ b/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/AbstractLanguageServerTest.xtend @@ -52,6 +52,7 @@ import org.eclipse.lsp4j.PublishDiagnosticsParams import org.eclipse.lsp4j.Range import org.eclipse.lsp4j.ReferenceContext import org.eclipse.lsp4j.ReferenceParams +import org.eclipse.lsp4j.ResourceOperation import org.eclipse.lsp4j.SemanticHighlightingInformation import org.eclipse.lsp4j.SemanticHighlightingParams import org.eclipse.lsp4j.SignatureHelp @@ -63,6 +64,7 @@ import org.eclipse.lsp4j.TextDocumentItem import org.eclipse.lsp4j.TextEdit import org.eclipse.lsp4j.VersionedTextDocumentIdentifier import org.eclipse.lsp4j.WorkspaceEdit +import org.eclipse.lsp4j.WorkspaceFolder import org.eclipse.lsp4j.WorkspaceSymbolParams import org.eclipse.lsp4j.jsonrpc.Endpoint import org.eclipse.lsp4j.jsonrpc.messages.Either @@ -89,7 +91,6 @@ import org.junit.jupiter.api.BeforeEach import static extension org.eclipse.lsp4j.util.Ranges.containsRange import static extension org.eclipse.xtext.util.Strings.* -import org.eclipse.lsp4j.WorkspaceFolder /** * @author Sven Efftinge - Initial contribution and API @@ -430,11 +431,24 @@ abstract class AbstractLanguageServerTest implements Endpoint { protected dispatch def String toExpectation(WorkspaceEdit it) ''' changes : - «FOR entry : changes.entrySet» - «URI.createURI(entry.key).lastSegment» : «entry.value.toExpectation» - «ENDFOR» + «IF changes !== null» + «FOR entry : changes.entrySet» + «URI.createURI(entry.key).lastSegment» : «entry.value.toExpectation» + «ENDFOR» + «ENDIF» documentChanges : - «documentChanges.toExpectation» + «IF !documentChanges.nullOrEmpty» + «FOR entry: documentChanges.filter[isLeft].map[getLeft]» + «entry.toExpectation» + «ENDFOR» + «FOR entry: documentChanges.filter[isRight].map[getRight]» + «entry.toExpectation» + «ENDFOR» + «ENDIF» + ''' + + protected dispatch def String toExpectation(ResourceOperation it) ''' + kind : «kind» ''' protected dispatch def String toExpectation(CodeAction it) ''' diff --git a/org.eclipse.xtext.testing/xtend-gen/org/eclipse/xtext/testing/AbstractLanguageServerTest.java b/org.eclipse.xtext.testing/xtend-gen/org/eclipse/xtext/testing/AbstractLanguageServerTest.java index c61ad7e7a..18213e8d7 100644 --- a/org.eclipse.xtext.testing/xtend-gen/org/eclipse/xtext/testing/AbstractLanguageServerTest.java +++ b/org.eclipse.xtext.testing/xtend-gen/org/eclipse/xtext/testing/AbstractLanguageServerTest.java @@ -67,6 +67,7 @@ import org.eclipse.lsp4j.PublishDiagnosticsParams; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.ReferenceContext; import org.eclipse.lsp4j.ReferenceParams; +import org.eclipse.lsp4j.ResourceOperation; import org.eclipse.lsp4j.SemanticHighlightingInformation; import org.eclipse.lsp4j.SemanticHighlightingParams; import org.eclipse.lsp4j.SignatureHelp; @@ -919,22 +920,69 @@ public abstract class AbstractLanguageServerTest implements Endpoint { _builder.append("changes :"); _builder.newLine(); { - Set>> _entrySet = it.getChanges().entrySet(); - for(final Map.Entry> entry : _entrySet) { - _builder.append("\t"); - String _lastSegment = org.eclipse.emf.common.util.URI.createURI(entry.getKey()).lastSegment(); - _builder.append(_lastSegment, "\t"); - _builder.append(" : "); - String _expectation = this.toExpectation(entry.getValue()); - _builder.append(_expectation, "\t"); - _builder.newLineIfNotEmpty(); + Map> _changes = it.getChanges(); + boolean _tripleNotEquals = (_changes != null); + if (_tripleNotEquals) { + { + Set>> _entrySet = it.getChanges().entrySet(); + for(final Map.Entry> entry : _entrySet) { + _builder.append("\t"); + String _lastSegment = org.eclipse.emf.common.util.URI.createURI(entry.getKey()).lastSegment(); + _builder.append(_lastSegment, "\t"); + _builder.append(" : "); + String _expectation = this.toExpectation(entry.getValue()); + _builder.append(_expectation, "\t"); + _builder.newLineIfNotEmpty(); + } + } } } _builder.append("documentChanges : "); _builder.newLine(); - _builder.append("\t"); - String _expectation_1 = this.toExpectation(it.getDocumentChanges()); - _builder.append(_expectation_1, "\t"); + { + boolean _isNullOrEmpty = IterableExtensions.isNullOrEmpty(it.getDocumentChanges()); + boolean _not = (!_isNullOrEmpty); + if (_not) { + { + final Function1, Boolean> _function = (Either it_1) -> { + return Boolean.valueOf(it_1.isLeft()); + }; + final Function1, TextDocumentEdit> _function_1 = (Either it_1) -> { + return it_1.getLeft(); + }; + Iterable _map = IterableExtensions., TextDocumentEdit>map(IterableExtensions.>filter(it.getDocumentChanges(), _function), _function_1); + for(final TextDocumentEdit entry_1 : _map) { + _builder.append("\t"); + String _expectation_1 = this.toExpectation(entry_1); + _builder.append(_expectation_1, "\t"); + _builder.newLineIfNotEmpty(); + } + } + { + final Function1, Boolean> _function_2 = (Either it_1) -> { + return Boolean.valueOf(it_1.isRight()); + }; + final Function1, ResourceOperation> _function_3 = (Either it_1) -> { + return it_1.getRight(); + }; + Iterable _map_1 = IterableExtensions., ResourceOperation>map(IterableExtensions.>filter(it.getDocumentChanges(), _function_2), _function_3); + for(final ResourceOperation entry_2 : _map_1) { + _builder.append("\t"); + String _expectation_2 = this.toExpectation(entry_2); + _builder.append(_expectation_2, "\t"); + _builder.newLineIfNotEmpty(); + } + } + } + } + return _builder.toString(); + } + + protected String _toExpectation(final ResourceOperation it) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("kind : "); + String _kind = it.getKind(); + _builder.append(_kind); _builder.newLineIfNotEmpty(); return _builder.toString(); } @@ -1514,6 +1562,8 @@ public abstract class AbstractLanguageServerTest implements Endpoint { return _toExpectation((Position)it); } else if (it instanceof Range) { return _toExpectation((Range)it); + } else if (it instanceof ResourceOperation) { + return _toExpectation((ResourceOperation)it); } else if (it instanceof SignatureHelp) { return _toExpectation((SignatureHelp)it); } else if (it instanceof SymbolInformation) {