From 688e0199fd647f9a2ac72063b94d709e1d1842be Mon Sep 17 00:00:00 2001
From: Ryan Roden-Corrent <ryan@rcorre.net>
Date: Thu, 28 Dec 2023 14:28:45 -0500
Subject: [PATCH] Add textobject queries for protobuf grammar.

Given `message Foo {string s = 1;}`
- `mat` selects `message Foo {string s = 1}`
- `mit` selects `{string s = 1;}`

Given `service SearchService { rpc Search(Req) returns (Resp); }
- `mit` or `mat` selects `Req` or `Resp`
- `mif` or `maf` selects `rpc Search(Req) returns (Resp);`
- `mit` selects { rpc Search(Req) returns (Resp); }`
- `mat` selects `service SearchService { rpc Search(Req) returns (Resp); }`
---
 book/src/generated/lang-support.md       | 2 +-
 runtime/queries/protobuf/textobjects.scm | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 runtime/queries/protobuf/textobjects.scm

diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md
index 0c5b35cc6f08..e2fd9304db1e 100644
--- a/book/src/generated/lang-support.md
+++ b/book/src/generated/lang-support.md
@@ -127,7 +127,7 @@
 | ponylang | ✓ | ✓ | ✓ |  |
 | prisma | ✓ |  |  | `prisma-language-server` |
 | prolog |  |  |  | `swipl` |
-| protobuf | ✓ |  | ✓ | `bufls`, `pb` |
+| protobuf | ✓ | ✓ | ✓ | `bufls`, `pb` |
 | prql | ✓ |  |  |  |
 | purescript | ✓ | ✓ |  | `purescript-language-server` |
 | python | ✓ | ✓ | ✓ | `pylsp` |
diff --git a/runtime/queries/protobuf/textobjects.scm b/runtime/queries/protobuf/textobjects.scm
new file mode 100644
index 000000000000..6f06b13498b3
--- /dev/null
+++ b/runtime/queries/protobuf/textobjects.scm
@@ -0,0 +1,9 @@
+(message (messageBody) @class.inside) @class.around
+(enum (enumBody) @class.inside) @class.around
+(service (serviceBody) @class.inside) @class.around
+
+(rpc (enumMessageType) @parameter.inside) @function.inside
+(rpc (enumMessageType) @parameter.around) @function.around
+
+(comment) @comment.inside
+(comment)+ @comment.around