Skip to content
Merged
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
33 changes: 21 additions & 12 deletions lspSmithy/src/org/scala/abusers/lspsmithy/SmithyConverter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ object SmithyConverter:
val parts = List(common.mkString, outlier).sorted
s"${parts(0)}Or${parts(1)}"
else if suffix.nonEmpty then suffix.mkString + "Union"
else s"Union_${MurmurHash3.indexedSeqHash(types, 0)}"
else s"Union_${Math.abs(MurmurHash3.indexedSeqHash(types, 0))}"

private def extractTypeName(t: Type): String = t match
case Type.ReferenceType(name) => name.value
case Type.BaseType(base) => base.toString.capitalize
case Type.ArrayType(inner) => s"ListOf${extractTypeName(inner)}"
case Type.MapType(k, v) => s"MapOf${extractTypeName(k)}To${extractTypeName(v)}"
case Type.StringLiteralType(_) | Type.BooleanLiteralType(_) => "Literal"
case Type.StructureLiteralType(StructureLiteral(props, _)) => s"Literal${MurmurHash3.indexedSeqHash(props, 0)}"
case Type.StructureLiteralType(StructureLiteral(props, _)) => s"Literal${Math.abs(MurmurHash3.indexedSeqHash(props, 0))}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

negative hashes are my passion

case _ => ""

private def splitPascal(s: String): List[String] =
Expand Down Expand Up @@ -193,18 +193,27 @@ object SmithyConverter:
case TupleType(items) =>
for
items_ <- items.traverse(t => smithyType(t, namespace))
unifiedType = items_.distinct match
case Seq(one) => one
case _ => ShapeId.from("smithy.api#String") // TODO: fallback
listId = ShapeId.fromParts(namespace, s"TupleOf${unifiedType.getName}")
tupleId = ShapeId.fromParts(namespace, s"TupleOf${items_.map(_.getName).mkString}")
result <- State[Set[Shape], ShapeId] { shapes =>
val listShape = ListShape
val tupleBuilder = StructureShape
.builder()
.id(listId)
.id(tupleId)
.addTrait(TupleTrait.builder().build())
.member(MemberShape.builder().id(listId.withMember("member")).target(unifiedType).build())
.build()
(shapes + listShape, listId)

items_.zipWithIndex.foreach { case (m, i) =>
tupleBuilder.addMember(
MemberShape
.builder()
.id(tupleId.withMember(s"_$i"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll want some meaningful names for these. Probably using a mechanism similar to neandertech/langoustine#204

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. ParameterInformation will have sth like inclusiveStart, exclusiveEnd

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I'm happy to make it a ticket

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah let's leave it for later

.target(m)
.addTrait(
new RequiredTrait.Provider().createTrait(RequiredTrait.ID, Node.objectNode)
)
.build()
)
}

(shapes + tupleBuilder.build(), tupleId)
}
yield result

Expand Down Expand Up @@ -237,7 +246,7 @@ object SmithyConverter:
}

case StructureLiteralType(StructureLiteral(properties, false)) =>
val id = ShapeId.fromParts(namespace, s"InlineStruct${MurmurHash3.indexedSeqHash(properties, 0)}")
val id = ShapeId.fromParts(namespace, s"InlineStruct${Math.abs(MurmurHash3.indexedSeqHash(properties, 0))}")
structureMembers(id, properties)
.map(_.foldLeft(StructureShape.builder().id(id)) { case (acc, item) => acc.addMember(item) }.build())
.flatMap { structureShape =>
Expand Down
15 changes: 9 additions & 6 deletions target/lsp.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -5405,6 +5405,14 @@ structure TextEdit {
newText: String
}

@tuple()
structure TupleOfIntegerInteger {
@required
_0: Integer
@required
_1: Integer
}

/// Since 3.6.0
structure TypeDefinitionClientCapabilities {
/// Whether implementation supports dynamic registration. If this is set to `true`
Expand Down Expand Up @@ -6736,7 +6744,7 @@ union StringOrNULL {
@untagged()
union StringUnion {
case0: String
case1: TupleOfInteger
case1: TupleOfIntegerInteger
}

@untagged()
Expand Down Expand Up @@ -7105,11 +7113,6 @@ list LSPArray {
member: Document
}

@tuple()
list TupleOfInteger {
member: Integer
}

map LSPObject {
key: String
value: Document
Expand Down