Add test for concourse hierarchical document symbols
This commit is contained in:
@@ -36,6 +36,7 @@ import org.eclipse.lsp4j.CodeLens;
|
||||
import org.eclipse.lsp4j.CompletionItem;
|
||||
import org.eclipse.lsp4j.CompletionList;
|
||||
import org.eclipse.lsp4j.Diagnostic;
|
||||
import org.eclipse.lsp4j.DocumentSymbol;
|
||||
import org.eclipse.lsp4j.Hover;
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.MarkedString;
|
||||
@@ -901,6 +902,38 @@ public class Editor {
|
||||
assertEquals(expected.toString(), actual.toString());
|
||||
}
|
||||
|
||||
public void assertHierarchicalDocumentSymbols(String expectedSymbolDump) throws Exception {
|
||||
StringBuilder symbolDump = new StringBuilder();
|
||||
List<? extends DocumentSymbol> rootSymbols = getHierarchicalDocumentSymbols();
|
||||
dumpSymbols(rootSymbols, 0, symbolDump);
|
||||
assertEquals(expectedSymbolDump, symbolDump.toString());
|
||||
}
|
||||
|
||||
private void dumpSymbols(List<? extends DocumentSymbol> syms, int indent, StringBuilder symbolDump) {
|
||||
for (DocumentSymbol s : syms) {
|
||||
dumpSymbol(s, indent, symbolDump);
|
||||
}
|
||||
}
|
||||
|
||||
private void dumpSymbol(DocumentSymbol s, int indent, StringBuilder symbolDump) {
|
||||
for (int i = 0; i < indent; i++) {
|
||||
symbolDump.append(" ");
|
||||
}
|
||||
symbolDump.append(s.getName());
|
||||
symbolDump.append("::");
|
||||
symbolDump.append(s.getDetail());
|
||||
symbolDump.append("\n");
|
||||
assertEquals(s.getName(), getText(s.getSelectionRange()));
|
||||
List<DocumentSymbol> children = s.getChildren();
|
||||
if (children!=null) {
|
||||
dumpSymbols(children, indent+1, symbolDump);
|
||||
}
|
||||
}
|
||||
|
||||
private List<? extends DocumentSymbol> getHierarchicalDocumentSymbols() throws Exception {
|
||||
return harness.getHierarchicalDocumentSymbols(this.doc);
|
||||
}
|
||||
|
||||
private List<? extends SymbolInformation> getDocumentSymbols() throws Exception {
|
||||
return harness.getDocumentSymbols(this.doc);
|
||||
}
|
||||
|
||||
@@ -62,6 +62,8 @@ import org.eclipse.lsp4j.DidChangeTextDocumentParams;
|
||||
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
|
||||
import org.eclipse.lsp4j.DidCloseTextDocumentParams;
|
||||
import org.eclipse.lsp4j.DidOpenTextDocumentParams;
|
||||
import org.eclipse.lsp4j.DocumentSymbol;
|
||||
import org.eclipse.lsp4j.DocumentSymbolCapabilities;
|
||||
import org.eclipse.lsp4j.DocumentSymbolParams;
|
||||
import org.eclipse.lsp4j.ExecuteCommandCapabilities;
|
||||
import org.eclipse.lsp4j.ExecuteCommandParams;
|
||||
@@ -83,6 +85,7 @@ import org.eclipse.lsp4j.ResourceOperation;
|
||||
import org.eclipse.lsp4j.ResourceOperationKind;
|
||||
import org.eclipse.lsp4j.ShowMessageRequestParams;
|
||||
import org.eclipse.lsp4j.SymbolInformation;
|
||||
import org.eclipse.lsp4j.SymbolKindCapabilities;
|
||||
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
|
||||
import org.eclipse.lsp4j.TextDocumentContentChangeEvent;
|
||||
import org.eclipse.lsp4j.TextDocumentEdit;
|
||||
@@ -143,6 +146,8 @@ public class LanguageServerHarness {
|
||||
private List<Editor> activeEditors = new ArrayList<>();
|
||||
private Gson gson = new Gson();
|
||||
|
||||
private boolean enableHierarchicalDocumentSymbols = false;
|
||||
|
||||
|
||||
public LanguageServerHarness(SimpleLanguageServer server, LanguageId defaultLanguageId) {
|
||||
this.defaultLanguageId = defaultLanguageId;
|
||||
@@ -242,6 +247,9 @@ public class LanguageServerHarness {
|
||||
initParams.setProcessId(parentPid);
|
||||
ClientCapabilities clientCap = new ClientCapabilities();
|
||||
TextDocumentClientCapabilities textCap = new TextDocumentClientCapabilities();
|
||||
DocumentSymbolCapabilities documentSymbolCap = new DocumentSymbolCapabilities();
|
||||
documentSymbolCap.setHierarchicalDocumentSymbolSupport(enableHierarchicalDocumentSymbols);
|
||||
textCap.setDocumentSymbol(documentSymbolCap);
|
||||
CompletionCapabilities completionCap = new CompletionCapabilities(new CompletionItemCapabilities(true));
|
||||
textCap.setCompletion(completionCap);
|
||||
clientCap.setTextDocument(textCap);
|
||||
@@ -837,6 +845,12 @@ public class LanguageServerHarness {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<? extends DocumentSymbol> getHierarchicalDocumentSymbols(TextDocumentInfo document) throws Exception {
|
||||
waitForReconcile(); //TODO: if the server works properly this shouldn't be needed it should do that internally itself somehow.
|
||||
DocumentSymbolParams params = new DocumentSymbolParams(document.getId());
|
||||
return getServer().getTextDocumentService().documentSymbol(params).get().stream().map(e -> e.getRight()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<? extends SymbolInformation> getDocumentSymbols(TextDocumentInfo document) throws Exception {
|
||||
waitForReconcile(); //TODO: if the server works properly this shouldn't be needed it should do that internally itself somehow.
|
||||
DocumentSymbolParams params = new DocumentSymbolParams(document.getId());
|
||||
@@ -904,4 +918,8 @@ public class LanguageServerHarness {
|
||||
public SimpleLanguageServer getServer() {
|
||||
return server==null ? null : server.getServer();
|
||||
}
|
||||
|
||||
public void enableHierarchicalDocumentSymbols(boolean b) {
|
||||
this.enableHierarchicalDocumentSymbols = b;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3669,6 +3669,7 @@ public class ConcourseEditorTest {
|
||||
}
|
||||
|
||||
@Test public void gotoSymbolInPipeline() throws Exception {
|
||||
harness.enableHierarchicalDocumentSymbols(false);
|
||||
Editor editor = harness.newEditor(
|
||||
"resource_types:\n" +
|
||||
"- name: some-resource-type\n" +
|
||||
@@ -3695,7 +3696,7 @@ public class ConcourseEditorTest {
|
||||
}
|
||||
|
||||
@Test public void hiearhicalDocumentSymbolsInPipeline() throws Exception {
|
||||
|
||||
harness.enableHierarchicalDocumentSymbols(true);
|
||||
Editor editor = harness.newEditor(
|
||||
"resource_types:\n" +
|
||||
"- name: some-resource-type\n" +
|
||||
@@ -3710,14 +3711,18 @@ public class ConcourseEditorTest {
|
||||
"- name: group-two\n"
|
||||
);
|
||||
|
||||
editor.assertDocumentSymbols(
|
||||
"some-resource-type|ResourceType",
|
||||
"foo-resource|Resource",
|
||||
"bar-resource|Resource",
|
||||
"do-some-stuff|Job",
|
||||
"do-more-stuff|Job",
|
||||
"group-one|Group",
|
||||
"group-two|Group"
|
||||
editor.assertHierarchicalDocumentSymbols(
|
||||
"resource_types::Resource Types\n" +
|
||||
" some-resource-type::Resource Type\n" +
|
||||
"resources::Resources\n" +
|
||||
" foo-resource::Resource\n" +
|
||||
" bar-resource::Resource\n" +
|
||||
"jobs::Jobs\n" +
|
||||
" do-some-stuff::Job\n" +
|
||||
" do-more-stuff::Job\n" +
|
||||
"groups::Groups\n" +
|
||||
" group-one::Groups\n" +
|
||||
" group-two::Groups\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user