Skip to content
Draft
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 @@ -296,7 +296,7 @@ object OperationRunner {
)

val getInternal: IorNel[Issue, OperationRunner[F]] = runners.reduce(
IorUtils.orElseCombine[NonEmptyList[Issue], OperationRunner[F]]
IorUtils.orElseCombine[NonEmptyList[Issue], OperationRunner[F]](_, _)
)

def get(
Expand Down
18 changes: 17 additions & 1 deletion modules/core/src/test/smithy/demo.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,27 @@ service DemoService {
operations: [
CreateHero
GetPowers
CreateSubscription
CreateSubscription,
CreateList
]
errors: [GenericServerError]
}

@http(uri: "/list", method: "POST")
operation CreateList {
input := {
items: Items,
lists: Lists
}
}

list Lists { member: Items }
list Items { member: Item }

structure Item {
@required name: String
}

@simpleRestJson
service DemoService2 {
version: "0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ object CompletionProvider {
val matchingNode = RangeIndex
.build(sf)
.findAtPosition(pos)

// System.err.println("matchingNode: " + matchingNode.render)

matchingNode match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ trait CompletionResolver[+A] {
def retag[B]: CompletionResolver[B] = getCompletions(_)
}

object CompletionResolver {

def routed[A](
f: NodeContext => CompletionResolver[A]
): CompletionResolver[A] = ctx => f(ctx).getCompletions(ctx)

}

final case class CompletionItem(
kind: CompletionItemKind,
label: String,
Expand Down Expand Up @@ -463,8 +471,22 @@ object CompletionVisitor extends SchemaVisitor[CompletionResolver] {
): CompletionResolver[List[A]] = {
val memberInstance = member.compile(this)

val emptyList = CompletionItem(
kind = CompletionItemKind.Constant /* todo */,
label = "[]",
insertText = InsertText.SnippetString("[$0]"),
detail = "todo",
description = Some("todo"),
deprecated = false,
sortText = None,
// todo
docs = None,
extraTextEdits = Nil,
)

{
case PathEntry.CollectionEntry(_) ^^: rest => memberInstance.getCompletions(rest)
case EmptyPath => List(emptyList)
case _ =>
// other contexts are invalid
Nil
Expand Down Expand Up @@ -527,9 +549,22 @@ object CompletionVisitor extends SchemaVisitor[CompletionResolver] {
fields: Vector[SchemaField[S, _]],
make: IndexedSeq[Any] => S,
): CompletionResolver[S] = {
val emptyStruct = CompletionItem(
kind = CompletionItemKind.Constant /* todo */,
label = "{}",
insertText = InsertText.SnippetString("{$0}"),
detail = "todo",
description = Some("todo"),
deprecated = false,
sortText = None,
// todo
docs = None,
extraTextEdits = Nil,
)

val compiledFields = fields.map(field => (field.mapK(this), field.instance))

structLike(
val byStructShape = structLike(
inBody =
fields
// todo: filter out present fields
Expand All @@ -547,6 +582,12 @@ object CompletionVisitor extends SchemaVisitor[CompletionResolver] {
}
.foldMap(_.instance.getCompletions(rest)),
)

// todo this doesn't work
CompletionResolver.routed {
case EmptyPath => _ => List(emptyStruct)
case _ => byStructShape
}
}

override def union[U](
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package playground.language

import cats.implicits._
import demo.smithy.Friends
import demo.smithy.Good
import demo.smithy.HasDeprecations
import demo.smithy.HasNewtypes
Expand All @@ -12,6 +13,8 @@ import demo.smithy.MyInt
import demo.smithy.MyString
import demo.smithy.Power
import demo.smithy.PowerMap
import playground.Assertions._
import playground.language.Diffs._
import playground.smithyql.NodeContext
import playground.smithyql.NodeContext.PathEntry._
import smithy.api.TimestampFormat
Expand All @@ -29,6 +32,13 @@ object CompletionTests extends FunSuite {
ctx: NodeContext,
): List[CompletionItem] = schema.compile(CompletionVisitor).getCompletions(ctx)

test("completions on list items that are structs") {

val completions = getCompletions(Friends.schema, NodeContext.EmptyPath)

assertNoDiff(completions, Nil)
}

test("completions on struct are empty without StructBody") {

val completions = getCompletions(Good.schema, NodeContext.EmptyPath)
Expand Down