diff --git a/modules/core/src/main/scala/playground/MultiServiceResolver.scala b/modules/core/src/main/scala/playground/MultiServiceResolver.scala index ecd4f696..b65f8d97 100644 --- a/modules/core/src/main/scala/playground/MultiServiceResolver.scala +++ b/modules/core/src/main/scala/playground/MultiServiceResolver.scala @@ -60,8 +60,7 @@ object MultiServiceResolver { ): EitherNel[CompilationError, QualifiedIdentifier] = queryOperationName.name match { case Some(opName) => - // todo: this should be an Option in codegen. might be a bad grammar - queryOperationName.identifier.headOption match { + queryOperationName.identifier.flatMap(_.qualified_identifier) match { case Some(explicitRef) => resolveExplicitTs(serviceIndex, explicitRef, opName) case None => resolveImplicitTs(opName, serviceIndex, useClauses) diff --git a/modules/language-support/src/main/scala/playground/language/CompletionProvider.scala b/modules/language-support/src/main/scala/playground/language/CompletionProvider.scala index 65338216..53721322 100644 --- a/modules/language-support/src/main/scala/playground/language/CompletionProvider.scala +++ b/modules/language-support/src/main/scala/playground/language/CompletionProvider.scala @@ -120,7 +120,7 @@ object CompletionProvider { // includes the current query's service reference // as it wouldn't result in ading a use clause val presentServiceIdentifiers = { - q.select(_.operation_name.identifier) ++ + q.select(_.operation_name.identifier.qualified_identifier) ++ sf.select(_.prelude.use_clause.identifier) }.flatMap(ASTAdapter.decodeQI) diff --git a/modules/treesitter/src/main/resources/darwin-aarch64/libtree-sitter-smithyql.dylib b/modules/treesitter/src/main/resources/darwin-aarch64/libtree-sitter-smithyql.dylib index 0f570b11..b6e1fde7 100755 Binary files a/modules/treesitter/src/main/resources/darwin-aarch64/libtree-sitter-smithyql.dylib and b/modules/treesitter/src/main/resources/darwin-aarch64/libtree-sitter-smithyql.dylib differ diff --git a/modules/treesitter/src/main/resources/darwin-x86-64/libtree-sitter-smithyql.dylib b/modules/treesitter/src/main/resources/darwin-x86-64/libtree-sitter-smithyql.dylib index 3652c855..4ab1b3b4 100755 Binary files a/modules/treesitter/src/main/resources/darwin-x86-64/libtree-sitter-smithyql.dylib and b/modules/treesitter/src/main/resources/darwin-x86-64/libtree-sitter-smithyql.dylib differ diff --git a/modules/treesitter/src/main/resources/linux-aarch64/libtree-sitter-smithyql.so b/modules/treesitter/src/main/resources/linux-aarch64/libtree-sitter-smithyql.so index 8dbb9f2f..616d0dab 100755 Binary files a/modules/treesitter/src/main/resources/linux-aarch64/libtree-sitter-smithyql.so and b/modules/treesitter/src/main/resources/linux-aarch64/libtree-sitter-smithyql.so differ diff --git a/modules/treesitter/src/main/resources/linux-x86-64/libtree-sitter-smithyql.so b/modules/treesitter/src/main/resources/linux-x86-64/libtree-sitter-smithyql.so index 0a40d7e6..a29d0195 100755 Binary files a/modules/treesitter/src/main/resources/linux-x86-64/libtree-sitter-smithyql.so and b/modules/treesitter/src/main/resources/linux-x86-64/libtree-sitter-smithyql.so differ diff --git a/modules/treesitter/src/main/scala/playground/generated/nodes/OperationNameQualifier.scala b/modules/treesitter/src/main/scala/playground/generated/nodes/OperationNameQualifier.scala new file mode 100644 index 00000000..a193f952 --- /dev/null +++ b/modules/treesitter/src/main/scala/playground/generated/nodes/OperationNameQualifier.scala @@ -0,0 +1,39 @@ +// Generated code! Do not modify by hand. +package playground.generated.nodes + +import org.polyvariant.treesitter4s.Node +import playground.treesitter4s.std.Selection + +opaque type OperationNameQualifier <: Node = Node + +object OperationNameQualifier { + extension (node: OperationNameQualifier) { + def select[A](f: OperationNameQualifier.Selector => Selection[A]): List[A] = f(OperationNameQualifier.Selector(List(node))).path + // fields + + // typed children + def typedChildren: Option[QualifiedIdentifier] = node.children.collectFirst { + case QualifiedIdentifier(node) => node + } + // precise typed children + def qualified_identifier: Option[QualifiedIdentifier] = node.children.collectFirst { + case QualifiedIdentifier(node) => node + } + } + + def apply(node: Node): Either[String, OperationNameQualifier] = + if node.tpe == "operation_name_qualifier" + then Right(node) + else Left(s"Expected OperationNameQualifier, got ${node.tpe}") + + def unsafeApply(node: Node): OperationNameQualifier = apply(node).fold(sys.error, identity) + + def unapply(node: Node): Option[OperationNameQualifier] = apply(node).toOption + + final case class Selector(path: List[OperationNameQualifier]) extends Selection[OperationNameQualifier] { + def qualified_identifier: QualifiedIdentifier.Selector = QualifiedIdentifier.Selector(path.flatMap(_.qualified_identifier)) + + type Self = Selector + protected val remake = Selector.apply + } +} diff --git a/modules/treesitter/src/main/scala/playground/generated/nodes/QueryOperationName.scala b/modules/treesitter/src/main/scala/playground/generated/nodes/QueryOperationName.scala index 6e4ba9ad..cae47bc5 100644 --- a/modules/treesitter/src/main/scala/playground/generated/nodes/QueryOperationName.scala +++ b/modules/treesitter/src/main/scala/playground/generated/nodes/QueryOperationName.scala @@ -10,8 +10,8 @@ object QueryOperationName { extension (node: QueryOperationName) { def select[A](f: QueryOperationName.Selector => Selection[A]): List[A] = f(QueryOperationName.Selector(List(node))).path // fields - def identifier: List[QualifiedIdentifier] = node.fields.getOrElse("identifier", Nil).toList.collect { - case QualifiedIdentifier(node) => node + def identifier: Option[OperationNameQualifier] = node.fields.getOrElse("identifier", Nil).headOption.map { + case OperationNameQualifier(node) => node } def name: Option[OperationName] = node.fields.getOrElse("name", Nil).headOption.map { @@ -33,7 +33,7 @@ object QueryOperationName { def unapply(node: Node): Option[QueryOperationName] = apply(node).toOption final case class Selector(path: List[QueryOperationName]) extends Selection[QueryOperationName] { - def identifier: QualifiedIdentifier.Selector = QualifiedIdentifier.Selector(path.flatMap(_.identifier)) + def identifier: OperationNameQualifier.Selector = OperationNameQualifier.Selector(path.flatMap(_.identifier)) def name: OperationName.Selector = OperationName.Selector(path.flatMap(_.name)) type Self = Selector diff --git a/tree-sitter-smithyql/grammar.js b/tree-sitter-smithyql/grammar.js index 54b663f2..a1e1bfe0 100644 --- a/tree-sitter-smithyql/grammar.js +++ b/tree-sitter-smithyql/grammar.js @@ -47,12 +47,11 @@ module.exports = grammar({ field("selection", $.identifier) ), + operation_name_qualifier: ($) => seq($.qualified_identifier, "."), + query_operation_name: ($) => seq( - field( - "identifier", - optional(prec.left(seq($.qualified_identifier, "."))) - ), + field("identifier", optional($.operation_name_qualifier)), field("name", $.operation_name) ),