mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 21:12:44 +03:00
Escape default text arguments in suggestions database (#9010)
Changelog: - fix: escape default text arguments in suggestions database
This commit is contained in:
parent
26aa27c9ad
commit
200a494242
@ -10,7 +10,6 @@ import org.enso.compiler.core.ir.{
|
||||
Expression,
|
||||
Function,
|
||||
IdentifiedLocation,
|
||||
Literal,
|
||||
Location,
|
||||
Name,
|
||||
Type
|
||||
@ -575,7 +574,7 @@ final class SuggestionBuilder[A: IndexedSource](
|
||||
reprType = selfType.toString,
|
||||
isSuspended = suspended,
|
||||
hasDefault = defaultValue.isDefined,
|
||||
defaultValue = defaultValue.flatMap(buildDefaultValue)
|
||||
defaultValue = defaultValue.map(buildDefaultValue)
|
||||
)
|
||||
go(vtail, targs, acc :+ thisArg)
|
||||
}
|
||||
@ -640,7 +639,7 @@ final class SuggestionBuilder[A: IndexedSource](
|
||||
reprType = buildTypeArgumentName(targ),
|
||||
isSuspended = varg.suspended,
|
||||
hasDefault = varg.defaultValue.isDefined,
|
||||
defaultValue = varg.defaultValue.flatMap(buildDefaultValue),
|
||||
defaultValue = varg.defaultValue.map(buildDefaultValue),
|
||||
tagValues = buildTagValues(targ)
|
||||
)
|
||||
|
||||
@ -712,7 +711,7 @@ final class SuggestionBuilder[A: IndexedSource](
|
||||
reprType = Any,
|
||||
isSuspended = arg.suspended,
|
||||
hasDefault = arg.defaultValue.isDefined,
|
||||
defaultValue = arg.defaultValue.flatMap(buildDefaultValue)
|
||||
defaultValue = arg.defaultValue.map(buildDefaultValue)
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -730,13 +729,11 @@ final class SuggestionBuilder[A: IndexedSource](
|
||||
* @param expr the argument expression
|
||||
* @return the argument default value
|
||||
*/
|
||||
private def buildDefaultValue(expr: IR): Option[String] =
|
||||
private def buildDefaultValue(expr: IR): String =
|
||||
expr match {
|
||||
case Literal.Number(_, value, _, _, _) => Some(value)
|
||||
case Literal.Text(text, _, _, _) => Some(text)
|
||||
case Application.Prefix(name, path, _, _, _, _) =>
|
||||
Some(path.map(_.value.showCode()).mkString(".") + "." + name.showCode())
|
||||
case other => Some(other.showCode())
|
||||
path.map(_.value.showCode()).mkString(".") + "." + name.showCode()
|
||||
case other => other.showCode()
|
||||
}
|
||||
|
||||
/** Build scope from the location. */
|
||||
|
@ -220,7 +220,7 @@ object Literal {
|
||||
/** @inheritdoc */
|
||||
override def toString: String =
|
||||
s"""
|
||||
|Literal.String(
|
||||
|Literal.Text(
|
||||
|text = $text,
|
||||
|location = $location,
|
||||
|passData = ${this.showPassData},
|
||||
|
@ -381,7 +381,7 @@ class SuggestionBuilderTest extends AnyWordSpecLike with Matchers {
|
||||
|
||||
"build method with default arguments" in {
|
||||
|
||||
val code = """foo (a = 0) = a + 1"""
|
||||
val code = """foo (a = 0) (b = "bar") (c = x.y) = a + b + c"""
|
||||
val module = code.preprocessModule
|
||||
|
||||
build(code, module) shouldEqual Tree.Root(
|
||||
@ -394,7 +394,23 @@ class SuggestionBuilderTest extends AnyWordSpecLike with Matchers {
|
||||
name = "foo",
|
||||
arguments = Seq(
|
||||
Suggestion
|
||||
.Argument("a", SuggestionBuilder.Any, false, true, Some("0"))
|
||||
.Argument("a", SuggestionBuilder.Any, false, true, Some("0")),
|
||||
Suggestion
|
||||
.Argument(
|
||||
"b",
|
||||
SuggestionBuilder.Any,
|
||||
false,
|
||||
true,
|
||||
Some("\"bar\"")
|
||||
),
|
||||
Suggestion
|
||||
.Argument(
|
||||
"c",
|
||||
SuggestionBuilder.Any,
|
||||
false,
|
||||
true,
|
||||
Some("x.y")
|
||||
)
|
||||
),
|
||||
selfType = "Unnamed.Test",
|
||||
returnType = SuggestionBuilder.Any,
|
||||
|
Loading…
Reference in New Issue
Block a user