Java Code Examples for org.eclipse.lsp4j.Hover

The following examples show how to use org.eclipse.lsp4j.Hover. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: intellij-quarkus   Author: redhat-developer   File: GradleJavaHoverTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testConfigPropertyNameYaml() throws Exception {
	MicroProfileAssert.saveFile(PsiMicroProfileProject.APPLICATION_YAML_FILE,
			"greeting:\n" + "  message: message from yaml\n" + "  number: 2001", javaProject);

	MicroProfileAssert.saveFile(PsiMicroProfileProject.APPLICATION_PROPERTIES_FILE,
			"greeting.message = hello\r\n" + "greeting.name = quarkus\r\n" + "greeting.number = 100", javaProject);

	// Position(14, 40) is the character after the | symbol:
	// @ConfigProperty(name = "greeting.mes|sage")
	Hover info = getActualHover(new Position(14, 40));
	MicroProfileAssert.assertHover("greeting.message", "message from yaml", 14, 28, 44, info);

	// Position(26, 33) is the character after the | symbol:
	// @ConfigProperty(name = "greet|ing.number", defaultValue="0")
	info = getActualHover(new Position(26, 33));
	MicroProfileAssert.assertHover("greeting.number", "2001", 26, 28, 43, info);

	MicroProfileAssert.saveFile(PsiMicroProfileProject.APPLICATION_YAML_FILE, "greeting:\n" + "  message: message from yaml",
			javaProject);

	// fallback to application.properties
	info = getActualHover(new Position(26, 33));
	MicroProfileAssert.assertHover("greeting.number", "100", 26, 28, 43, info);
}
 
Example #2
Source Project: intellij-quarkus   Author: redhat-developer   File: MavenJavaHoverTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testConfigPropertyNameYaml() throws Exception {
	MicroProfileAssert.saveFile(PsiMicroProfileProject.APPLICATION_YAML_FILE,
			"greeting:\n" + "  message: message from yaml\n" + "  number: 2001", javaProject);

	MicroProfileAssert.saveFile(PsiMicroProfileProject.APPLICATION_PROPERTIES_FILE,
			"greeting.message = hello\r\n" + "greeting.name = quarkus\r\n" + "greeting.number = 100", javaProject);

	// Position(14, 40) is the character after the | symbol:
	// @ConfigProperty(name = "greeting.mes|sage")
	Hover info = getActualHover(new Position(14, 40));
	MicroProfileAssert.assertHover("greeting.message", "message from yaml", 14, 28, 44, info);

	// Position(26, 33) is the character after the | symbol:
	// @ConfigProperty(name = "greet|ing.number", defaultValue="0")
	info = getActualHover(new Position(26, 33));
	MicroProfileAssert.assertHover("greeting.number", "2001", 26, 28, 43, info);

	MicroProfileAssert.saveFile(PsiMicroProfileProject.APPLICATION_YAML_FILE, "greeting:\n" + "  message: message from yaml",
			javaProject);

	// fallback to application.properties
	info = getActualHover(new Position(26, 33));
	MicroProfileAssert.assertHover("greeting.number", "100", 26, 28, 43, info);
}
 
Example #3
Source Project: lemminx   Author: eclipse   File: MarkupContentFactory.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Create the hover from the given markup content list and range.
 * 
 * @param values       the list of documentation values
 * @param defaultRange the default range.
 * @return the hover from the given markup content list and range.
 */
public static Hover createHover(List<MarkupContent> values, Range defaultRange) {
	if (values.isEmpty()) {
		return null;
	}
	if (values.size() == 1) {
		return new Hover(values.get(0), defaultRange);
	}
	// Markup kind
	boolean hasMarkdown = values.stream() //
			.anyMatch(contents -> MarkupKind.MARKDOWN.equals(contents.getKind()));
	String markupKind = hasMarkdown ? MarkupKind.MARKDOWN : MarkupKind.PLAINTEXT;
	// Contents
	String content = createContent(values, markupKind);
	// Range
	Range range = defaultRange;
	return new Hover(new MarkupContent(markupKind, content), range);
}
 
Example #4
Source Project: lemminx   Author: eclipse   File: XMLHover.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the LSP hover from the hovered element.
 * 
 * @param hoverRequest the hover request.
 * @param tagRange     the tag range
 * @param open         true if it's the start tag which is hovered and false if
 *                     it's the end tag.
 * @return the LSP hover from the hovered element.
 */
