diff --git a/org.eclipse.xtext.ide.tests/META-INF/MANIFEST.MF b/org.eclipse.xtext.ide.tests/META-INF/MANIFEST.MF index 538924eb3c..09095d77e7 100644 --- a/org.eclipse.xtext.ide.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.xtext.ide.tests/META-INF/MANIFEST.MF @@ -14,8 +14,8 @@ Require-Bundle: org.eclipse.xtext;visibility:=reexport, org.eclipse.core.runtime;bundle-version="3.13.0", org.eclipse.xtext.ide, org.junit;bundle-version="4.12.0", - org.eclipse.lsp4j;bundle-version="[0.12.0,0.13.0)";resolution:=optional, - org.eclipse.lsp4j.jsonrpc;bundle-version="[0.12.0,0.13.0)";resolution:=optional, + org.eclipse.lsp4j;bundle-version="[0.13.0,0.14.0)";resolution:=optional, + org.eclipse.lsp4j.jsonrpc;bundle-version="[0.13.0,0.14.0)";resolution:=optional, org.eclipse.xtext.testlanguages, org.eclipse.xtext.testlanguages.ide Import-Package: org.apache.log4j;version="1.2.19" diff --git a/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/ServerTest.java b/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/ServerTest.java index 18e2fecb1e..30c4c2e5aa 100644 --- a/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/ServerTest.java +++ b/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/ServerTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others. + * Copyright (c) 2016, 2022 TypeFox GmbH (http://www.typefox.io) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -140,7 +140,7 @@ public void testMissingInitialize() throws Exception { languageServer.definition(definitionParams).get(); Assert.fail("Expected a ResponseErrorException"); } catch (ExecutionException exception) { - Assert.assertEquals(ResponseErrorCode.serverNotInitialized.getValue(), + Assert.assertEquals(ResponseErrorCode.ServerNotInitialized.getValue(), ((ResponseErrorException) exception.getCause()).getResponseError().getCode()); } } diff --git a/org.eclipse.xtext.ide/META-INF/MANIFEST.MF b/org.eclipse.xtext.ide/META-INF/MANIFEST.MF index 9e9d588475..face0c7876 100644 --- a/org.eclipse.xtext.ide/META-INF/MANIFEST.MF +++ b/org.eclipse.xtext.ide/META-INF/MANIFEST.MF @@ -11,8 +11,8 @@ Require-Bundle: org.eclipse.xtext;visibility:=reexport, org.eclipse.xtend.lib, org.eclipse.core.runtime;bundle-version="3.13.0";resolution:=optional;x-installation:=greedy, org.eclipse.equinox.common;bundle-version="3.9.0", - org.eclipse.lsp4j;bundle-version="[0.12.0,0.13.0)";resolution:=optional, - org.eclipse.lsp4j.jsonrpc;bundle-version="[0.12.0,0.13.0)";resolution:=optional, + org.eclipse.lsp4j;bundle-version="[0.13.0,0.14.0)";resolution:=optional, + org.eclipse.lsp4j.jsonrpc;bundle-version="[0.13.0,0.14.0)";resolution:=optional, org.eclipse.emf.ecore.change;bundle-version="[2.14.0,3)" Import-Package: org.apache.log4j;version="1.2.19" Export-Package: org.eclipse.xtext.ide; diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.java b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.java index ebab723e30..acde20b5e9 100644 --- a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.java +++ b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.java @@ -92,6 +92,7 @@ import org.eclipse.lsp4j.WorkspaceFolder; import org.eclipse.lsp4j.WorkspaceFoldersOptions; import org.eclipse.lsp4j.WorkspaceServerCapabilities; +import org.eclipse.lsp4j.WorkspaceSymbol; import org.eclipse.lsp4j.WorkspaceSymbolParams; import org.eclipse.lsp4j.jsonrpc.Endpoint; import org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethod; @@ -684,7 +685,7 @@ protected boolean isHierarchicalDocumentSymbolSupport() { } @Override - public CompletableFuture> symbol(WorkspaceSymbolParams params) { + public CompletableFuture, List>> symbol(WorkspaceSymbolParams params) { return requestManager.runRead((cancelIndicator) -> symbol(params, cancelIndicator)); } @@ -692,7 +693,7 @@ public CompletableFuture> symbol(WorkspaceSymb * Compute the symbol information. Executed in a read request. * @since 2.20 */ - protected List symbol(WorkspaceSymbolParams params, CancelIndicator cancelIndicator) { + protected Either, List> symbol(WorkspaceSymbolParams params, CancelIndicator cancelIndicator) { return workspaceSymbolService.getSymbols(params.getQuery(), resourceAccess, workspaceManager.getIndex(), cancelIndicator); } diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/WorkspaceManager.java b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/WorkspaceManager.java index cf12dea87d..b747b9eec7 100644 --- a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/WorkspaceManager.java +++ b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/WorkspaceManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others. + * Copyright (c) 2016, 2022 TypeFox GmbH (http://www.typefox.io) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -240,7 +240,7 @@ protected void refreshWorkspaceConfig(CancelIndicator cancelIndicator) { */ protected IWorkspaceConfig getWorkspaceConfig() throws ResponseErrorException { if (workspaceConfig == null) { - ResponseError error = new ResponseError(ResponseErrorCode.serverNotInitialized, + ResponseError error = new ResponseError(ResponseErrorCode.ServerNotInitialized, "Workspace has not been initialized yet.", null); throw new ResponseErrorException(error); } diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/symbol/WorkspaceSymbolService.java b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/symbol/WorkspaceSymbolService.java index 1d8a139052..9f3d67f610 100644 --- a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/symbol/WorkspaceSymbolService.java +++ b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/symbol/WorkspaceSymbolService.java @@ -14,6 +14,8 @@ import java.util.LinkedList; import java.util.List; import org.eclipse.lsp4j.SymbolInformation; +import org.eclipse.lsp4j.WorkspaceSymbol; +import org.eclipse.lsp4j.jsonrpc.messages.Either; import org.eclipse.xtext.findReferences.IReferenceFinder.IResourceAccess; import org.eclipse.xtext.resource.IResourceDescription; import org.eclipse.xtext.resource.IResourceDescriptions; @@ -34,7 +36,7 @@ public class WorkspaceSymbolService { @Inject private OperationCanceledManager operationCanceledManager; - public List getSymbols( + public Either, List> getSymbols( String query, IResourceAccess resourceAccess, IResourceDescriptions indexData, @@ -51,7 +53,7 @@ public List getSymbols( } } } - return result; + return Either.forLeft(result); } } 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 825b9f57b3..d9f59a30b9 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2021 TypeFox GmbH (http://www.typefox.io) and others. + * Copyright (c) 2016, 2022 TypeFox GmbH (http://www.typefox.io) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -92,6 +92,7 @@ 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.WorkspaceSymbol /** * @author Sven Efftinge - Initial contribution and API @@ -305,6 +306,7 @@ abstract class AbstractLanguageServerTest implements Endpoint { protected def dispatch String toExpectation(Position it) '''[�line�, �character�]''' + @Deprecated protected def dispatch String toExpectation(SymbolInformation it) ''' symbol "�name�" { kind: �kind.value� @@ -315,6 +317,16 @@ abstract class AbstractLanguageServerTest implements Endpoint { } ''' + protected def dispatch String toExpectation(WorkspaceSymbol it) ''' + symbol "�name�" { + kind: �kind.value� + location: �location.toExpectation� + �IF !containerName.nullOrEmpty� + container: "�containerName�" + �ENDIF� + } + ''' + /** * @since 2.16 */ @@ -624,7 +636,7 @@ abstract class AbstractLanguageServerTest implements Endpoint { if (configuration.getAssertSymbols !== null) { configuration.getAssertSymbols.apply(symbols) } else { - val unwrappedSymbols = symbols.map[if(hierarchicalDocumentSymbolSupport) getRight else getLeft] + val unwrappedSymbols = symbols.map[if (hierarchicalDocumentSymbolSupport) getRight else getLeft] val String actualSymbols = unwrappedSymbols.toExpectation assertEquals(getExpectedSymbols, actualSymbols) } @@ -637,8 +649,12 @@ abstract class AbstractLanguageServerTest implements Endpoint { initializeContext(configuration) val symbols = languageServer.symbol(new WorkspaceSymbolParams(query)).get - if (configuration.assertSymbols !== null) { - configuration.assertSymbols.apply(symbols) + if (configuration.assertSymbols !== null || configuration.assertWorkspaceSymbols !== null) { + if (symbols.isLeft) { + configuration.assertSymbols.apply(symbols.getLeft) + } else { + configuration.assertWorkspaceSymbols.apply(symbols.getRight) + } } else { val String actualSymbols = symbols.toExpectation assertEquals(expectedSymbols, actualSymbols) diff --git a/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/WorkspaceSymbolConfiguration.java b/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/WorkspaceSymbolConfiguration.java index a3bdcd8d0d..15bceda194 100644 --- a/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/WorkspaceSymbolConfiguration.java +++ b/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/WorkspaceSymbolConfiguration.java @@ -11,6 +11,7 @@ import java.util.List; import org.eclipse.lsp4j.SymbolInformation; +import org.eclipse.lsp4j.WorkspaceSymbol; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; public class WorkspaceSymbolConfiguration extends TextDocumentConfiguration { @@ -18,7 +19,9 @@ public class WorkspaceSymbolConfiguration extends TextDocumentConfiguration { private String expectedSymbols = ""; + @Deprecated private Procedure1> assertSymbols = null; + private Procedure1> assertWorkspaceSymbols = null; public String getQuery() { return query; @@ -36,11 +39,27 @@ public void setExpectedSymbols(String expectedSymbols) { this.expectedSymbols = expectedSymbols; } + @Deprecated public Procedure1> getAssertSymbols() { return assertSymbols; } + @Deprecated public void setAssertSymbols(Procedure1> assertSymbols) { this.assertSymbols = assertSymbols; } + + /** + * @since 2.27.0 + */ + public Procedure1> getAssertWorkspaceSymbols() { + return assertWorkspaceSymbols; + } + + /** + * @since 2.27.0 + */ + public void setAssertWorkspaceSymbols(Procedure1> assertWorkspaceSymbols) { + this.assertWorkspaceSymbols = assertWorkspaceSymbols; + } } 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 d846cf1524..d4400f48ba 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 @@ -1,5 +1,5 @@ /** - * Copyright (c) 2016, 2021 TypeFox GmbH (http://www.typefox.io) and others. + * Copyright (c) 2016, 2022 TypeFox GmbH (http://www.typefox.io) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -81,6 +81,7 @@ import org.eclipse.lsp4j.VersionedTextDocumentIdentifier; import org.eclipse.lsp4j.WorkspaceEdit; import org.eclipse.lsp4j.WorkspaceFolder; +import org.eclipse.lsp4j.WorkspaceSymbol; import org.eclipse.lsp4j.WorkspaceSymbolParams; import org.eclipse.lsp4j.jsonrpc.Endpoint; import org.eclipse.lsp4j.jsonrpc.messages.Either; @@ -519,6 +520,7 @@ protected String _toExpectation(final Position it) { return _builder.toString(); } + @Deprecated protected String _toExpectation(final SymbolInformation it) { StringConcatenation _builder = new StringConcatenation(); _builder.append("symbol \""); @@ -553,6 +555,40 @@ protected String _toExpectation(final SymbolInformation it) { return _builder.toString(); } + protected String _toExpectation(final WorkspaceSymbol it) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("symbol \""); + String _name = it.getName(); + _builder.append(_name); + _builder.append("\" {"); + _builder.newLineIfNotEmpty(); + _builder.append(" "); + _builder.append("kind: "); + int _value = it.getKind().getValue(); + _builder.append(_value, " "); + _builder.newLineIfNotEmpty(); + _builder.append(" "); + _builder.append("location: "); + String _expectation = this.toExpectation(it.getLocation()); + _builder.append(_expectation, " "); + _builder.newLineIfNotEmpty(); + { + boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(it.getContainerName()); + boolean _not = (!_isNullOrEmpty); + if (_not) { + _builder.append(" "); + _builder.append("container: \""); + String _containerName = it.getContainerName(); + _builder.append(_containerName, " "); + _builder.append("\""); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("}"); + _builder.newLine(); + return _builder.toString(); + } + /** * @since 2.16 */ @@ -1297,11 +1333,14 @@ protected void testSymbol(final Procedure1 this.initializeContext(configuration); String _query = configuration.getQuery(); WorkspaceSymbolParams _workspaceSymbolParams = new WorkspaceSymbolParams(_query); - final List symbols = this.languageServer.symbol(_workspaceSymbolParams).get(); - Procedure1> _assertSymbols = configuration.getAssertSymbols(); - boolean _tripleNotEquals = (_assertSymbols != null); - if (_tripleNotEquals) { - configuration.getAssertSymbols().apply(symbols); + final Either, List> symbols = this.languageServer.symbol(_workspaceSymbolParams).get(); + if (((configuration.getAssertSymbols() != null) || (configuration.getAssertWorkspaceSymbols() != null))) { + boolean _isLeft = symbols.isLeft(); + if (_isLeft) { + configuration.getAssertSymbols().apply(symbols.getLeft()); + } else { + configuration.getAssertWorkspaceSymbols().apply(symbols.getRight()); + } } else { final String actualSymbols = this.toExpectation(symbols); this.assertEquals(configuration.getExpectedSymbols(), actualSymbols); @@ -1524,6 +1563,8 @@ protected String toExpectation(final Object it) { return _toExpectation((TextEdit)it); } else if (it instanceof WorkspaceEdit) { return _toExpectation((WorkspaceEdit)it); + } else if (it instanceof WorkspaceSymbol) { + return _toExpectation((WorkspaceSymbol)it); } else if (it instanceof Either) { return _toExpectation((Either)it); } else {