Skip to content

Commit 1f4b6e9

Browse files
committed
Add workaround for empty enum
1 parent 5b0185a commit 1f4b6e9

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

lspSmithy/src/org/scala/abusers/lspsmithy/SmithyConverter.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.scala.abusers.lspsmithy
22

3+
import alloy.OpenEnumTrait
34
import alloy.UntaggedUnionTrait
45
import cats.data.State
56
import cats.syntax.all.*
@@ -135,18 +136,26 @@ object SmithyConverter:
135136
.build()
136137
case _: String =>
137138
val builder = EnumShape.builder().id(shapeId)
139+
140+
val hasEmptyValues = enum_.values.exists(_.value.stringValue.isEmpty)
141+
142+
// workaround to support the CodeActionKind type having an empty string value
143+
if (hasEmptyValues) builder.addTrait(new OpenEnumTrait())
144+
138145
enum_.values
139146
.distinctBy(_.value)
140147
.filterNot(_.proposed)
141148
// Smithy doesn't allow enum values: https://github.com/smithy-lang/smithy/issues/2626
142149
.filter(_.value.stringValue.nonEmpty)
143-
.foldLeft(builder) { case (acc, entry) =>
144-
acc.addMember(
150+
.foreach { entry =>
151+
builder.addMember(
145152
toUpperSnakeCase(entry.name.value),
146153
entry.value.stringValue,
147154
_.tap(maybeAddDocs(entry.documentation.toOption.map(_.value), entry.since.toOption)),
148155
)
149156
}
157+
158+
builder
150159
.build()
151160

152161
enumShape

target/META-INF/smithy/lsp.smithy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ $version: "2.0"
22

33
namespace lsp
44

5+
use alloy#openEnum
56
use alloy#untagged
67
use jsonrpclib#jsonRpcNotification
78
use jsonrpclib#jsonRpcPayload
@@ -7571,6 +7572,7 @@ intEnum ApplyKind {
75717572

75727573
string ChangeAnnotationIdentifier
75737574

7575+
@openEnum
75747576
enum CodeActionKind {
75757577
/// Base kind for quickfix actions: 'quickfix'
75767578
QUICK_FIX = "quickfix"

0 commit comments

Comments
 (0)