private Hover getTagHover(HoverRequest hoverRequest, Range tagRange, boolean open) {
	hoverRequest.setHoverRange(tagRange);
	hoverRequest.setOpen(open);
	List<Hover> hovers = new ArrayList<>();
	for (IHoverParticipant participant : extensionsRegistry.getHoverParticipants()) {
		try {
			Hover hover = participant.onTag(hoverRequest);
			if (hover != null) {
				hovers.add(hover);
			}
		} catch (Exception e) {
			LOGGER.log(Level.SEVERE, "While performing IHoverParticipant#onTag", e);
		}
	}
	return mergeHover(hovers, tagRange);
}
 
Example #5
Source Project: lemminx   Author: eclipse   File: XMLHover.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the LSP hover from the hovered attribute.
 * 
 * @param hoverRequest the hover request.
 * @param attrRange    the attribute range
 * @return the LSP hover from the hovered attribute.
 */
private Hover getAttrNameHover(HoverRequest hoverRequest, Range attrRange) {
	hoverRequest.setHoverRange(attrRange);
	List<Hover> hovers = new ArrayList<>();
	for (IHoverParticipant participant : extensionsRegistry.getHoverParticipants()) {
		try {
			Hover hover = participant.onAttributeName(hoverRequest);
			if (hover != null) {
				hovers.add(hover);
			}
		} catch (Exception e) {
			LOGGER.log(Level.SEVERE, "While performing IHoverParticipant#onAttributeName", e);
		}
	}
	return mergeHover(hovers, attrRange);
}
 
Example #6
Source Project: lemminx   Author: eclipse   File: XMLHover.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the LSP hover from the hovered attribute.
 * 
 * @param hoverRequest the hover request.
 * @param attrRange    the attribute range
 * @return the LSP hover from the hovered attribute.
 */
private Hover getAttrValueHover(HoverRequest hoverRequest, Range attrRange) {
	hoverRequest.setHoverRange(attrRange);
	List<Hover> hovers = new ArrayList<>();
	for (IHoverParticipant participant : extensionsRegistry.getHoverParticipants()) {
		try {
			Hover hover = participant.onAttributeValue(hoverRequest);
			if (hover != null) {
				hovers.add(hover);
			}
		} catch (Exception e) {
			LOGGER.log(Level.SEVERE, "While performing IHoverParticipant#onAttributeValue", e);
		}
	}
	return mergeHover(hovers, attrRange);
}
 
Example #7
Source Project: lemminx   Author: eclipse   File: XMLHover.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the LSP hover from the hovered text.
 * 
 * @param hoverRequest the hover request.
 * @param attrRange    the attribute range
 * @return the LSP hover from the hovered text.
 */
private Hover getTextHover(HoverRequest hoverRequest, Range textRange) {
	hoverRequest.setHoverRange(textRange);
	List<Hover> hovers = new ArrayList<>();
	for (IHoverParticipant participant : extensionsRegistry.getHoverParticipants()) {
		try {
			Hover hover = participant.onText(hoverRequest);
			if (hover != null) {
				hovers.add(hover);
			}
		} catch (Exception e) {
			LOGGER.log(Level.SEVERE, "While performing IHoverParticipant#onText", e);
		}
	}
	return mergeHover(hovers, textRange);
}
 
Example #8
Source Project: eclipse.jdt.ls   Author: eclipse   File: HoverHandlerTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@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().getLeft().get(0).getRight();
	assertEquals("Unexpected hover " + signature, "java", signature.getLanguage());
	assertEquals("Unexpected hover " + signature, "String[] args - java.Foo.main(String[])", signature.getValue());
}
 
Example #9
Source Project: lemminx   Author: eclipse   File: EntitiesHoverParticipant.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Hover onText(IHoverRequest request) throws Exception {
	DOMNode node = request.getNode();
	if (!node.isText()) {
		return null;
	}
	// Hover is done in a text node, check if it's a entity reference
	DOMDocument document = request.getXMLDocument();
	int offset = request.getOffset();
	EntityReferenceRange entityRange = XMLPositionUtility.selectEntityReference(offset, document);
	if (entityRange == null) {
		return null;
	}
	// The hovered text follows the entity reference syntax (ex : &amp;)
	String entityName = entityRange.getName();
	Range range = entityRange.getRange();
	// Try to find the entity
	MarkupContent entityContents = searchInEntities(entityName, range, document, request);
	if (entityContents != null) {
		return new Hover(entityContents, range);
	}
	return null;
}
 
Example #10
Source Project: lemminx   Author: eclipse   File: ContentModelHoverParticipant.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Hover onTag(IHoverRequest hoverRequest) throws Exception {
	try {
		ContentModelManager contentModelManager = hoverRequest.getComponent(ContentModelManager.class);
		DOMElement element = (DOMElement) hoverRequest.getNode();
		Collection<CMDocument> cmDocuments = contentModelManager.findCMDocument(element);
		if (cmDocuments.isEmpty()) {
			// no bound grammar -> no documentation
			return null;
		}
		// Compute element declaration documentation from bound grammars
		List<MarkupContent> contentValues = new ArrayList<>();
		for (CMDocument cmDocument : cmDocuments) {
			CMElementDeclaration cmElement = cmDocument.findCMElement(element);
			if (cmElement != null) {
				MarkupContent content = XMLGenerator.createMarkupContent(cmElement, hoverRequest);
				fillHoverContent(content, contentValues);
			}
		}
		return createHover(contentValues);
	} catch (CacheResourceDownloadingException e) {
		return getCacheWarningHover(e, hoverRequest);
	}
}
 
Example #11
Source Project: eclipse.jdt.ls   Author: eclipse   File: HoverHandlerTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testInvalidJavadoc() throws Exception {
	importProjects("maven/aspose");
	IProject project = null;
	ICompilationUnit unit = null;
	try {
		project = ResourcesPlugin.getWorkspace().getRoot().getProject("aspose");
		IJavaProject javaProject = JavaCore.create(project);
		IType type = javaProject.findType("org.sample.TestJavadoc");
		unit = type.getCompilationUnit();
		unit.becomeWorkingCopy(null);
		String uri = JDTUtils.toURI(unit);
		TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
		TextDocumentPositionParams position = new TextDocumentPositionParams(textDocument, new Position(8, 24));
		Hover hover = handler.hover(position, monitor);
		assertNotNull(hover);
		assertNotNull(hover.getContents());
		assertEquals(1, hover.getContents().getLeft().size());
		assertEquals("com.aspose.words.Document.Document(String fileName) throws Exception", hover.getContents().getLeft().get(0).getRight().getValue());
	} finally {
		if (unit != null) {
			unit.discardWorkingCopy();
		}
	}
}
 
Example #12
Source Project: eclipse.jdt.ls   Author: eclipse   File: HoverHandlerTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testHoverOnJavadocWithLinkToMethodInClass() throws Exception {
	importProjects("maven/salut");
	project = WorkspaceHelper.getProject("salut");
	handler = new HoverHandler(preferenceManager);
	//given
	String payload = createHoverRequest("src/main/java/java/Foo2.java", 18, 25);
	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().getLeft().size());
	Either<String, MarkedString> javadoc = hover.getContents().getLeft().get(1);
	String content = null;
	assertTrue("javadoc has null content", javadoc != null && javadoc.getLeft() != null && (content = javadoc.getLeft()) != null);
	assertMatches("\\[newMethodBeingLinkedToo\\]\\(file:/.*/salut/src/main/java/java/Foo2.java#23\\)", content);
}
 
Example #13
Source Project: camel-language-server   Author: camel-tooling   File: HoverProcessor.java    License: Apache License 2.0 6 votes vote down vote up
public CompletableFuture<Hover> getHover(Position position) {
	try {
		ParserFileHelper parserFileHelper = new ParserFileHelperFactory().getCorrespondingParserFileHelper(textDocumentItem, position.getLine());
		if (parserFileHelper != null){
			String camelComponentUri = parserFileHelper.getCamelComponentUri(textDocumentItem, position);
			String componentName = StringUtils.asComponentName(camelComponentUri);
			if (componentName != null) {
				CamelURIInstance camelURIInstance = parserFileHelper.createCamelURIInstance(textDocumentItem, position, camelComponentUri);
				int positionInCamelUri = parserFileHelper.getPositionInCamelURI(textDocumentItem, position);
				CamelUriElementInstance elem = camelURIInstance.getSpecificElement(positionInCamelUri);
				return camelCatalog.thenApply(new HoverFuture(elem));
			}
		}
	} catch (Exception e) {
		LOGGER.error("Error searching hover", e);
	}
	return CompletableFuture.completedFuture(null);
}
 
