use of org.eclipse.lsp4j.Hover in project ballerina by ballerina-lang.
the class HoverUtil method getDefaultHoverObject.
/**
* Get the default hover object.
*
* @return hover default hover object.
*/
private static Hover getDefaultHoverObject() {
Hover hover = new Hover();
List<Either<String, MarkedString>> contents = new ArrayList<>();
contents.add(Either.forLeft(""));
hover.setContents(contents);
return hover;
}
use of org.eclipse.lsp4j.Hover in project ballerina by ballerina-lang.
the class HoverUtil method getHoverContent.
/**
* get current hover content.
*
* @param hoverContext text document context for the hover provider.
* @param currentBLangPackage package which currently user working on.
* @return return Hover object.
*/
public static Hover getHoverContent(TextDocumentServiceContext hoverContext, BLangPackage currentBLangPackage, LSPackageCache packageContext) {
PositionTreeVisitor positionTreeVisitor = new PositionTreeVisitor(hoverContext);
currentBLangPackage.accept(positionTreeVisitor);
Hover hover;
// If the cursor is on a node of the current package go inside, else check builtin and native packages.
if (hoverContext.get(NodeContextKeys.PACKAGE_OF_NODE_KEY) != null) {
hover = getHoverInformation(packageContext.findPackage(hoverContext.get(DocumentServiceKeys.COMPILER_CONTEXT_KEY), hoverContext.get(NodeContextKeys.PACKAGE_OF_NODE_KEY)), hoverContext);
} else {
hover = new Hover();
List<Either<String, MarkedString>> contents = new ArrayList<>();
contents.add(Either.forLeft(""));
hover.setContents(contents);
}
return hover;
}
use of org.eclipse.lsp4j.Hover in project ballerina by ballerina-lang.
the class HoverUtil method getDocumentationContent.
/**
* Get documentation content.
*
* @param docAnnotation list of doc annotation
* @return {@link Hover} hover object.
*/
private static Hover getDocumentationContent(List<BLangDocumentation> docAnnotation) {
Hover hover = new Hover();
StringBuilder content = new StringBuilder();
BLangDocumentation bLangDocumentation = docAnnotation.get(0);
Map<String, List<BLangDocumentationAttribute>> filterAttributes = filterDocumentationAttributes(docAnnotation.get(0));
if (!bLangDocumentation.documentationText.isEmpty()) {
content.append(getFormattedHoverDocContent(ContextConstants.DESCRIPTION, bLangDocumentation.documentationText));
}
if (filterAttributes.get(ContextConstants.DOC_RECEIVER) != null) {
content.append(getFormattedHoverDocContent(ContextConstants.DOC_RECEIVER, getDocAttributes(filterAttributes.get(ContextConstants.DOC_RECEIVER))));
}
if (filterAttributes.get(ContextConstants.DOC_PARAM) != null) {
content.append(getFormattedHoverDocContent(ContextConstants.DOC_PARAM, getDocAttributes(filterAttributes.get(ContextConstants.DOC_PARAM))));
}
if (filterAttributes.get(ContextConstants.DOC_FIELD) != null) {
content.append(getFormattedHoverDocContent(ContextConstants.DOC_FIELD, getDocAttributes(filterAttributes.get(ContextConstants.DOC_FIELD))));
}
if (filterAttributes.get(ContextConstants.DOC_RETURN) != null) {
content.append(getFormattedHoverDocContent(ContextConstants.DOC_RETURN, getDocAttributes(filterAttributes.get(ContextConstants.DOC_RETURN))));
}
if (filterAttributes.get(ContextConstants.DOC_VARIABLE) != null) {
content.append(getFormattedHoverDocContent(ContextConstants.DOC_VARIABLE, getDocAttributes(filterAttributes.get(ContextConstants.DOC_VARIABLE))));
}
List<Either<String, MarkedString>> contents = new ArrayList<>();
contents.add(Either.forLeft(content.toString()));
hover.setContents(contents);
return hover;
}
use of org.eclipse.lsp4j.Hover in project sts4 by spring-projects.
the class Editor method assertHoverExactText.
/**
* Verifies an expected text is the hover text that is computed when
* hovering mouse at position at the end of first occurrence of a given
* string in the editor.
*/
public void assertHoverExactText(String afterString, String expectedHover) throws Exception {
int pos = getRawText().indexOf(afterString);
if (pos >= 0) {
pos += afterString.length();
}
Hover hover = harness.getHover(doc, doc.toPosition(pos));
assertEquals(expectedHover, hoverString(hover));
}
use of org.eclipse.lsp4j.Hover in project sts4 by spring-projects.
the class Editor method assertHoverContains.
public void assertHoverContains(String hoverOver, int occurrence, String snippet) throws Exception {
int hoverPosition = getHoverPosition(hoverOver, occurrence);
Hover hover = harness.getHover(doc, doc.toPosition(hoverPosition));
assertContains(snippet, hoverString(hover));
}
Aggregations