use of org.eclipse.lsp4j.MarkedString in project ballerina by ballerina-lang.
the class BallerinaTextDocumentService method hover.
@Override
public CompletableFuture<Hover> hover(TextDocumentPositionParams position) {
return CompletableFuture.supplyAsync(() -> {
TextDocumentServiceContext hoverContext = new TextDocumentServiceContext();
hoverContext.put(DocumentServiceKeys.FILE_URI_KEY, position.getTextDocument().getUri());
hoverContext.put(DocumentServiceKeys.POSITION_KEY, position);
Hover hover;
try {
BLangPackage currentBLangPackage = TextDocumentServiceUtil.getBLangPackage(hoverContext, documentManager, false, LSCustomErrorStrategy.class, false).get(0);
hoverContext.put(DocumentServiceKeys.CURRENT_PACKAGE_NAME_KEY, currentBLangPackage.symbol.getName().getValue());
lSPackageCache.addPackage(currentBLangPackage);
hover = HoverUtil.getHoverContent(hoverContext, currentBLangPackage, lSPackageCache);
} catch (Exception | AssertionError e) {
hover = new Hover();
List<Either<String, MarkedString>> contents = new ArrayList<>();
contents.add(Either.forLeft(""));
hover.setContents(contents);
}
return hover;
});
}
use of org.eclipse.lsp4j.MarkedString in project sts4 by spring-projects.
the class RequestMappingHoverProvider method addHoverContent.
private void addHoverContent(List<Tuple2<RequestMapping, SpringBootApp>> mappingMethods, List<Either<String, MarkedString>> hoverContent) throws Exception {
for (int i = 0; i < mappingMethods.size(); i++) {
Tuple2<RequestMapping, SpringBootApp> mappingMethod = mappingMethods.get(i);
SpringBootApp app = mappingMethod.getT2();
String port = mappingMethod.getT2().getPort();
String host = mappingMethod.getT2().getHost();
List<Renderable> renderableUrls = Arrays.stream(mappingMethod.getT1().getSplitPath()).flatMap(path -> {
String url = UrlUtil.createUrl(host, port, path);
StringBuilder builder = new StringBuilder();
builder.append("[");
builder.append(url);
builder.append("]");
builder.append("(");
builder.append(url);
builder.append(")");
return Stream.of(Renderables.text(builder.toString()), Renderables.lineBreak());
}).collect(Collectors.toList());
// Remove the last line break
renderableUrls.remove(renderableUrls.size() - 1);
hoverContent.add(Either.forLeft(Renderables.concat(renderableUrls).toMarkdown()));
hoverContent.add(Either.forLeft(LiveHoverUtils.niceAppName(app)));
if (i < mappingMethods.size() - 1) {
// Three dashes == line separator in Markdown
hoverContent.add(Either.forLeft("---"));
}
}
}
Aggregations