Example #14
Source Project: eclipse.jdt.ls   Author: eclipse   File: HoverHandlerTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testHoverPackage() throws Exception {
	// given
	// Hovers on the java.internal package
	String payload = createHoverRequest("src/java/Baz.java", 2, 16);
	TextDocumentPositionParams position = getParams(payload);

	// when
	Hover hover = handler.hover(position, monitor);

	// then
	assertNotNull(hover);
	String signature = hover.getContents().getLeft().get(0).getRight().getValue();//
	assertEquals("Unexpected signature ", "java.internal", signature);
	String result = hover.getContents().getLeft().get(1).getLeft();//
	assertEquals("Unexpected hover ", "this is a **bold** package!", result);
}
 
Example #15
Source Project: eclipse.jdt.ls   Author: eclipse   File: HoverHandlerTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testEmptyHover() throws Exception {
	//given
	//Hovers on the System.out
	URI standalone = Paths.get("projects", "maven", "salut", "src", "main", "java", "java", "Foo.java").toUri();
	String payload = createHoverRequest(standalone, 1, 2);
	TextDocumentPositionParams position = getParams(payload);

	//when
	Hover hover = handler.hover(position, monitor);

	//then
	assertNotNull(hover);
	assertNotNull(hover.getContents());
	assertEquals(1, hover.getContents().getLeft().size());
	assertEquals("Should find empty hover for " + payload, "", hover.getContents().getLeft().get(0).getLeft());
}
 
Example #16
Source Project: syndesis   Author: syndesisio   File: TeiidDdlTextDocumentService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<Hover> hover(TextDocumentPositionParams position) {
    /*
     * LOGGER.debug("hover: {}", position.getTextDocument()); TextDocumentItem
     * textDocumentItem = openedDocuments.get(position.getTextDocument().getUri());
     * String htmlContent = new
     * HoverProcessor(textDocumentItem).getHover(position.getPosition()); Hover
     * hover = new Hover();
     * hover.setContents(Collections.singletonList((Either.forLeft(htmlContent))));
     * LOGGER.debug("hover: {}", position.getTextDocument()); Hover hover = new
     * Hover(); hover.setContents(Collections.singletonList((Either.
     * forLeft("HELLO HOVER WORLD!!!!"))));
     */
    Hover result = null;
    return CompletableFuture.completedFuture(result);
}
 
Example #17
Source Project: eclipse.jdt.ls   Author: eclipse   File: SyntaxServerTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testHover() throws Exception {
	URI fileURI = openFile("maven/salut4", "src/main/java/java/TestJavadoc.java");
	String fileUri = ResourceUtils.fixURI(fileURI);
	TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileUri);
	HoverParams params = new HoverParams(identifier, new Position(8, 23));
	Hover result = server.hover(params).join();
	assertNotNull(result);
	assertNotNull(result.getContents());
	assertTrue(result.getContents().isLeft());
	List<Either<String, MarkedString>> list = result.getContents().getLeft();
	assertNotNull(list);
	assertEquals(2, list.size());
	assertTrue(list.get(1).isLeft());
	assertEquals("Test", list.get(1).getLeft());
}
 
Example #18
Source Project: eclipse.jdt.ls   Author: eclipse   File: SyntaxServerTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testHoverUnresolvedType() throws Exception {
	URI fileURI = openFile("maven/salut4", "src/main/java/java/Foo.java");
	String fileUri = ResourceUtils.fixURI(fileURI);
	TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileUri);
	HoverParams params = new HoverParams(identifier, new Position(7, 30));
	Hover result = server.hover(params).join();
	assertNotNull(result);
	assertNotNull(result.getContents());
	assertTrue(result.getContents().isLeft());
	List<Either<String, MarkedString>> list = result.getContents().getLeft();
	assertNotNull(list);
	assertEquals(2, list.size());
	assertTrue(list.get(1).isLeft());
	assertEquals("This is interface IFoo.", list.get(1).getLeft());
}
 
Example #19
Source Project: eclipse.jdt.ls   Author: eclipse   File: HoverHandlerTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testHoverOnPackageWithJavadoc() throws Exception {
	importProjects("maven/salut2");
	project = WorkspaceHelper.getProject("salut2");
	handler = new HoverHandler(preferenceManager);
	//given
	//Hovers on the org.apache.commons import
	String payload = createHoverRequest("src/main/java/foo/Bar.java", 2, 22);
	TextDocumentPositionParams position = getParams(payload);

	//when
	Hover hover = handler.hover(position, monitor);
	assertNotNull(hover);
	String result = hover.getContents().getLeft().get(0).getRight().getValue();//
	assertEquals("Unexpected hover ", "org.apache.commons", result);

	assertEquals(logListener.getErrors().toString(), 0, logListener.getErrors().size());
}
 
