use of org.eclipse.lsp4j.Hover in project sts4 by spring-projects.
the class ConditionalsLiveHoverProvider method provideHover.
private Hover provideHover(Annotation annotation, TextDocument doc, SpringBootApp[] runningApps) {
try {
List<Either<String, MarkedString>> hoverContent = new ArrayList<>();
Optional<List<LiveConditional>> val = getMatchedLiveConditionals(annotation, runningApps);
if (val.isPresent()) {
addHoverContent(val.get(), hoverContent);
}
Range hoverRange = doc.toRange(annotation.getStartPosition(), annotation.getLength());
Hover hover = new Hover();
hover.setContents(hoverContent);
hover.setRange(hoverRange);
return hover;
} catch (Exception e) {
Log.log(e);
}
return null;
}
use of org.eclipse.lsp4j.Hover in project sts4 by spring-projects.
the class ConditionalsLiveHoverTest method PT152535713testMultipleLiveHoverHints.
@Test
public void PT152535713testMultipleLiveHoverHints() throws Exception {
// Tests fix for PT152535713. Ensure that in a method with multiple
// conditionals,
// hovering over any one conditional annotation only shows content for that
// conditional
// and not any of the other ones
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-conditionals-live-hover/").toURI());
String docUri = directory.toPath().resolve("src/main/java/example/MultipleConditionalsPT152535713.java").toUri().toString();
// Build a mock running boot app
mockAppProvider.builder().isSpringBootApp(true).port("1000").processId("70000").host("cfapps.io").processName("test-conditionals-live-hover").liveConditionalsJson("{\"positiveMatches\":{\"MultipleConditionalsPT152535713#hi\":[{\"condition\":\"OnWebApplicationCondition\",\"message\":\"@ConditionalOnWebApplication (required) found StandardServletEnvironment\"},{\"condition\":\"OnJavaCondition\",\"message\":\"@ConditionalOnJava (1.8 or newer) found 1.8\"}]}}").build();
harness.intialize(directory);
Editor editor = harness.newEditorFromFileUri(docUri, LanguageId.JAVA);
editor.assertHoverExactText("@ConditionalOnWebApplication", "@ConditionalOnWebApplication (required) found StandardServletEnvironment\n" + "\n" + "Process [PID=70000, name=`test-conditionals-live-hover`]");
editor.assertHoverExactText("@ConditionalOnJava(value=ConditionalOnJava.JavaVersion.EIGHT)", "@ConditionalOnJava (1.8 or newer) found 1.8\n" + "\n" + "Process [PID=70000, name=`test-conditionals-live-hover`]");
// Test that the hovers dont have extra information of the other conditionals:
Hover hover = editor.getHover("@ConditionalOnWebApplication");
String hoverContent = editor.hoverString(hover);
assertFalse(hoverContent.contains("@ConditionalOnJava"));
hover = editor.getHover("@ConditionalOnJava(value=ConditionalOnJava.JavaVersion.EIGHT)");
hoverContent = editor.hoverString(hover);
assertFalse(hoverContent.contains("@ConditionalOnWebApplication"));
}
use of org.eclipse.lsp4j.Hover in project xtext-core by eclipse.
the class HoverService method hover.
protected Hover hover(final HoverContext context) {
if ((context == null)) {
return IHoverService.EMPTY_HOVER;
}
final List<Either<String, MarkedString>> contents = this.getContents(context);
if ((contents == null)) {
return IHoverService.EMPTY_HOVER;
}
final Range range = this.getRange(context);
if ((range == null)) {
return IHoverService.EMPTY_HOVER;
}
return new Hover(contents, range);
}
use of org.eclipse.lsp4j.Hover in project xtext-core by eclipse.
the class AbstractLanguageServerTest method testHover.
protected void testHover(final Procedure1<? super HoverTestConfiguration> configurator) {
try {
@Extension final HoverTestConfiguration configuration = new HoverTestConfiguration();
configuration.setFilePath(("MyModel." + this.fileExtension));
configurator.apply(configuration);
final String fileUri = this.initializeContext(configuration).getUri();
TextDocumentPositionParams _textDocumentPositionParams = new TextDocumentPositionParams();
final Procedure1<TextDocumentPositionParams> _function = (TextDocumentPositionParams it) -> {
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
it.setTextDocument(_textDocumentIdentifier);
int _line = configuration.getLine();
int _column = configuration.getColumn();
Position _position = new Position(_line, _column);
it.setPosition(_position);
};
TextDocumentPositionParams _doubleArrow = ObjectExtensions.<TextDocumentPositionParams>operator_doubleArrow(_textDocumentPositionParams, _function);
final CompletableFuture<Hover> hoverFuture = this.languageServer.hover(_doubleArrow);
final Hover hover = hoverFuture.get();
Procedure1<? super Hover> _assertHover = configuration.getAssertHover();
boolean _tripleNotEquals = (_assertHover != null);
if (_tripleNotEquals) {
configuration.getAssertHover().apply(hover);
} else {
final String actualHover = this.toExpectation(hover);
this.assertEquals(configuration.getExpectedHover(), actualHover);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.lsp4j.Hover in project eclipse.jdt.ls by eclipse.
the class HoverHandlerTest method getTitleHover.
/**
* @param cu
* @return
*/
private String getTitleHover(ICompilationUnit cu, int line, int character) {
// when
Hover hover = getHover(cu, line, character);
// then
assertNotNull(hover);
MarkedString result = hover.getContents().get(0).getRight();
return result.getValue();
}
Aggregations