Skip to content

Commit

Permalink
Added manual HTML escaping when converting values to doc strings (to …
Browse files Browse the repository at this point in the history
…avoid rendering issues in documentation popups).
  • Loading branch information
iancaffey committed Mar 20, 2023
1 parent 8a5833b commit 29b3442
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package software.amazon.smithy.intellij.psi

import com.google.common.html.HtmlEscapers
import com.intellij.openapi.editor.richcopy.HtmlSyntaxInfoUtil.appendStyledSpan
import com.intellij.openapi.editor.richcopy.HtmlSyntaxInfoUtil.getStyledSpan
import software.amazon.smithy.intellij.SmithyColorSettings
Expand Down Expand Up @@ -33,6 +34,7 @@ interface SmithyValueDefinition : SmithyElement {
values[it].equivalentTo(otherValues[it])
}
}

SmithyValueType.BOOLEAN -> asBoolean() == other.asBoolean()
SmithyValueType.NULL -> true
SmithyValueType.NUMBER -> asNumber() == other.asNumber()
Expand All @@ -44,6 +46,7 @@ interface SmithyValueDefinition : SmithyElement {
otherValue != null && value.equivalentTo(otherValue)
}
}

SmithyValueType.STRING -> asString() == other.asString()
}

Expand All @@ -53,6 +56,7 @@ interface SmithyValueDefinition : SmithyElement {
type == SmithyValueType.ARRAY -> SmithySyntheticValue.Array(listOf(values, other.values).flatten().map {
SmithySyntheticValue.from(it)
})

else -> null
}

Expand All @@ -66,6 +70,7 @@ interface SmithyValueDefinition : SmithyElement {
}
append("]")
}

SmithyValueType.BOOLEAN -> appendStyledSpan(this, SmithyColorSettings.KEYWORD, asBoolean().toString(), 1f)
SmithyValueType.NULL -> appendStyledSpan(this, SmithyColorSettings.KEYWORD, "null", 1f)
SmithyValueType.NUMBER -> appendStyledSpan(
Expand All @@ -74,6 +79,7 @@ interface SmithyValueDefinition : SmithyElement {
asNumber()?.toPlainString() ?: "NaN",
1f
)

SmithyValueType.OBJECT -> {
append("{")
fields.onEachIndexed { i, (key, value) ->
Expand All @@ -84,6 +90,7 @@ interface SmithyValueDefinition : SmithyElement {
}
append("}")
}

SmithyValueType.STRING -> {
val value = asString()
if (value != null && "#" in value) {
Expand Down Expand Up @@ -116,7 +123,7 @@ interface SmithyValueDefinition : SmithyElement {
appendStyledSpan(
this,
SmithyColorSettings.STRING,
SmithyJson.writeValueAsString(value),
HtmlEscapers.htmlEscaper().escape(SmithyJson.writeValueAsString(value)),
1f
)
}
Expand Down

0 comments on commit 29b3442

Please sign in to comment.