From fb60ea759a1aea8d19cf23214606e70283ac322b Mon Sep 17 00:00:00 2001 From: Stefan VanBuren Date: Fri, 13 Mar 2026 10:40:11 -0400 Subject: [PATCH 1/4] feat(proto): sync highlights with upstream Syncs with coder3101/tree-sitter-proto#22, which adjusts captures to better align with nvim-treesitter conventions: - Package idents use @module, extend/oneof idents use @type - Adds map_field, oneof_field @property captures - option/syntax/edition use @keyword.directive - extend/extensions/oneof/service moved to @keyword.type - key_type/type use @type.builtin; rpc_name uses @function.method - Import paths use @string.special.path - proto2/proto3 syntax strings use @string.special.symbol - Simplifies comment captures (removes doc comment distinction) Honestly not sure how well other tree-sitter clients handle the nvim-specific highlights, but I figure this is the primary client I'm (at least personally) concerned about. --- runtime/queries/proto/highlights.scm | 53 ++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/runtime/queries/proto/highlights.scm b/runtime/queries/proto/highlights.scm index 22df9002f..9175d8ebc 100644 --- a/runtime/queries/proto/highlights.scm +++ b/runtime/queries/proto/highlights.scm @@ -1,13 +1,27 @@ -(full_ident - (identifier) @variable) +(package + (full_ident + (identifier) @module)) -(full_ident - (identifier) - (identifier) @variable.member) +(extend + (full_ident + (identifier) @type)) + +(constant + (full_ident + (identifier) @constant)) (field (identifier) @property) +(map_field + (identifier) @property) + +(oneof + (identifier) @type) + +(oneof_field + (identifier) @property) + (field_option (identifier) @property) @@ -18,23 +32,26 @@ (identifier) @property) [ - "extend" - "extensions" - "oneof" "option" - "reserved" "syntax" "edition" +] @keyword.directive + +[ + "reserved" "to" "max" ] @keyword [ "enum" + "extend" + "extensions" "group" - "service" "message" "map" + "oneof" + "service" ] @keyword.type "rpc" @keyword.function @@ -60,22 +77,29 @@ [ (key_type) (type) +] @type.builtin + +[ (message_name) (enum_name) (service_name) - (rpc_name) (message_or_enum_type) ] @type +(rpc_name) @function.method + (enum_field (identifier) @constant) (string) @string +(import + path: (string) @string.special.path) + [ "\"proto3\"" "\"proto2\"" -] @string.special +] @string.special.symbol (escape_sequence) @string.escape @@ -88,10 +112,9 @@ (false) ] @boolean -(comment) @comment @spell +(comment) @spell -((comment) @comment.documentation - (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$")) +(comment) @comment [ "(" From d45b7245b8d90ea19b2c3d92e98b7b2477379b3c Mon Sep 17 00:00:00 2001 From: Stefan VanBuren Date: Fri, 13 Mar 2026 11:06:01 -0400 Subject: [PATCH 2/4] test(proto): Fix for upstream updates These all seem valid to me; it feels weird that the previous implementation considered subpackages `variable.member`, and similar with the option. --- tests/query/highlights/proto/test.proto | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/query/highlights/proto/test.proto b/tests/query/highlights/proto/test.proto index fdc610782..f037d8ef3 100644 --- a/tests/query/highlights/proto/test.proto +++ b/tests/query/highlights/proto/test.proto @@ -1,11 +1,11 @@ syntax = "proto2"; -// ^^^^^^^^ @string.special +// ^^^^^^^^ @string.special.symbol package sls.asfd.asfd; -// ^^^ @variable +// ^^^ @module // ^ @punctuation.delimiter -// ^^^^ @variable.member +// ^^^^ @module // ^ @punctuation.delimiter -// ^^^^ @variable.member +// ^^^^ @module // ^ @punctuation.delimiter import "github.com/gogo/protobuf/gogoproto/gogo.proto"; @@ -21,10 +21,6 @@ import "github.com/gogo/protobuf/gogoproto/gogo.proto"; option (gogoproto.sizer_all) = true; option (gogoproto.marshaler_all) = true; option (gogoproto.unmarshaler_all.foo) = true; -// ^^^^^^^^^ @variable -// ^^^^^^^^^^^^^^^ @variable.member -// ^ @punctuation.delimiter -// ^^^ @variable.member message LogContent //<- @keyword.type @@ -46,7 +42,7 @@ message LogContent optional JsonFormat json_format = 6 [ // ^^^^^^^^ @keyword.modifier retention = RETENTION_RUNTIME, -// ^^^^^^^^^^^^^^^^^ @variable +// ^^^^^^^^^^^^^^^^^ @constant // ^ @punctuation.delimiter targets = TARGET_TYPE_MESSAGE, // ^^^^^^^ @property @@ -60,3 +56,4 @@ message LogContent ]; } + From 86745d66a36a19603e0ec1f6b81e0bbc0924ba06 Mon Sep 17 00:00:00 2001 From: Stefan VanBuren Date: Fri, 13 Mar 2026 11:22:50 -0400 Subject: [PATCH 3/4] Re-add option handling; fix builtin type assertion Now need to wait for coder3101/tree-sitter-proto#23 to land to really sync this with upstream. --- runtime/queries/proto/highlights.scm | 10 ++++++++++ tests/query/highlights/proto/test.proto | 12 ++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/runtime/queries/proto/highlights.scm b/runtime/queries/proto/highlights.scm index 9175d8ebc..98b4db4ae 100644 --- a/runtime/queries/proto/highlights.scm +++ b/runtime/queries/proto/highlights.scm @@ -31,6 +31,16 @@ (block_lit (identifier) @property) +; Extension option names, e.g. option (foo.bar) = ... +(option + (full_ident + (identifier) @variable)) + +(option + (full_ident + (identifier) + (identifier) @variable.member)) + [ "option" "syntax" diff --git a/tests/query/highlights/proto/test.proto b/tests/query/highlights/proto/test.proto index f037d8ef3..7f8c3abdf 100644 --- a/tests/query/highlights/proto/test.proto +++ b/tests/query/highlights/proto/test.proto @@ -19,19 +19,27 @@ import "github.com/gogo/protobuf/gogoproto/gogo.proto"; //<- @keyword.import option (gogoproto.sizer_all) = true; +// ^^^^^^^^^ @variable +// ^^^^^^^^^ @variable.member option (gogoproto.marshaler_all) = true; +// ^^^^^^^^^ @variable +// ^^^^^^^^^^^^^ @variable.member option (gogoproto.unmarshaler_all.foo) = true; +// ^^^^^^^^^ @variable +// ^^^^^^^^^^^^^^^ @variable.member +// ^ @punctuation.delimiter +// ^^^ @variable.member message LogContent //<- @keyword.type { required string Key = 1; -// ^^^^^^ @type +// ^^^^^^ @type.builtin // ^^^ @property // ^ @operator // ^ @number required string Value = 2; -// ^^^^^^ @type +// ^^^^^^ @type.builtin // ^^^^^ @property required CustomType Value = 2; // ^^^^^^^^ @keyword.modifier From b294a93403995bf18c3368fba30da6bb5ac45a8d Mon Sep 17 00:00:00 2001 From: Stefan VanBuren Date: Tue, 17 Mar 2026 14:20:01 -0400 Subject: [PATCH 4/4] Apply suggested fix Since I can't via the GitHub UI. --- runtime/queries/proto/highlights.scm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/runtime/queries/proto/highlights.scm b/runtime/queries/proto/highlights.scm index 98b4db4ae..531209915 100644 --- a/runtime/queries/proto/highlights.scm +++ b/runtime/queries/proto/highlights.scm @@ -122,9 +122,7 @@ (false) ] @boolean -(comment) @spell - -(comment) @comment +(comment) @comment @spell [ "("