org.eclipse.lsp4j.Hover Java Examples
The following examples show how to use
org.eclipse.lsp4j.Hover.
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 File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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 #2
Source File: GradleJavaHoverTest.java From intellij-quarkus with Eclipse Public License 2.0 | 6 votes |
@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 File: MavenJavaHoverTest.java From intellij-quarkus with Eclipse Public License 2.0 | 6 votes |
@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 #4
Source File: MarkupContentFactory.java From lemminx with Eclipse Public License 2.0 | 6 votes |
/** * 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 #5
Source File: XMLHover.java From lemminx with Eclipse Public License 2.0 | 6 votes |
/** * 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 #6
Source File: XMLHover.java From lemminx with Eclipse Public License 2.0 | 6 votes |
/** * 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 #7
Source File: XMLHover.java From lemminx with Eclipse Public License 2.0 | 6 votes |
/** * 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 #8
Source File: XMLHover.java From lemminx with Eclipse Public License 2.0 | 6 votes |
/** * 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 #9
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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 #10
Source File: EntitiesHoverParticipant.java From lemminx with Eclipse Public License 2.0 | 6 votes |
@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 : &) 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 #11
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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 File: HoverProcessor.java From camel-language-server with Apache License 2.0 | 6 votes |
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 #13
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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 #14
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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 #15
Source File: TeiidDdlTextDocumentService.java From syndesis with Apache License 2.0 | 6 votes |
@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 #16
Source File: SyntaxServerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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 #17
Source File: ContentModelHoverParticipant.java From lemminx with Eclipse Public License 2.0 | 6 votes |
@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 #18
Source File: SyntaxServerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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 File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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 #20
Source File: CamelLanguageServerHoverTest.java From camel-language-server with Apache License 2.0 | 5 votes |
@Test void testDontProvideDocumentationOnHoverWhenEndingWithAnd() throws Exception { CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"ahc:httpUri?test=test&\" xmlns=\"http://camel.apache.org/schema/spring\"></from>\n"); HoverParams hoverParams = new HoverParams(new TextDocumentIdentifier(DUMMY_URI+".xml"), new Position(0, 15)); CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(hoverParams); assertThat(hover.get()).isNull(); }
Example #21
Source File: HoverFuture.java From camel-language-server with Apache License 2.0 | 5 votes |
@Override public Hover apply(CamelCatalog camelCatalog) { String componentJSonSchema = camelCatalog.componentJSonSchema(uriElement.getComponentName()); if (componentJSonSchema != null) { Hover hover = new Hover(); ComponentModel componentModel = ModelHelper.generateComponentModel(componentJSonSchema, true); hover.setContents(Collections.singletonList((Either.forLeft(uriElement.getDescription(componentModel))))); return hover; } return null; }
Example #22
Source File: CamelKModelineOptionNamesHoverTest.java From camel-language-server with Apache License 2.0 | 5 votes |
@Test void testNoErrorOnUnknwonOption() throws Exception { CamelLanguageServer camelLanguageServer = initializeLanguageServer("// camel-k: unknown=quarkus.enabled=true", ".java"); HoverParams hoverParams = new HoverParams(new TextDocumentIdentifier(DUMMY_URI+".java"), new Position(0, 14)); CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(hoverParams); assertThat(hover.get()).isNull(); }
Example #23
Source File: TestTypeScript.java From wildwebdeveloper with Eclipse Public License 2.0 | 5 votes |
@Test public void testHTMLinTSXFile() throws Exception { IFile file = project.getFile("test.tsx"); file.create(getClass().getResourceAsStream("/testProjects/htmlIn.tsx"), true, null); AbstractTextEditor editor = (AbstractTextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); IDocument document = LSPEclipseUtils.getDocument(editor); DisplayHelper.sleep(2000); // Give time for LS to initialize enough before making edit and sending a didChange HoverParams params = new HoverParams(new TextDocumentIdentifier(LSPEclipseUtils.toUri(document).toString()), new Position(0, 18)); Hover hover = LanguageServiceAccessor.getLanguageServers(document, null).get().get(0).getTextDocumentService().hover(params).get(); Assert.assertTrue(hover.getContents().toString().contains("button")); }
Example #24
Source File: StringLSP4J.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** @return string for given element */ public String toString(Hover hover) { if (hover == null) { return ""; } String str = toString(hover.getRange()) + " " + toString1(hover.getContents()); return str; }
Example #25
Source File: AggregetedHoverValuesTest.java From lemminx with Eclipse Public License 2.0 | 5 votes |
@Override public Hover onAttributeName(IHoverRequest request) throws Exception { if ("class".equals(request.getCurrentAttributeName())) { return createHover(TEST_FOR_ATTRIBUTENAME_HOVER); } return null; }
Example #26
Source File: AggregetedHoverValuesTest.java From lemminx with Eclipse Public License 2.0 | 5 votes |
@Override public Hover onTag(IHoverRequest request) throws Exception { if ("bean".equals(request.getCurrentTag())) { return createHover(TEST_FOR_TAG_HOVER); } return null; }
Example #27
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testHoverInheritedJavadoc() throws Exception { // given // Hovers on the overriding foo() String payload = createHoverRequest("src/java/Bar.java", 22, 19); TextDocumentPositionParams position = getParams(payload); // when Hover hover = handler.hover(position, monitor); // then assertNotNull(hover); String result = hover.getContents().getLeft().get(1).getLeft();// assertEquals("Unexpected hover ", "This method comes from Foo", result); }
Example #28
Source File: XLanguageServerImpl.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Compute the hover. Executed in a read request. */ protected Hover hover(OpenFileContext ofc, TextDocumentPositionParams params, CancelIndicator cancelIndicator) { URI uri = ofc.getURI(); IHoverService hoverService = getService(uri, IHoverService.class); if (hoverService == null) { return IHoverService.EMPTY_HOVER; } XtextResource res = ofc.getResource(); XDocument doc = ofc.getDocument(); return hoverService.hover(doc, res, params, cancelIndicator); }
Example #29
Source File: GroovyServices.java From groovy-language-server with Apache License 2.0 | 5 votes |
@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 #30
Source File: CamelKModelineOption.java From camel-language-server with Apache License 2.0 | 5 votes |
public CompletableFuture<Hover> getHover(int characterPosition) { if(getStartPositionInLine() <= characterPosition && characterPosition <= getStartPositionInLine() + optionName.length()) { String description = CamelKModelineOptionNames.getDescription(optionName); if(description != null) { return CompletableFuture.completedFuture(new Hover(Collections.singletonList((Either.forLeft(description))))); } } return CompletableFuture.completedFuture(null); }