Repository: helix-editor/helix (language: rust)

Issue:
Grammars: Missing support for proto2
I'm planning to work on this, so feel free to assign (I don't have permissions).

### Current situation:

- Grammar used by Helix is https://github.com/yusdacra/tree-sitter-protobuf at `19c211a01434d9f03efff99f85e19f967591b175`
  - [Queries](https://github.com/helix-editor/helix/tree/master/runtime/queries/protobuf)
- Grammar used by nvim is https://github.com/treywood/tree-sitter-proto (pinned at [current main](https://github.com/nvim-treesitter/nvim-treesitter/blob/fb2d41ec599b68af041f3071ada883718928e279/lockfile.json#L582))

### Problems of current situation:

- no proto2 support (also no support [Editions](https://protobuf.dev/editions/overview/) but this is not supported anywhere so out of scope for now)
- different grammar than nvim leads to fragmentation
- neither of the grammars' feature sets is a superset of the other one --> upstream work needed
- inconsistent language identifier (`proto` vs `protobuf`)

### Plan of action

- [ ] agree with @yusdacra and @treywood on a unification plan. Probably consolidating on treywood/tree-sitter-proto is easier because its [network graph](https://github.com/treywood/tree-sitter-proto/network) is larger (e.g it's used by [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter?tab=readme-ov-file#supported-languages)).
  - [X] reach out to @yusdacra to get agreement for that
  - [X] reach out to @treywood about adding missing features to https://github.com/treywood/tree-sitter-proto
- [x] implement missing features in https://github.com/treywood/tree-sitter-proto
- [ ] get missing features into https://github.com/treywood/tree-sitter-proto master branch - [PR](https://github.com/treywood/tree-sitter-proto/pull/2)
- [ ] switch Helix over to the new grammars (and `proto` identifier)
- [ ] fix [reverse-query-precedence-ordering branch](https://github.com/helix-editor/helix/tree/reverse-query-precedence-ordering) if needed

### Analysis of missing features

Features missing for [highlights.scm](https://github.com/helix-editor/helix/blob/master/runtime/queries/protobuf/highlights.scm):

- missing `mapName`, `extendName`, `fieldName` and `enumVariantName`
- missing `optionName` - this is fixed in the [`fixups` branch](https://github.com/treywood/tree-sitter-proto/tree/fixups) but needs merging into main

Features missing for [indents.scm](https://github.com/helix-editor/helix/blob/master/runtime/queries/protobuf/indents.scm):

- `oneofBody`, `serviceBody` and `rpcBody` are missing. You can use `oneof`, `service` and `rpc` instead, but this probably leads to some regressions. Not sure if there is a severe enough case to block on this. I noticed a difference with declarations like this in `hybrid` indent heuristic, but they actually both misbehave.
  ```
  rpc FooRpc(FooRpcRequest)
      returns (FooRpcResponse) {
    option deadline = 20.0;
  }
  ```

Features missing for [textobjects.scm](https://github.com/helix-editor/helix/blob/master/runtime/queries/protobuf/textobjects.scm):
 - missing `serviceBody`



Discussion / hints:
@yusdacra @treywood - feel free to comment directly here on the above. Otherwise I'll try to reach out more directly.
yeah sure, i don't mind unifying work somewhere else. i haven't looked at the grammar in a long while anyway 😅 
Couldn't get in touch with @treywood so far. There is also an [open PR](https://github.com/treywood/tree-sitter-proto/pull/1) without a response after 3 weeks. So upstreaming may be difficult.

My updated plan is now to create a new fork with the following features:
 * based on https://github.com/treywood/tree-sitter-proto/tree/fixups . This should make it easier to eventually merge them back, or to move nvim over to my fork.
 * having a deep look through https://github.com/treywood/tree-sitter-proto/network to find useful additions. Presumably the issues above have already been fixed.

Fix patch:
diff --git a/languages.toml b/languages.toml
index 23bd5fc93234..81ca7e77f7bb 100644
--- a/languages.toml
+++ b/languages.toml
@@ -340,16 +340,17 @@ source = { git = "https://github.com/Beaglefoot/tree-sitter-awk", rev = "a799bc5
 [[language]]
 name = "protobuf"
 scope = "source.proto"
-injection-regex = "protobuf"
+injection-regex = "proto"
 file-types = ["proto"]
 language-servers = [ "bufls", "pbkit" ]
 comment-token = "//"
 block-comment-tokens = { start = "/*", end = "*/" }
 indent = { tab-width = 2, unit = "  " }
+grammar = "proto"
 
 [[grammar]]
-name = "protobuf"
-source = { git = "https://github.com/yusdacra/tree-sitter-protobuf", rev = "19c211a01434d9f03efff99f85e19f967591b175"}
+name = "proto"
+source = { git = "https://github.com/sdoerner/tree-sitter-proto", rev = "778ab6ed18a7fcf82c83805a87d63376c51e80bc"}
 
 [[language]]
 name = "textproto"
diff --git a/runtime/queries/protobuf/highlights.scm b/runtime/queries/protobuf/highlights.scm
index 6deee7df8116..15dd7bb3a578 100644
--- a/runtime/queries/protobuf/highlights.scm
+++ b/runtime/queries/protobuf/highlights.scm
@@ -1,5 +1,6 @@
 [
   "syntax"
+  "edition"
   "package"
   "option"
   "import"
@@ -7,44 +8,45 @@
   "rpc"
   "returns"
   "message"
+  "map"
   "enum"
   "oneof"
   "repeated"
+  "optional"
+  "required"
   "reserved"
   "to"
   "stream"
   "extend"
-  "optional"
 ] @keyword
 
 [
-  (keyType)
+  (key_type)
   (type)
+  (message_or_enum_type)
 ] @type.builtin
 
 [
-  (mapName)
-  (enumName)
-  (messageName)
-  (extendName)
-  (serviceName)
-  (rpcName)
+  (enum_name)
+  (message_name)
+  (service_name)
+  (rpc_name)
 ] @type
 
 [
-  (fieldName)
-  (optionName)
+  (field_name)
+  (option_name)
 ] @variable.other.member
-(enumVariantName) @type.enum.variant
+(enum_variant_name) @type.enum.variant
 
-(fullIdent) @namespace
+(full_ident) @namespace
 
-(intLit) @constant.numeric.integer
-(floatLit) @constant.numeric.float
-(boolLit) @constant.builtin.boolean
-(strLit) @string
+(int_lit) @constant.numeric.integer
+(float_lit) @constant.numeric.float
+(bool) @constant.builtin.boolean
+(string) @string
 
-(constant) @constant
+(block_lit) @constant
 
 (comment) @comment
 
@@ -55,12 +57,8 @@
   "]"
   "{"
   "}"
-] @punctuation.bracket
+]  @punctuation.bracket
 
-[
-  "="
-] @operator
+"=" @operator
 
-[
-  ";"
-] @punctuation.delimiter
+";" @punctuation.delimiter
diff --git a/runtime/queries/protobuf/indents.scm b/runtime/queries/protobuf/indents.scm
index d457d75f1998..d55e81b2da17 100644
--- a/runtime/queries/protobuf/indents.scm
+++ b/runtime/queries/protobuf/indents.scm
@@ -1,10 +1,10 @@
 [
-  (messageBody)
-  (enumBody)
-  (oneofBody)
-  (serviceBody)
-  (rpcBody)
-  (msgLit)
+  (message_body)
+  (enum_body)
+  (oneof_body)
+  (service_body)
+  (rpc_body)
+  (block_lit)
 ] @indent
 
 "}" @outdent
diff --git a/runtime/queries/protobuf/textobjects.scm b/runtime/queries/protobuf/textobjects.scm
index 6f06b13498b3..7b0cfb198557 100644
--- a/runtime/queries/protobuf/textobjects.scm
+++ b/runtime/queries/protobuf/textobjects.scm
@@ -1,9 +1,9 @@
-(message (messageBody) @class.inside) @class.around
-(enum (enumBody) @class.inside) @class.around
-(service (serviceBody) @class.inside) @class.around
+(message (message_body) @class.inside) @class.around
+(enum (enum_body) @class.inside) @class.around
+(service (service_body) @class.inside) @class.around
 
-(rpc (enumMessageType) @parameter.inside) @function.inside
-(rpc (enumMessageType) @parameter.around) @function.around
+(rpc (message_or_enum_type) @parameter.inside) @function.inside
+(rpc (message_or_enum_type) @parameter.around) @function.around
 
 (comment) @comment.inside
 (comment)+ @comment.around


Test patch: