Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop down for Text.trim 'where' attribute #3407

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ object SearchProtocol {
conversion.sourceType,
false,
false,
None
None,
Option.empty
)
Suggestion.Method(
conversion.externalId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ object Suggestions {
|""".stripMargin.linesIterator.mkString("\n")
}

private def suggestionArgument(
name: String,
reprType: String,
isSuspended: Boolean,
hasDefault: Boolean,
defaultValue: Option[String]
): Suggestion.Argument = {
Suggestion.Argument(name, reprType, isSuspended, hasDefault, defaultValue, None)
}

val htmlDocsGenerator: DocsGenerator =
DocsGenerator
val docSectionsBuilder: DocSectionsBuilder =
Expand All @@ -42,7 +52,7 @@ object Suggestions {
externalId = None,
module = "Test.Main",
name = "MyType",
arguments = Vector(Suggestion.Argument("a", "Any", false, false, None)),
arguments = Vector(suggestionArgument("a", "Any", false, false, None)),
returnType = "MyAtom",
documentation = Some(comment.atom),
documentationHtml =
Expand All @@ -55,8 +65,8 @@ object Suggestions {
module = "Test.Main",
name = "foo",
arguments = Vector(
Suggestion.Argument("this", "MyType", false, false, None),
Suggestion.Argument("foo", "Number", false, true, Some("42"))
suggestionArgument("this", "MyType", false, false, None),
suggestionArgument("foo", "Number", false, true, Some("42"))
),
selfType = "MyType",
returnType = "Number",
Expand All @@ -70,9 +80,9 @@ object Suggestions {
module = "Test.Main",
name = "print",
arguments = Vector(
Suggestion.Argument("a", "Any", false, false, None),
Suggestion.Argument("b", "Any", true, false, None),
Suggestion.Argument("c", "Any", false, true, Some("C"))
suggestionArgument("a", "Any", false, false, None),
suggestionArgument("b", "Any", true, false, None),
suggestionArgument("c", "Any", false, true, Some("C"))
),
returnType = "IO",
scope =
Expand All @@ -93,8 +103,8 @@ object Suggestions {
module = "Standard.Base.Data.Any.Extensions",
name = "<<",
arguments = Vector(
Suggestion.Argument("this", "Any", false, false, None),
Suggestion.Argument("that", "Any", false, false, None)
suggestionArgument("this", "Any", false, false, None),
suggestionArgument("that", "Any", false, false, None)
),
selfType = "Any",
returnType = "Any",
Expand All @@ -108,7 +118,7 @@ object Suggestions {
module = "Standard.Base.Data.Number.Extensions",
name = "asin",
arguments = Vector(
Suggestion.Argument("this", "Number", false, false, None)
suggestionArgument("this", "Number", false, false, None)
),
selfType = "Number",
returnType = "Number",
Expand All @@ -122,7 +132,7 @@ object Suggestions {
module = "Builtins.Main",
name = "+",
arguments = Vector(
Suggestion.Argument("that", "Number", false, false, None)
suggestionArgument("that", "Number", false, false, None)
),
selfType = "Integer",
returnType = "Number",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1232,8 +1232,8 @@ class SuggestionsHandlerSpec
module = "Test.Pair",
name = "Pair",
arguments = Seq(
Suggestion.Argument("a", "Any", false, false, None),
Suggestion.Argument("b", "Any", false, false, None)
Suggestion.Argument("a", "Any", false, false, None, None),
Suggestion.Argument("b", "Any", false, false, None, None)
),
returnType = "Pair",
documentation = Some("Awesome"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class SuggestionsHandlerEventsTest extends BaseServerTest with FlakySpec {
"reprType" : "Any",
"isSuspended" : false,
"hasDefault" : false,
"defaultValue" : null
"defaultValue" : null,
"tagValues" : null
}
],
"returnType" : "MyAtom",
Expand Down Expand Up @@ -141,14 +142,16 @@ class SuggestionsHandlerEventsTest extends BaseServerTest with FlakySpec {
"reprType" : "MyType",
"isSuspended" : false,
"hasDefault" : false,
"defaultValue" : null
"defaultValue" : null,
"tagValues" : null
},
{
"name" : "foo",
"reprType" : "Number",
"isSuspended" : false,
"hasDefault" : true,
"defaultValue" : "42"
"defaultValue" : "42",
"tagValues" : null
}
],
"selfType" : "MyType",
Expand Down Expand Up @@ -224,21 +227,24 @@ class SuggestionsHandlerEventsTest extends BaseServerTest with FlakySpec {
"reprType" : "Any",
"isSuspended" : false,
"hasDefault" : false,
"defaultValue" : null
"defaultValue" : null,
"tagValues" : null
},
{
"name" : "b",
"reprType" : "Any",
"isSuspended" : true,
"hasDefault" : false,
"defaultValue" : null
"defaultValue" : null,
"tagValues" : null
},
{
"name" : "c",
"reprType" : "Any",
"isSuspended" : false,
"hasDefault" : true,
"defaultValue" : "C"
"defaultValue" : "C",
"tagValues" : null
}
],
"returnType" : "IO",
Expand Down Expand Up @@ -356,21 +362,24 @@ class SuggestionsHandlerEventsTest extends BaseServerTest with FlakySpec {
"reprType" : "Any",
"isSuspended" : false,
"hasDefault" : false,
"defaultValue" : null
"defaultValue" : null,
"tagValues" : null
},
{
"name" : "b",
"reprType" : "Any",
"isSuspended" : true,
"hasDefault" : false,
"defaultValue" : null
"defaultValue" : null,
"tagValues" : null
},
{
"name" : "c",
"reprType" : "Any",
"isSuspended" : false,
"hasDefault" : true,
"defaultValue" : "C"
"defaultValue" : "C",
"tagValues" : null
}
],
"returnType" : "IO",
Expand Down Expand Up @@ -419,14 +428,16 @@ class SuggestionsHandlerEventsTest extends BaseServerTest with FlakySpec {
"reprType" : "MyType",
"isSuspended" : false,
"hasDefault" : false,
"defaultValue" : null
"defaultValue" : null,
"tagValues" : null
},
{
"name" : "foo",
"reprType" : "Number",
"isSuspended" : false,
"hasDefault" : true,
"defaultValue" : "42"
"defaultValue" : "42",
"tagValues" : null
}
],
"selfType" : "MyType",
Expand All @@ -453,7 +464,8 @@ class SuggestionsHandlerEventsTest extends BaseServerTest with FlakySpec {
"reprType" : "Any",
"isSuspended" : false,
"hasDefault" : false,
"defaultValue" : null
"defaultValue" : null,
"tagValues" : null
}
],
"returnType" : "MyAtom",
Expand Down Expand Up @@ -572,7 +584,8 @@ class SuggestionsHandlerEventsTest extends BaseServerTest with FlakySpec {
"reprType" : "Any",
"isSuspended" : true,
"hasDefault" : false,
"defaultValue" : null
"defaultValue" : null,
"tagValues" : null
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ object Suggestion {
reprType: String,
isSuspended: Boolean,
hasDefault: Boolean,
defaultValue: Option[String]
defaultValue: Option[String],
tagValues: Option[Seq[String]]
) extends ToLogString {

/** @inheritdoc */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ final class SuggestionBuilder[A: IndexedSource](val source: A) {
): Suggestion.Method = {
val typeSig = buildTypeSignatureFromMetadata(typeSignature, bindings)
val (methodArgs, returnTypeDef) =
buildMethodArguments(args, typeSig, selfType)
buildMethodArguments(args, typeSig, selfType, name.name)
Suggestion.Method(
externalId = externalId,
module = module.toString,
Expand Down Expand Up @@ -431,8 +431,17 @@ final class SuggestionBuilder[A: IndexedSource](val source: A) {
private def buildMethodArguments(
vargs: Seq[IR.DefinitionArgument],
targs: Seq[TypeArg],
selfType: QualifiedName
selfType: QualifiedName,
methodName: String
): (Seq[Suggestion.Argument], Option[TypeArg]) = {
var tagValues: Map[String, Seq[String]] = Map.empty;
if (selfType.toString().equals("Standard.Builtins.Main.Text")) {
if ("trim".equals(methodName)) {
tagValues = Map(
"where" -> Seq("Location.Both", "Location.Start", "Location.End")
)
}
}
@scala.annotation.tailrec
def go(
vargs: Seq[IR.DefinitionArgument],
Expand All @@ -457,13 +466,14 @@ final class SuggestionBuilder[A: IndexedSource](val source: A) {
reprType = selfType.toString,
isSuspended = suspended,
hasDefault = defaultValue.isDefined,
defaultValue = defaultValue.flatMap(buildDefaultValue)
defaultValue = defaultValue.flatMap(buildDefaultValue),
tagValues = Option.empty
)
go(vtail, targs, acc :+ thisArg)
case varg +: vtail =>
targs match {
case targ +: ttail =>
go(vtail, ttail, acc :+ buildTypedArgument(varg, targ))
go(vtail, ttail, acc :+ buildTypedArgument(varg, targ, tagValues))
case _ =>
go(vtail, targs, acc :+ buildArgument(varg))
}
Expand Down Expand Up @@ -496,7 +506,7 @@ final class SuggestionBuilder[A: IndexedSource](val source: A) {
case varg +: vtail =>
targs match {
case targ +: ttail =>
go(vtail, ttail, acc :+ buildTypedArgument(varg, targ))
go(vtail, ttail, acc :+ buildTypedArgument(varg, targ, Map.empty))
case _ =>
go(vtail, targs, acc :+ buildArgument(varg))
}
Expand All @@ -514,14 +524,16 @@ final class SuggestionBuilder[A: IndexedSource](val source: A) {
*/
private def buildTypedArgument(
varg: IR.DefinitionArgument,
targ: TypeArg
targ: TypeArg,
tagValues : Map[String,Seq[String]]
): Suggestion.Argument =
Suggestion.Argument(
name = varg.name.name,
reprType = buildTypeArgumentName(targ),
isSuspended = varg.suspended,
hasDefault = varg.defaultValue.isDefined,
defaultValue = varg.defaultValue.flatMap(buildDefaultValue)
defaultValue = varg.defaultValue.flatMap(buildDefaultValue),
tagValues = tagValues.get(varg.name.name)
)

/** Build the name of type argument.
Expand Down Expand Up @@ -565,7 +577,8 @@ final class SuggestionBuilder[A: IndexedSource](val source: A) {
reprType = Any,
isSuspended = arg.suspended,
hasDefault = arg.defaultValue.isDefined,
defaultValue = arg.defaultValue.flatMap(buildDefaultValue)
defaultValue = arg.defaultValue.flatMap(buildDefaultValue),
tagValues = Option.empty
)

/** Build return type from the type definition.
Expand Down
Loading