Simple test for 'goto symbol' in pipeline.yml

This commit is contained in:
Kris De Volder
2017-04-13 15:35:51 -07:00
parent 3ccb392e6f
commit bbe2bdd54e
4 changed files with 58 additions and 2 deletions

View File

@@ -69,7 +69,6 @@ public class SchemaBasedYamlASTReconciler implements YamlASTReconciler {
this.quickfixes = quickfixes;
}
@Override
public void reconcile(YamlFileAST ast) {
if (typeCollector!=null) typeCollector.beginCollecting(ast);

View File

@@ -18,6 +18,7 @@ import static org.springframework.ide.vscode.languageserver.testharness.TestAsse
import static org.springframework.ide.vscode.languageserver.testharness.TestAsserts.assertDoesNotContain;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
@@ -38,12 +39,14 @@ import org.eclipse.lsp4j.MarkedString;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.PublishDiagnosticsParams;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.eclipse.lsp4j.TextDocumentPositionParams;
import org.eclipse.lsp4j.TextEdit;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.junit.Assert;
import org.springframework.ide.vscode.commons.util.CollectionUtil;
import org.springframework.ide.vscode.commons.util.StringUtil;
import com.google.common.collect.ImmutableList;
@@ -647,4 +650,31 @@ public class Editor {
assertEquals(expectedText, getRawText());
}
public void assertDocumentSymbols(String... symbolsAndContainers) throws Exception {
Arrays.sort(symbolsAndContainers);
StringBuilder expected = new StringBuilder();
for (String string : symbolsAndContainers) {
expected.append(string+"\n");
}
List<? extends SymbolInformation> actualSymbols = getDocumentSymbols();
List<String> actuals = new ArrayList<>();
for (SymbolInformation actualSymbol : actualSymbols) {
assertEquals(document.getUri(), actualSymbol.getLocation().getUri());
String coveredText = getText(actualSymbol.getLocation().getRange());
assertEquals(actualSymbol.getName(), coveredText);
actuals.add(coveredText + "|" + actualSymbol.getContainerName());
}
Collections.sort(actuals);
StringBuilder actual = new StringBuilder();
for (String string : actuals) {
actual.append(string+"\n");
}
assertEquals(expected.toString(), actual.toString());
}
private List<? extends SymbolInformation> getDocumentSymbols() throws Exception {
return harness.getDocumentSymbols(this.document);
}
}

View File

@@ -41,6 +41,7 @@ import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4j.DidChangeTextDocumentParams;
import org.eclipse.lsp4j.DidOpenTextDocumentParams;
import org.eclipse.lsp4j.DocumentSymbolParams;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.InitializeParams;
import org.eclipse.lsp4j.InitializeResult;
@@ -51,7 +52,9 @@ import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.PublishDiagnosticsParams;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.ShowMessageRequestParams;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.TextDocumentContentChangeEvent;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.eclipse.lsp4j.TextDocumentItem;
import org.eclipse.lsp4j.TextDocumentPositionParams;
import org.eclipse.lsp4j.TextDocumentSyncKind;
@@ -495,5 +498,9 @@ public class LanguageServerHarness {
.collect(Collectors.toList());
}
public List<? extends SymbolInformation> getDocumentSymbols(TextDocumentInfo document) throws Exception {
server.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 server.getTextDocumentService().documentSymbol(params).get();
}
}

View File

@@ -2964,6 +2964,26 @@ public class ConcourseEditorTest {
);
}
@Test public void gotoSymbolInPipeline() throws Exception {
Editor editor = harness.newEditor(
"resource_types:\n" +
"- name: some-resource-type\n" +
"resources:\n" +
"- name: foo-resource\n" +
"- name: bar-resource\n" +
"jobs:\n" +
"- name: do-some-stuff\n" +
"- name: do-more-stuff\n"
);
editor.assertDocumentSymbols(
"some-resource-type|ResourceType",
"foo-resource|Resource",
"bar-resource|Resource",
"do-some-stuff|Job",
"do-more-stuff|Job"
);
}
//////////////////////////////////////////////////////////////////////////////