Example #20
Source Project: groovy-language-server   Author: prominic   File: GroovyServices.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Hover> hover(TextDocumentPositionParams params) {
	URI uri = URI.create(params.getTextDocument().getUri());
	recompileIfContextChanged(uri);

	HoverProvider provider = new HoverProvider(astVisitor);
	return provider.provideHover(params.getTextDocument(), params.getPosition());
}
 
Example #21
Source Project: xtext-core   Author: eclipse   File: LanguageServerImpl.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Compute the hover. Executed in a read request.
 * @since 2.20
 */
protected Hover hover(HoverParams params, CancelIndicator cancelIndicator) {
	URI uri = getURI(params);
	IHoverService hoverService = getService(uri, IHoverService.class);
	if (hoverService == null) {
		return IHoverService.EMPTY_HOVER;
	}
	return workspaceManager.<Hover>doRead(uri,
			(document, resource) -> hoverService.hover(document, resource, params, cancelIndicator));
}
 
Example #22
Source Project: intellij-quarkus   Author: redhat-developer   File: LSPTextHover.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected static @Nullable String getHoverString(Hover hover) {
    Either<List<Either<String, MarkedString>>, MarkupContent> hoverContent = hover.getContents();
    if (hoverContent.isLeft()) {
        List<Either<String, MarkedString>> contents = hoverContent.getLeft();
        if (contents == null || contents.isEmpty()) {
            return null;
        }
        return contents.stream().map(content -> {
            if (content.isLeft()) {
                return content.getLeft();
            } else if (content.isRight()) {
                MarkedString markedString = content.getRight();
                // TODO this won't work fully until markup parser will support syntax
                // highlighting but will help display
                // strings with language tags, e.g. without it things after <?php tag aren't
                // displayed
                if (markedString.getLanguage() != null && !markedString.getLanguage().isEmpty()) {
                    return String.format("```%s%n%s%n```", markedString.getLanguage(), markedString.getValue()); //$NON-NLS-1$
                } else {
                    return markedString.getValue();
                }
            } else {
                return ""; //$NON-NLS-1$
            }
        }).filter(((Predicate<String>) String::isEmpty).negate()).collect(Collectors.joining("\n\n")); //$NON-NLS-1$ )
    } else {
        return hoverContent.getRight().getValue();
    }
}
 
Example #23
Source Project: intellij-quarkus   Author: redhat-developer   File: PropertiesManagerForJava.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private void collectHover(String uri, PsiFile typeRoot, PsiElement hoverElement, IPsiUtils utils,
                          Position hoverPosition, DocumentFormat documentFormat, List<Hover> hovers) {
    try {
        VirtualFile file = utils.findFile(uri);
        if (file != null) {
            Module module = utils.getModule(file);
            if (module != null) {
                // Collect all adapted hover participant
                JavaHoverContext context = new JavaHoverContext(uri, typeRoot, utils, module, hoverElement, hoverPosition,
                        documentFormat);
                List<IJavaHoverParticipant> definitions = IJavaHoverParticipant.EP_NAME.extensions()
                        .filter(definition -> definition.isAdaptedForHover(context)).collect(Collectors.toList());
                if (definitions.isEmpty()) {
                    return;
                }

                // Begin, collect, end participants
                definitions.forEach(definition -> definition.beginHover(context));
                definitions.forEach(definition -> {
                    Hover hover = definition.collectHover(context);
                    if (hover != null) {
                        hovers.add(hover);
                    }
                });
                definitions.forEach(definition -> definition.endHover(context));
            }
        }
    } catch (IOException e) {
        LOGGER.error(e.getLocalizedMessage(), e);
    }
}
 
Example #24
Source Project: intellij-quarkus   Author: redhat-developer   File: GradleJavaHoverTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private Hover getActualHover(Position hoverPosition) {
	MicroProfileJavaHoverParams params = new MicroProfileJavaHoverParams();
	params.setDocumentFormat(DocumentFormat.Markdown);
	params.setPosition(hoverPosition);
	params.setUri(javaFileUri);

	return PropertiesManagerForJava.getInstance().hover(params, PsiUtilsImpl.getInstance());
}
 
