org.eclipse.lsp4j.MarkedString Java Examples
The following examples show how to use
org.eclipse.lsp4j.MarkedString.
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 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 #2
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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().getLeft().get(0).getRight(); assertEquals("Unexpected hover " + signature, "java", signature.getLanguage()); assertEquals("Unexpected hover " + signature, "java.Foo", signature.getValue()); String doc = hover.getContents().getLeft().get(1).getLeft(); assertEquals("Unexpected hover " + doc, "This is foo", doc); }
Example #3
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testHoverStandalone() 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, 10, 71); TextDocumentPositionParams position = getParams(payload); //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, "java.Foo", signature.getValue()); String doc = hover.getContents().getLeft().get(1).getLeft(); assertEquals("Unexpected hover " + doc, "This is foo", doc); }
Example #4
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 #5
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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().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); 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:**")); }
Example #6
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 #7
Source File: SyntaxServerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testHoverType() 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(11, 9)); 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 Bar.", list.get(1).getLeft()); }
Example #8
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 #9
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testHoverOnJavadocWithValueTag() throws Exception { importProjects("maven/salut"); project = WorkspaceHelper.getProject("salut"); handler = new HoverHandler(preferenceManager); //given String payload = createHoverRequest("src/main/java/java/Foo2.java", 12, 30); 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("\\[\"SimpleStringData\"\\]\\(file:/.*/salut/src/main/java/java/Foo2.java#13\\) is a simple String", content); }
Example #10
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testHoverOnJavadocWithLinkToMethodInOtherClass() throws Exception { importProjects("maven/salut"); project = WorkspaceHelper.getProject("salut"); handler = new HoverHandler(preferenceManager); //given String payload = createHoverRequest("src/main/java/java/Foo2.java", 29, 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("\\[Foo.linkedFromFoo2\\(\\)\\]\\(file:/.*/salut/src/main/java/java/Foo.java#14\\)", content); }
Example #11
Source File: N4JSHoverService.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override protected List<Either<String, MarkedString>> getContents(HoverContext ctx) { List<Either<String, MarkedString>> contents = new LinkedList<>(); EObject element = ctx.getElement(); EObject idRef = getIdentifierRefOrElement(ctx); String signature = signatureProvider.get(idRef); if (signature != null) { String keyword = keywordProvider.keyword(element); String signatureLabel = composeFirstLine(keyword, signature); CharSequence signatureAdoc = html2adocConverter.transformHTML(signatureLabel); MarkedString mdSignatureLabel = new MarkedString("n4js", signatureAdoc.toString()); contents.add(Either.forRight(mdSignatureLabel)); } String documentation = documentationProvider.getDocumentation(element); if (documentation != null) { CharSequence docuAdoc = html2adocConverter.transformHTML(documentation); MarkedString mdDocumentation = new MarkedString(MARKUP_KIND_MARKDOWN, docuAdoc.toString()); contents.add(Either.forRight(mdDocumentation)); } return contents; }
Example #12
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testHoverWhenLinkDoesNotExist() throws Exception { importProjects("maven/salut"); project = WorkspaceHelper.getProject("salut"); handler = new HoverHandler(preferenceManager); //given String payload = createHoverRequest("src/main/java/java/Foo2.java", 51, 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("This link doesnt work LinkToSomethingNotFound", content); }
Example #13
Source File: HoverTypeAdapter.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
protected Either<List<Either<String, MarkedString>>, MarkupContent> readContents(final JsonReader in) throws IOException { final JsonToken nextToken = in.peek(); boolean _equals = Objects.equal(nextToken, JsonToken.STRING); if (_equals) { final List<Either<String, MarkedString>> value = CollectionLiterals.<Either<String, MarkedString>>newArrayList(Either.<String, MarkedString>forLeft(in.nextString())); return Either.<List<Either<String, MarkedString>>, MarkupContent>forLeft(value); } else { boolean _equals_1 = Objects.equal(nextToken, JsonToken.BEGIN_ARRAY); if (_equals_1) { final List<Either<String, MarkedString>> value_1 = this.gson.<List<Either<String, MarkedString>>>fromJson(in, HoverTypeAdapter.LIST_STRING_MARKEDSTRING.getType()); return Either.<List<Either<String, MarkedString>>, MarkupContent>forLeft(value_1); } else { JsonElement _parse = new JsonParser().parse(in); final JsonObject object = ((JsonObject) _parse); boolean _has = object.has("language"); if (_has) { final List<Either<String, MarkedString>> value_2 = CollectionLiterals.<Either<String, MarkedString>>newArrayList(Either.<String, MarkedString>forRight(this.gson.<MarkedString>fromJson(object, MarkedString.class))); return Either.<List<Either<String, MarkedString>>, MarkupContent>forLeft(value_2); } else { return Either.<List<Either<String, MarkedString>>, MarkupContent>forRight(this.gson.<MarkupContent>fromJson(object, MarkupContent.class)); } } } }
Example #14
Source File: HoverTypeAdapter.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
protected void writeContents(final JsonWriter out, final Either<List<Either<String, MarkedString>>, MarkupContent> contents) throws IOException { boolean _isLeft = contents.isLeft(); if (_isLeft) { final List<Either<String, MarkedString>> list = contents.getLeft(); int _size = list.size(); boolean _equals = (_size == 1); if (_equals) { this.gson.toJson(list.get(0), HoverTypeAdapter.STRING_MARKEDSTRING.getType(), out); } else { this.gson.toJson(list, HoverTypeAdapter.LIST_STRING_MARKEDSTRING.getType(), out); } } else { this.gson.toJson(contents.getRight(), MarkupContent.class, out); } }
Example #15
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private String getTitleHover(ICompilationUnit cu, int line, int character) { // when Hover hover = getHover(cu, line, character); // then assertNotNull(hover); MarkedString result = hover.getContents().getLeft().get(0).getRight(); return result.getValue(); }
Example #16
Source File: Hover.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
public void setContents(final List<Either<String, MarkedString>> contents) { if (contents == null) { Preconditions.checkNotNull(contents, "contents"); this.contents = null; return; } this.contents = Either.forLeft(contents); }
Example #17
Source File: HoverProvider.java From groovy-language-server with Apache License 2.0 | 5 votes |
public CompletableFuture<Hover> provideHover(TextDocumentIdentifier textDocument, Position position) { Hover hover = new Hover(); List<Either<String, MarkedString>> contents = new ArrayList<>(); hover.setContents(contents); if (ast == null) { //this shouldn't happen, but let's avoid an exception if something //goes terribly wrong. return CompletableFuture.completedFuture(hover); } URI uri = URI.create(textDocument.getUri()); ASTNode offsetNode = ast.getNodeAtLineAndColumn(uri, position.getLine(), position.getCharacter()); if (offsetNode == null) { return CompletableFuture.completedFuture(hover); } ASTNode definitionNode = GroovyASTUtils.getDefinition(offsetNode, false, ast); if (definitionNode == null) { return CompletableFuture.completedFuture(hover); } String content = getContent(definitionNode); if (content == null) { return CompletableFuture.completedFuture(hover); } contents.add(Either.forRight(new MarkedString("groovy", content))); return CompletableFuture.completedFuture(hover); }
Example #18
Source File: JavadocContentTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testMethodJavadoc() throws Exception { IType type = project.findType("org.sample.TestJavadoc"); assertNotNull(type); IMethod method = type.getMethod("foo", new String[0]); assertNotNull(method); MarkedString signature = HoverInfoProvider.computeSignature(method); assertEquals("String org.sample.TestJavadoc.foo()", signature.getValue()); MarkedString javadoc = HoverInfoProvider.computeJavadoc(method); assertEquals("Foo method", javadoc.getValue()); }
Example #19
Source File: JavadocContentTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testFieldJavadoc() throws Exception { IType type = project.findType("org.sample.TestJavadoc"); assertNotNull(type); IField field = type.getField("fooField"); assertNotNull(field); MarkedString signature = HoverInfoProvider.computeSignature(field); assertEquals("int fooField", signature.getValue()); MarkedString javadoc = HoverInfoProvider.computeJavadoc(field); assertEquals("Foo field", javadoc.getValue()); }
Example #20
Source File: JavadocContentTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testClassJavadoc() throws Exception { IType type = project.findType("org.sample.TestJavadoc"); assertNotNull(type); MarkedString signature = HoverInfoProvider.computeSignature(type); assertEquals("org.sample.TestJavadoc", signature.getValue()); MarkedString javadoc = HoverInfoProvider.computeJavadoc(type); assertEquals("Test javadoc class", javadoc.getValue()); }
Example #21
Source File: HoverHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public Hover hover(TextDocumentPositionParams position, IProgressMonitor monitor) { ITypeRoot unit = JDTUtils.resolveTypeRoot(position.getTextDocument().getUri()); List<Either<String, MarkedString>> content = null; if (unit != null && !monitor.isCanceled()) { content = computeHover(unit, position.getPosition().getLine(), position.getPosition().getCharacter(), monitor); } else { content = Collections.singletonList(Either.forLeft("")); } Hover $ = new Hover(); $.setContents(content); return $; }
Example #22
Source File: StringLSP4J.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** @return string for given element */ public String toString(MarkedString markedStr) { if (markedStr == null) { return ""; } return "[" + markedStr.getLanguage() + "] " + markedStr.getValue(); }
Example #23
Source File: StringLSP4J.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** @return string for given element */ public String toString2(Either<String, MarkedString> ms) { if (ms == null) { return ""; } if (ms.isLeft()) { return ms.getLeft(); } else { return toString(ms.getRight()); } }
Example #24
Source File: StringLSP4J.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** @return string for given element */ public String toString1(Either<List<Either<String, MarkedString>>, MarkupContent> contents) { if (contents == null) { return ""; } if (contents.isLeft()) { List<Either<String, MarkedString>> markedStrings = contents.getLeft(); return Strings.toString(this::toString2, markedStrings); } else { return toString(contents.getRight()); } }
Example #25
Source File: XMLAssert.java From lemminx with Eclipse Public License 2.0 | 5 votes |
private static String getHoverLabel(Hover hover) { Either<List<Either<String, MarkedString>>, MarkupContent> contents = hover != null ? hover.getContents() : null; if (contents == null) { return null; } return contents.getRight().getValue(); }
Example #26
Source File: LSPTextHover.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
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 #27
Source File: HoverInfoProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private List<Either<String, MarkedString>> cancelled(List<Either<String, MarkedString>> res) { res.clear(); res.add(Either.forLeft("")); return res; }
Example #28
Source File: HoverHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private List<Either<String, MarkedString>> computeHover(ITypeRoot unit, int line, int column, IProgressMonitor monitor) { HoverInfoProvider provider = new HoverInfoProvider(unit, this.preferenceManager); return provider.computeHover(line, column, monitor); }
Example #29
Source File: HoverHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Test public void testHoverOnJavadocWithMultipleDifferentTypesOfTags() throws Exception { importProjects("maven/salut"); project = WorkspaceHelper.getProject("salut"); handler = new HoverHandler(preferenceManager); //given String payload = createHoverRequest("src/main/java/java/Foo2.java", 44, 24); 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); //@formatter:off String expectedJavadoc = "This Javadoc contains a link to \\[newMethodBeingLinkedToo\\]\\(file:/.*/salut/src/main/java/java/Foo2.java#23\\)\n" + "\n" + " \\* \\*\\*Parameters:\\*\\*\n" + " \n" + " \\* \\*\\*someString\\*\\* the string to enter\n" + " \\* \\*\\*Returns:\\*\\*\n" + " \n" + " \\* String\n" + " \\* \\*\\*Throws:\\*\\*\n" + " \n" + " \\* IOException\n" + " \\* \\*\\*Since:\\*\\*\n" + " \n" + " \\* 0.0.1\n" + " \\* \\*\\*Version:\\*\\*\n" + " \n" + " \\* 0.0.1\n" + " \\* \\*\\*Author:\\*\\*\n" + " \n" + " \\* jpinkney\n" + " \\* \\*\\*See Also:\\*\\*\n" + " \n" + " \\* \\[Online docs for java\\]\\(https://docs.oracle.com/javase/7/docs/api/\\)\n" + " \\* \\*\\*API Note:\\*\\*\n" + " \n" + " \\* This is a note"; //@formatter:on assertMatches(expectedJavadoc, content); }
Example #30
Source File: Hover.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
public Hover(@NonNull final List<Either<String, MarkedString>> contents) { this.setContents(Preconditions.<List<Either<String, MarkedString>>>checkNotNull(contents, "contents")); }