use of org.eclipse.lsp4j.MarkedString 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();
}
use of org.eclipse.lsp4j.MarkedString in project eclipse.jdt.ls by eclipse.
the class HoverHandlerTest method testHover.
@Test
public void testHover() throws Exception {
// given
// Hovers on the System.out
String payload = createHoverRequest("src/java/Foo.java", 5, 15);
TextDocumentPositionParams position = getParams(payload);
// when
Hover hover = handler.hover(position, monitor);
// then
assertNotNull(hover);
assertNotNull(hover.getContents());
MarkedString signature = hover.getContents().get(0).getRight();
assertEquals("Unexpected hover " + signature, "java", signature.getLanguage());
assertEquals("Unexpected hover " + signature, "java.Foo", signature.getValue());
String doc = hover.getContents().get(1).getLeft();
assertEquals("Unexpected hover " + doc, "This is foo", doc);
}
use of org.eclipse.lsp4j.MarkedString in project eclipse.jdt.ls by eclipse.
the class HoverHandlerTest method testHoverWithAttachedJavadoc.
@Test
public void testHoverWithAttachedJavadoc() throws Exception {
File commonPrimitivesJdoc = DependencyUtil.getJavadoc("commons-primitives", "commons-primitives", "1.0");
assertNotNull("Unable to locate commons-primitives-1.0-javadoc.jar", commonPrimitivesJdoc);
importProjects("maven/attached-javadoc");
project = WorkspaceHelper.getProject("attached-javadoc");
handler = new HoverHandler(preferenceManager);
// given
// Hovers on org.apache.commons.collections.primitives.ShortCollections which has no source but an attached javadoc
String payload = createHoverRequest("src/main/java/org/sample/Bar.java", 2, 56);
TextDocumentPositionParams position = getParams(payload);
// when
Hover hover = handler.hover(position, monitor);
assertNotNull("Hover is null", hover);
assertEquals("Unexpected hover contents:\n" + hover.getContents(), 2, hover.getContents().size());
Either<String, MarkedString> javadoc = hover.getContents().get(1);
String content = null;
assertTrue("javadoc has null content", javadoc != null && javadoc.getLeft() != null && (content = javadoc.getLeft()) != null);
assertTrue("Unexpected hover :\n" + content, content.contains("This class consists exclusively of static methods that operate on or return ShortCollections"));
assertTrue("Unexpected hover :\n" + content, content.contains("**Author:**"));
}
use of org.eclipse.lsp4j.MarkedString in project eclipse.jdt.ls by eclipse.
the class HoverHandlerTest method testHoverVariable.
@Test
public void testHoverVariable() throws Exception {
// given
// Hover on args parameter
String argParam = createHoverRequest("src/java/Foo.java", 7, 37);
TextDocumentPositionParams position = getParams(argParam);
// when
Hover hover = handler.hover(position, monitor);
// then
assertNotNull(hover);
assertNotNull(hover.getContents());
MarkedString signature = hover.getContents().get(0).getRight();
assertEquals("Unexpected hover " + signature, "java", signature.getLanguage());
assertEquals("Unexpected hover " + signature, "String[] args - java.Foo.main(String[])", signature.getValue());
}
use of org.eclipse.lsp4j.MarkedString in project ballerina by ballerina-lang.
the class HoverUtil method getHoverInformation.
/**
* Get the hover information for the given hover context.
*
* @param bLangPackage resolved bLangPackage for the hover context.
* @param hoverContext context of the hover.
* @return hover content.
*/
public static Hover getHoverInformation(BLangPackage bLangPackage, TextDocumentServiceContext hoverContext) {
Hover hover;
switch(hoverContext.get(NodeContextKeys.SYMBOL_KIND_OF_NODE_PARENT_KEY)) {
case ContextConstants.FUNCTION:
BLangFunction bLangFunction = bLangPackage.functions.stream().filter(function -> function.name.getValue().equals(hoverContext.get(NodeContextKeys.NAME_OF_NODE_KEY))).findAny().orElse(null);
if (bLangFunction != null) {
if (bLangFunction.docAttachments.size() > 0) {
hover = getDocumentationContent(bLangFunction.docAttachments);
} else {
hover = getAnnotationContent(bLangFunction.annAttachments);
}
} else {
hover = getDefaultHoverObject();
}
break;
case ContextConstants.STRUCT:
BLangStruct bLangStruct = bLangPackage.structs.stream().filter(struct -> struct.name.getValue().equals(hoverContext.get(NodeContextKeys.NAME_OF_NODE_KEY))).findAny().orElse(null);
if (bLangStruct != null) {
if (bLangStruct.docAttachments.size() > 0) {
hover = getDocumentationContent(bLangStruct.docAttachments);
} else {
hover = getAnnotationContent(bLangStruct.annAttachments);
}
} else {
hover = getDefaultHoverObject();
}
break;
case ContextConstants.OBJECT:
BLangObject bLangObject = bLangPackage.objects.stream().filter(object -> object.name.getValue().equals(hoverContext.get(NodeContextKeys.NAME_OF_NODE_KEY))).findAny().orElse(null);
if (bLangObject != null) {
if (bLangObject.docAttachments.size() > 0) {
hover = getDocumentationContent(bLangObject.docAttachments);
} else {
hover = getAnnotationContent(bLangObject.annAttachments);
}
} else {
hover = getDefaultHoverObject();
}
break;
case ContextConstants.ENUM:
BLangEnum bLangEnum = bLangPackage.enums.stream().filter(bEnum -> bEnum.name.getValue().equals(hoverContext.get(NodeContextKeys.NAME_OF_NODE_KEY))).findAny().orElse(null);
if (bLangEnum != null) {
if (bLangEnum.docAttachments.size() > 0) {
hover = getDocumentationContent(bLangEnum.docAttachments);
} else {
hover = getAnnotationContent(bLangEnum.annAttachments);
}
} else {
hover = getDefaultHoverObject();
}
break;
case ContextConstants.TRANSFORMER:
BLangTransformer bLangTransformer = bLangPackage.transformers.stream().filter(bTransformer -> bTransformer.name.getValue().equals(hoverContext.get(NodeContextKeys.NAME_OF_NODE_KEY))).findAny().orElse(null);
if (bLangTransformer != null) {
if (bLangTransformer.docAttachments.size() > 0) {
hover = getDocumentationContent(bLangTransformer.docAttachments);
} else {
hover = getAnnotationContent(bLangTransformer.annAttachments);
}
} else {
hover = getDefaultHoverObject();
}
break;
case ContextConstants.CONNECTOR:
BLangConnector bLangConnector = bLangPackage.connectors.stream().filter(bConnector -> bConnector.name.getValue().equals(hoverContext.get(NodeContextKeys.NAME_OF_NODE_KEY))).findAny().orElse(null);
if (bLangConnector != null) {
if (bLangConnector.docAttachments.size() > 0) {
hover = getDocumentationContent(bLangConnector.docAttachments);
} else {
hover = getAnnotationContent(bLangConnector.annAttachments);
}
} else {
hover = getDefaultHoverObject();
}
break;
case ContextConstants.ACTION:
BLangAction bLangAction = bLangPackage.connectors.stream().filter(bConnector -> bConnector.name.getValue().equals(((BLangInvocation) hoverContext.get(NodeContextKeys.PREVIOUSLY_VISITED_NODE_KEY)).symbol.owner.name.getValue())).flatMap(connector -> connector.actions.stream()).filter(bAction -> bAction.name.getValue().equals(hoverContext.get(NodeContextKeys.NAME_OF_NODE_KEY))).findAny().orElse(null);
if (bLangAction != null) {
if (bLangAction.docAttachments.size() > 0) {
hover = getDocumentationContent(bLangAction.docAttachments);
} else {
hover = getAnnotationContent(bLangAction.annAttachments);
}
} else {
hover = getDefaultHoverObject();
}
break;
case ContextConstants.ENDPOINT:
BLangEndpoint bLangEndpoint = bLangPackage.globalEndpoints.stream().filter(globalEndpoint -> globalEndpoint.name.value.equals(hoverContext.get(NodeContextKeys.VAR_NAME_OF_NODE_KEY))).findAny().orElse(null);
if (bLangEndpoint != null) {
hover = getAnnotationContent(bLangEndpoint.annAttachments);
} else {
hover = getDefaultHoverObject();
}
break;
case ContextConstants.VARIABLE:
BLangVariable bLangVariable = bLangPackage.globalVars.stream().filter(globalVar -> globalVar.name.getValue().equals(hoverContext.get(NodeContextKeys.VAR_NAME_OF_NODE_KEY))).findAny().orElse(null);
if (bLangVariable != null) {
if (bLangVariable.docAttachments.size() > 0) {
hover = getDocumentationContent(bLangVariable.docAttachments);
} else {
hover = getAnnotationContent(bLangVariable.annAttachments);
}
} else {
hover = getDefaultHoverObject();
}
break;
default:
hover = new Hover();
List<Either<String, MarkedString>> contents = new ArrayList<>();
contents.add(Either.forLeft(""));
hover.setContents(contents);
break;
}
return hover;
}
Aggregations