Skip to content

Commit

Permalink
GH-1431: adjust yaml manifest editor tests to simplified document sym…
Browse files Browse the repository at this point in the history
…bols
  • Loading branch information
martinlippert committed Feb 20, 2025
1 parent 812102a commit ef83670
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
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.TextEdit;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
Expand Down Expand Up @@ -1039,32 +1038,35 @@ public void assertRawText(String expectedText) throws Exception {
assertEquals(expectedText, getRawText());
}

public void assertDocumentSymbols(String... symbolsAndContainers) throws Exception {
Arrays.sort(symbolsAndContainers);
public void assertDocumentSymbols(String... symbols) throws Exception {
Arrays.sort(symbols);

StringBuilder expected = new StringBuilder();
for (String string : symbolsAndContainers) {
for (String string : symbols) {
expected.append(string + "\n");
}

List<? extends SymbolInformation> actualSymbols = getDocumentSymbols();
List<? extends DocumentSymbol> actualSymbols = getDocumentSymbols();

List<String> actuals = new ArrayList<>();
for (SymbolInformation actualSymbol : actualSymbols) {
assertEquals(doc.getUri(), actualSymbol.getLocation().getUri());
String coveredText = getText(actualSymbol.getLocation().getRange());
for (DocumentSymbol actualSymbol : actualSymbols) {
String coveredText = getText(actualSymbol.getRange());
assertEquals(actualSymbol.getName(), coveredText);
actuals.add(coveredText + "|" + actualSymbol.getContainerName());
actuals.add(coveredText);
}

Collections.sort(actuals);
StringBuilder actual = new StringBuilder();
for (String string : actuals) {
actual.append(string + "\n");
}

assertEquals(expected.toString(), actual.toString());
}

public void assertHierarchicalDocumentSymbols(String expectedSymbolDump) throws Exception {
StringBuilder symbolDump = new StringBuilder();
List<? extends DocumentSymbol> rootSymbols = getHierarchicalDocumentSymbols();
List<? extends DocumentSymbol> rootSymbols = getDocumentSymbols();
dumpSymbols(rootSymbols, 0, symbolDump);
assertEquals(expectedSymbolDump, symbolDump.toString());
}
Expand Down Expand Up @@ -1114,11 +1116,7 @@ private static int compare(Position p1, Position p2) {
}
}

private List<? extends DocumentSymbol> getHierarchicalDocumentSymbols() throws Exception {
return harness.getHierarchicalDocumentSymbols(this.doc);
}

private List<? extends SymbolInformation> getDocumentSymbols() throws Exception {
private List<? extends DocumentSymbol> getDocumentSymbols() throws Exception {
return harness.getDocumentSymbols(this.doc);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
import org.eclipse.lsp4j.ShowDocumentParams;
import org.eclipse.lsp4j.ShowDocumentResult;
import org.eclipse.lsp4j.ShowMessageRequestParams;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
import org.eclipse.lsp4j.TextDocumentContentChangeEvent;
import org.eclipse.lsp4j.TextDocumentEdit;
Expand Down Expand Up @@ -978,18 +977,12 @@ private synchronized List<Editor> getOpenEditors(String uri) {
.collect(Collectors.toList());
}

public List<? extends DocumentSymbol> getHierarchicalDocumentSymbols(TextDocumentInfo document) throws Exception {
public List<? extends DocumentSymbol> 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());
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());
return getServer().getTextDocumentService().documentSymbol(params).get().stream().map(e -> e.getLeft()).collect(Collectors.toList());
}

/**
* Blocks the reconciler thread until a specific point in time explicitly controlled by the test.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1801,8 +1801,8 @@ public void reconcileRouteValidDomain() throws Exception {
);

editor.assertDocumentSymbols(
"my-app|Application",
"app2|Application"
"my-app",
"app2"
);
}

Expand Down

0 comments on commit ef83670

Please sign in to comment.