Switch HTML hover tests to markdown tests
This commit is contained in:
@@ -11,8 +11,7 @@
|
||||
package org.springframework.ide.vscode.commons.util;
|
||||
|
||||
/**
|
||||
* Placeholder. Still need to figure out what exactly we should do with this in
|
||||
* vscode. TODO: rename to Renderable
|
||||
* Renderable can be rendered with various mark-up languages
|
||||
*/
|
||||
public interface Renderable {
|
||||
|
||||
|
||||
@@ -95,6 +95,44 @@ public class Renderables {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Renderable paragraph(Renderable text) {
|
||||
return new Renderable() {
|
||||
|
||||
@Override
|
||||
public void renderAsMarkdown(StringBuilder buffer) {
|
||||
buffer.append("\n");
|
||||
text.renderAsMarkdown(buffer);
|
||||
buffer.append("\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderAsHtml(HtmlBuffer buffer) {
|
||||
buffer.raw("<p>");
|
||||
text.renderAsHtml(buffer);
|
||||
buffer.raw("</p>");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Renderable strikeThrough(Renderable text) {
|
||||
return new Renderable() {
|
||||
|
||||
@Override
|
||||
public void renderAsMarkdown(StringBuilder buffer) {
|
||||
buffer.append("~~");
|
||||
text.renderAsMarkdown(buffer);
|
||||
buffer.append("~~");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderAsHtml(HtmlBuffer buffer) {
|
||||
buffer.raw("<s>");
|
||||
text.renderAsHtml(buffer);
|
||||
buffer.raw("</s>");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Renderable link(String text, String url) {
|
||||
return new Renderable() {
|
||||
@@ -127,7 +165,11 @@ public class Renderables {
|
||||
|
||||
@Override
|
||||
public void renderAsMarkdown(StringBuilder buffer) {
|
||||
buffer.append("\n\n");
|
||||
if (buffer.charAt(buffer.length() - 1) != '\n') {
|
||||
// 2 spaces and then new line would create a line break in text
|
||||
buffer.append(" ");
|
||||
}
|
||||
buffer.append("\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -230,7 +272,7 @@ public class Renderables {
|
||||
|
||||
private Renderable[] pieces;
|
||||
|
||||
ConcatRenderables(Renderable[] pieces) {
|
||||
ConcatRenderables(Renderable... pieces) {
|
||||
this.pieces = pieces;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ public class YPropertyHoverInfo {
|
||||
|
||||
Renderable description = prop.getDescription();
|
||||
if (description != null) {
|
||||
html.add(lineBreak());
|
||||
html.add(lineBreak());
|
||||
html.add(description);
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ import java.util.Optional;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.PropertyInfo;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.SpringPropertyIndex;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.hints.StsValueHint;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.hover.PropertyRenderableProvider;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.types.Type;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.types.TypeUtil;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.types.TypeUtil.EnumCaseMode;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.util.FuzzyMap;
|
||||
import org.springframework.ide.vscode.boot.properties.tools.PropertyRenderableProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.BadLocationException;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.DocumentRegion;
|
||||
|
||||
@@ -8,16 +8,19 @@
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.application.properties.metadata.hover;
|
||||
package org.springframework.ide.vscode.boot.properties.tools;
|
||||
|
||||
import static org.springframework.ide.vscode.commons.util.Renderables.*;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.util.HtmlBuffer;
|
||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
import org.springframework.ide.vscode.commons.util.Renderables;
|
||||
import org.springframework.ide.vscode.commons.util.StringUtil;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
|
||||
public abstract class AbstractPropertyRenderableProvider {
|
||||
|
||||
/**
|
||||
@@ -27,71 +30,45 @@ public abstract class AbstractPropertyRenderableProvider {
|
||||
private static final String ACTION_HOST = "action";
|
||||
|
||||
public Renderable getRenderable() {
|
||||
return new Renderable() {
|
||||
Builder<Renderable> renderableBuilder = ImmutableList.builder();
|
||||
|
||||
@Override
|
||||
public void renderAsHtml(HtmlBuffer buffer) {
|
||||
// JavaTypeLinks jtLinks = new JavaTypeLinks(this);
|
||||
|
||||
renderId(buffer);
|
||||
|
||||
String type = getType();
|
||||
if (type==null) {
|
||||
type = Object.class.getName();
|
||||
}
|
||||
// jtLinks.javaTypeLink(html, getJavaProject(), type);
|
||||
actionLink(buffer, type);
|
||||
|
||||
String deflt = formatDefaultValue(getDefaultValue());
|
||||
if (deflt!=null) {
|
||||
buffer.raw("<br><br>");
|
||||
buffer.text("Default: ");
|
||||
buffer.raw("<i>");
|
||||
buffer.text(deflt);
|
||||
buffer.raw("</i>");
|
||||
}
|
||||
|
||||
if (isDeprecated()) {
|
||||
buffer.raw("<br><br>");
|
||||
String reason = getDeprecationReason();
|
||||
if (StringUtil.hasText(reason)) {
|
||||
buffer.bold("Deprecated: ");
|
||||
buffer.text(reason);
|
||||
} else {
|
||||
buffer.bold("Deprecated!");
|
||||
}
|
||||
}
|
||||
|
||||
Renderable description = getDescription();
|
||||
if (description!=null) {
|
||||
buffer.raw("<br><br>");
|
||||
buffer.p(description.toHtml());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderAsMarkdown(StringBuilder buffer) {
|
||||
buffer.append(Renderables.getHtmlToMarkdownConverter().convert(toHtml()));
|
||||
}
|
||||
|
||||
};
|
||||
renderId(renderableBuilder);
|
||||
|
||||
String type = getType();
|
||||
if (type==null) {
|
||||
type = Object.class.getName();
|
||||
}
|
||||
actionLink(renderableBuilder, type);
|
||||
|
||||
String deflt = formatDefaultValue(getDefaultValue());
|
||||
if (deflt!=null) {
|
||||
defaultValueRenderable(renderableBuilder, deflt);
|
||||
}
|
||||
|
||||
if (isDeprecated()) {
|
||||
depreactionRenderable(renderableBuilder);
|
||||
}
|
||||
|
||||
Renderable description = getDescription();
|
||||
if (description!=null) {
|
||||
descriptionRenderable(renderableBuilder, description);
|
||||
}
|
||||
|
||||
return concat(renderableBuilder.build());
|
||||
}
|
||||
|
||||
final protected void renderId(HtmlBuffer html) {
|
||||
boolean deprecated = isDeprecated();
|
||||
String tag = deprecated ? "s" : "b";
|
||||
String replacement = getDeprecationReplacement();
|
||||
|
||||
html.raw("<"+tag+">");
|
||||
html.text(getId());
|
||||
html.raw("</"+tag+">");
|
||||
if (StringUtil.hasText(replacement)) {
|
||||
html.text(" -> "+ replacement);
|
||||
final protected void renderId(Builder<Renderable> renderableBuilder) {
|
||||
if (isDeprecated()) {
|
||||
renderableBuilder.add(strikeThrough(text(getId())));
|
||||
String replacement = getDeprecationReplacement();
|
||||
if (StringUtil.hasText(replacement)) {
|
||||
renderableBuilder.add(text(" -> " + replacement));
|
||||
}
|
||||
} else {
|
||||
renderableBuilder.add(bold(text(getId())));
|
||||
}
|
||||
html.raw("<br>");
|
||||
}
|
||||
|
||||
|
||||
protected abstract Object getDefaultValue();
|
||||
protected abstract IJavaProject getJavaProject();
|
||||
protected abstract Renderable getDescription();
|
||||
@@ -125,13 +102,34 @@ public abstract class AbstractPropertyRenderableProvider {
|
||||
* Creates an 'action' link and adds it to the html buffer. When the user clicks the given
|
||||
* link then the provided runnable is to be executed.
|
||||
*/
|
||||
public void actionLink(HtmlBuffer html, String displayString/*, Runnable runnable*/) {
|
||||
// String actionId = registerAction(runnable);
|
||||
html.raw("<a href=\"http://"+ACTION_HOST+"/");
|
||||
html.url("action-id");
|
||||
html.raw("\">");
|
||||
html.text(displayString);
|
||||
html.raw("</a>");
|
||||
public void actionLink(Builder<Renderable> renderableBuilder, String displayString) {
|
||||
String url = "http://"+ACTION_HOST+"/action-id";
|
||||
renderableBuilder.add(lineBreak());
|
||||
renderableBuilder.add(link(displayString, url));
|
||||
}
|
||||
|
||||
private void defaultValueRenderable(Builder<Renderable> renderableBuilder, String defaultValue) {
|
||||
renderableBuilder.add(lineBreak());
|
||||
renderableBuilder.add(lineBreak());
|
||||
renderableBuilder.add(text("Default: "));
|
||||
renderableBuilder.add(italic(text(defaultValue)));
|
||||
}
|
||||
|
||||
private void depreactionRenderable(Builder<Renderable> renderableBuilder) {
|
||||
renderableBuilder.add(lineBreak());
|
||||
renderableBuilder.add(lineBreak());
|
||||
String reason = getDeprecationReason();
|
||||
if (StringUtil.hasText(reason)) {
|
||||
renderableBuilder.add(bold(text("Deprecated: ")));
|
||||
renderableBuilder.add(text(reason));
|
||||
} else {
|
||||
renderableBuilder.add(bold(text("Deprecated!")));
|
||||
}
|
||||
}
|
||||
|
||||
private void descriptionRenderable(Builder<Renderable> renderableBuilder, Renderable description) {
|
||||
renderableBuilder.add(lineBreak());
|
||||
renderableBuilder.add(paragraph(description));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.application.properties.metadata.hover;
|
||||
package org.springframework.ide.vscode.boot.properties.tools;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -25,7 +25,6 @@ import org.springframework.ide.vscode.application.properties.metadata.completion
|
||||
import org.springframework.ide.vscode.application.properties.metadata.hints.HintProvider;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.hints.StsValueHint;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.hints.ValueHintHoverInfo;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.hover.PropertyRenderableProvider;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.types.Type;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.types.TypeParser;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.types.TypeUtil;
|
||||
@@ -34,6 +33,7 @@ import org.springframework.ide.vscode.application.properties.metadata.types.Type
|
||||
import org.springframework.ide.vscode.application.properties.metadata.types.TypedProperty;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.util.FuzzyMap;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.util.FuzzyMap.Match;
|
||||
import org.springframework.ide.vscode.boot.properties.tools.PropertyRenderableProvider;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.LazyProposalApplier;
|
||||
|
||||
@@ -18,11 +18,11 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.springframework.boot.configurationmetadata.Deprecation;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.hover.AbstractPropertyRenderableProvider;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.types.Type;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.types.TypeUtil;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.types.TypeUtil.BeanPropertyNameMode;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.types.TypeUtil.EnumCaseMode;
|
||||
import org.springframework.ide.vscode.boot.properties.tools.AbstractPropertyRenderableProvider;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.types.TypedProperty;
|
||||
import org.springframework.ide.vscode.commons.java.IField;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaElement;
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.ide.vscode.application.properties.metadata.Properties
|
||||
import org.springframework.ide.vscode.boot.BootPropertiesLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.languageserver.hover.VscodeHoverEngineAdapter.HoverType;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.maven.java.MavenJavaProject;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.Editor;
|
||||
@@ -180,10 +179,10 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
);
|
||||
//Case 1: an 'exact' match of the property is in the hover region
|
||||
editor.assertHoverText("server.",
|
||||
"<b>server.port</b>"
|
||||
"**server.port**"
|
||||
);
|
||||
//Case 2: an object/map property has extra text after the property name
|
||||
editor.assertHoverText("logging.", "<b>logging.level</b>");
|
||||
editor.assertHoverText("logging.", "**logging.level**");
|
||||
}
|
||||
|
||||
@Test public void testHoverInfosWithSpaces() throws Exception {
|
||||
@@ -197,10 +196,10 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
);
|
||||
//Case 1: an 'exact' match of the property is in the hover region
|
||||
editor.assertHoverText("server.",
|
||||
"<b>server.port</b>"
|
||||
"**server.port**"
|
||||
);
|
||||
//Case 2: an object/map property has extra text after the property name
|
||||
editor.assertHoverText("logging.", "<b>logging.level</b>");
|
||||
editor.assertHoverText("logging.", "**logging.level**");
|
||||
}
|
||||
|
||||
@Test public void testHoverLongAndShort() throws Exception {
|
||||
@@ -210,8 +209,8 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
"server.port=8080\n" +
|
||||
"server.port.fancy=true\n"
|
||||
);
|
||||
editor.assertHoverText("server.", "<b>server.port</b>");
|
||||
editor.assertHoverText("port.fa", "<b>server.port.fancy</b>");
|
||||
editor.assertHoverText("server.", "**server.port**");
|
||||
editor.assertHoverText("port.fa", "**server.port.fancy**");
|
||||
}
|
||||
|
||||
|
||||
@@ -924,18 +923,18 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
);
|
||||
|
||||
deprecate("error.path", "server.error.path", null);
|
||||
editor.assertHoverText("path", "<s>error.path</s> -> server.error.path");
|
||||
editor.assertHoverText("path", "<b>Deprecated!</b>");
|
||||
editor.assertHoverText("path", "~~error.path~~ -> server.error.path");
|
||||
editor.assertHoverText("path", "**Deprecated!**");
|
||||
|
||||
deprecate("error.path", "server.error.path", "This is old.");
|
||||
editor.assertHoverText("path", "<s>error.path</s> -> server.error.path");
|
||||
editor.assertHoverText("path", "<b>Deprecated: </b>This is old");
|
||||
editor.assertHoverText("path", "~~error.path~~ -> server.error.path");
|
||||
editor.assertHoverText("path", "**Deprecated: **This is old");
|
||||
|
||||
deprecate("error.path", null, "This is old.");
|
||||
editor.assertHoverText("path", "<b>Deprecated: </b>This is old");
|
||||
editor.assertHoverText("path", "**Deprecated: **This is old");
|
||||
|
||||
deprecate("error.path", null, null);
|
||||
editor.assertHoverText("path", "<b>Deprecated!</b>");
|
||||
editor.assertHoverText("path", "**Deprecated!**");
|
||||
}
|
||||
|
||||
@Ignore @Test public void testDeprecatedPropertyQuickfix() throws Exception {
|
||||
@@ -1573,7 +1572,6 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
protected SimpleLanguageServer newLanguageServer() {
|
||||
BootPropertiesLanguageServer server = new BootPropertiesLanguageServer(md.getIndexProvider(), typeUtilProvider, javaProjectFinder);
|
||||
server.setMaxCompletionsNumber(-1);
|
||||
server.setHoverType(HoverType.HTML);
|
||||
return server;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user