Skip to content

Commit

Permalink
resolve todos
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Dec 24, 2024
1 parent a931eda commit 4408463
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 40 deletions.
73 changes: 33 additions & 40 deletions modules/core/src/main/scala/playground/MultiServiceResolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,13 @@ object MultiServiceResolver {
queryOperationName: playground.generated.nodes.QueryOperationName,
serviceIndex: ServiceIndex,
useClauses: List[playground.generated.nodes.UseClause],
): EitherNel[CompilationError, QualifiedIdentifier] =
queryOperationName.name match {
case Some(opName) =>
queryOperationName.identifier.flatMap(_.qualified_identifier) match {
case Some(explicitRef) => resolveExplicitTs(serviceIndex, explicitRef, opName)

case None => resolveImplicitTs(opName, serviceIndex, useClauses)
}
case None =>
// TODO: operation name is invalid or something like that
???

): EitherNel[CompilationError, Option[QualifiedIdentifier]] = queryOperationName
.name
.flatTraverse { opName =>
queryOperationName.identifier.flatMap(_.qualified_identifier) match {
case Some(explicitRef) => resolveExplicitTs(serviceIndex, explicitRef, opName)
case None => resolveImplicitTs(opName, serviceIndex, useClauses).map(_.some)
}
}

private def resolveExplicit(
Expand Down Expand Up @@ -104,34 +99,32 @@ object MultiServiceResolver {
index: ServiceIndex,
explicitRef: playground.generated.nodes.QualifiedIdentifier,
operationName: playground.generated.nodes.OperationName,
): EitherNel[CompilationError, QualifiedIdentifier] =
ASTAdapter.decodeQI(explicitRef) match {
case None => ??? /* todo - I don't really know xD */
// explicit reference exists, but doesn't parse
case Some(ref) =>
index.getService(ref) match {
// explicit reference exists, but the service doesn't
case None =>
CompilationError
.error(
CompilationErrorDetails.UnknownService(index.serviceIds.toList),
explicitRef.range,
)
.leftNel

// the service exists, but doesn't have the requested operation
case Some(service)
if !service.operationNames.contains_(OperationName(operationName.source)) =>
CompilationError
.error(
CompilationErrorDetails.OperationMissing(service.operationNames.toList),
operationName.range,
)
.leftNel

// all good
case Some(_) => ref.asRight
}
): EitherNel[CompilationError, Option[QualifiedIdentifier]] = ASTAdapter
.decodeQI(explicitRef)
.traverse { ref =>
index.getService(ref) match {
// explicit reference exists, but the service doesn't
case None =>
CompilationError
.error(
CompilationErrorDetails.UnknownService(index.serviceIds.toList),
explicitRef.range,
)
.leftNel

// the service exists, but doesn't have the requested operation
case Some(service)
if !service.operationNames.contains_(OperationName(operationName.source)) =>
CompilationError
.error(
CompilationErrorDetails.OperationMissing(service.operationNames.toList),
operationName.range,
)
.leftNel

// all good
case Some(_) => ref.asRight
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ object CompletionProvider {
sf.select(_.prelude.use_clause),
)
.toOption
.flatten

ctx match {
case NodeContext.PathEntry.AtOperationName ^^: EmptyPath =>
Expand Down
1 change: 1 addition & 0 deletions tree-sitter-smithyql/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = grammar({

operation_name_qualifier: ($) => seq($.qualified_identifier, "."),

// todo: model as union?
query_operation_name: ($) =>
seq(
field("identifier", optional($.operation_name_qualifier)),
Expand Down

0 comments on commit 4408463

Please sign in to comment.