Example #25
Source Project: eclipse.jdt.ls   Author: eclipse   File: HoverHandlerTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testHoverUnresolvedType() throws Exception {
	importProjects("eclipse/unresolvedtype");
	project = WorkspaceHelper.getProject("unresolvedtype");
	handler = new HoverHandler(preferenceManager);
	//given
	//Hovers on the IFoo
	String payload = createHoverRequest("src/pckg/Foo.java", 2, 31);
	TextDocumentPositionParams position = getParams(payload);

	// when
	Hover hover = handler.hover(position, monitor);
	assertNotNull(hover);
	assertTrue("Unexpected hover ", hover.getContents().getLeft().isEmpty());
}
 
Example #26
Source Project: eclipse.jdt.ls   Author: eclipse   File: HoverHandlerTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testMissingUnit() throws Exception {
	URI uri = Paths.get("projects", "maven", "salut", "src", "main", "java", "java", "Missing.java").toUri();
	String payload = createHoverRequest(uri, 0, 0);
	TextDocumentPositionParams position = getParams(payload);

	//when
	Hover hover = handler.hover(position, monitor);

	//then
	assertNotNull(hover);
	assertNotNull(hover.getContents());
	assertEquals(1, hover.getContents().getLeft().size());
	assertEquals("Should find empty hover for " + payload, "", hover.getContents().getLeft().get(0).getLeft());
}
 
Example #27
Source Project: intellij-quarkus   Author: redhat-developer   File: MicroProfileAssert.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public static void assertHover(String expectedKey, String expectedValue, int expectedLine, int expectedStartOffset,
							   int expectedEndOffset, Hover actualInfo) {
	Assert.assertNotNull(actualInfo);

	Position expectedStart = new Position(expectedLine, expectedStartOffset);
	Position expectedEnd = new Position(expectedLine, expectedEndOffset);
	Range expectedRange = new Range(expectedStart, expectedEnd);

	MarkupContent expectedContent = MicroProfileConfigHoverParticipant.getDocumentation(expectedKey, expectedValue,
			DocumentFormat.Markdown, true);

	Assert.assertEquals(expectedContent, actualInfo.getContents().getRight());
	Assert.assertEquals(expectedRange, actualInfo.getRange());
}
 
Example #28
Source Project: lsp4j   Author: eclipse   File: HoverTypeAdapter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public void write(final JsonWriter out, final Hover value) throws IOException {
  if (value == null) {
  	out.nullValue();
  	return;
  }
  
  out.beginObject();
  out.name("contents");
  writeContents(out, value.getContents());
  out.name("range");
  writeRange(out, value.getRange());
  out.endObject();
}
 
Example #29
Source Project: xtext-core   Author: eclipse   File: HoverService.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected Hover hover(HoverContext context) {
	if (context == null) {
		return IHoverService.EMPTY_HOVER;
	}
	MarkupContent contents = getMarkupContent(context);
	if (contents == null) {
		return IHoverService.EMPTY_HOVER;
	}
	Range range = getRange(context);
	if (range == null) {
		return IHoverService.EMPTY_HOVER;
	}
	return new Hover(contents, range);
}
 
Example #30
Source Project: lemminx   Author: eclipse   File: XSISchemaModel.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public static Hover computeHoverResponse(DOMAttr attribute, IHoverRequest request) {

		String name = attribute.getName();
		if(!name.startsWith(request.getXMLDocument().getSchemaInstancePrefix() + ":")) {
			return null;
		}

		DOMDocument document = request.getXMLDocument();
		DOMElement root = document.getDocumentElement();
		String doc = null;
		if(root != null) {
			if(root.equals(document.findNodeAt(attribute.getStart()))) {
				if(name.endsWith(":schemaLocation")) {
					doc = SCHEMA_LOCATION_DOC;
				}
				else if(name.endsWith(":noNamespaceSchemaLocation")) {
					doc = NO_NAMESPACE_SCHEMA_LOCATION_DOC;
				}
			}
		} else {
			return null;
		}
		if(doc == null) {
			if(name.endsWith(":nil")) {
				doc = NIL_DOC;
			}
			else if(name.endsWith(":type")) {
				doc = TYPE_DOC;
			}
			else {
				return null;
			}
		}

		MarkupContent content = new MarkupContent();
		content.setKind(MarkupKind.MARKDOWN);
		content.setValue(doc);
		return new Hover(content);
	}