Add some test for '//' workspace symbols

Fix a small bug in the process too (the case without paths).
This commit is contained in:
Kris De Volder
2019-04-01 16:15:23 -07:00
parent 8468c7d67e
commit 4ed167aaae
3 changed files with 122 additions and 6 deletions

View File

@@ -11,9 +11,7 @@
package org.springframework.ide.vscode.boot.java.requestmapping;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.Position;
@@ -24,6 +22,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.boot.java.handlers.RunningAppProvider;
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
import org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping;
/**
* @author Martin Lippert
@@ -49,10 +48,20 @@ public class LiveAppURLSymbolProvider {
String host = app.getHost();
String port = app.getPort();
String contextPath = app.getContextPath();
Stream<String> urls = app.getRequestMappings().stream()
.flatMap(rm -> Arrays.stream(rm.getSplitPath()))
.map(path -> UrlUtil.createUrl(urlScheme, host, port, path, contextPath));
urls.forEach(url -> result.add(new SymbolInformation(url, SymbolKind.Method, new Location(url, new Range(new Position(0, 0), new Position(0, 1))))));
for (RequestMapping rm : app.getRequestMappings()) {
String[] paths = rm.getSplitPath();
if (paths==null || paths.length==0) {
//Technically, this means the path 'predicate' is unconstrained, meaning any path matches.
//So this is not quite the same as the case where path=""... but...
//It is better for us to show one link where any path is allowed, versus showing no links where any link is allowed.
//So we'll pretend this is the same as path="" as that gives a working link.
paths = new String[] {""};
}
for (String path : paths) {
String url = UrlUtil.createUrl(urlScheme, host, port, path, contextPath);
result.add(new SymbolInformation(url, SymbolKind.Method, new Location(url, new Range(new Position(0, 0), new Position(0, 1)))));
}
}
}
catch (Exception e) {
log.error("", e);