From 13e3ce3bf41521551b8d1daf401d31938f62e7ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=B5=E6=9B=A6?= Date: Mon, 11 Aug 2025 15:21:23 +0800 Subject: [PATCH] feat(sproto): add parser --- SUPPORTED_LANGUAGES.md | 1 + lua/nvim-treesitter/parsers.lua | 8 +++++ runtime/queries/sproto/folds.scm | 6 ++++ runtime/queries/sproto/highlights.scm | 47 +++++++++++++++++++++++++++ runtime/queries/sproto/indents.scm | 10 ++++++ runtime/queries/sproto/injections.scm | 2 ++ 6 files changed, 74 insertions(+) create mode 100644 runtime/queries/sproto/folds.scm create mode 100644 runtime/queries/sproto/highlights.scm create mode 100644 runtime/queries/sproto/indents.scm create mode 100644 runtime/queries/sproto/injections.scm diff --git a/SUPPORTED_LANGUAGES.md b/SUPPORTED_LANGUAGES.md index 7a7f23505..ceb928e72 100644 --- a/SUPPORTED_LANGUAGES.md +++ b/SUPPORTED_LANGUAGES.md @@ -269,6 +269,7 @@ jsx (queries only)[^jsx] | unstable | `HFIJ ` | | @steelsojka [sosl](https://github.com/aheber/tree-sitter-sfapex) | unstable | `H    ` | | @aheber, @xixiafinland [sourcepawn](https://github.com/nilshelmig/tree-sitter-sourcepawn) | unstable | `H  JL` | | @Sarrus1 [sparql](https://github.com/GordianDziwis/tree-sitter-sparql) | unstable | `HFIJL` | | @GordianDziwis +[sproto](https://github.com/hanxi/tree-sitter-sproto) | unstable | `HFIJ ` | | @hanxi [sql](https://github.com/derekstride/tree-sitter-sql) | unstable | `HFIJ ` | | @derekstride [squirrel](https://github.com/tree-sitter-grammars/tree-sitter-squirrel) | unstable | `HFIJL` | | @amaanq [ssh_config](https://github.com/tree-sitter-grammars/tree-sitter-ssh-config) | unstable | `HFIJL` | | @ObserverOfTime diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 2cb92ef3b..98e9ef78a 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -2115,6 +2115,14 @@ return { maintainers = { '@GordianDziwis' }, tier = 2, }, + sproto = { + install_info = { + revision = 'd554c1456e35e7b2690552d52921c987d0cf6799', + url = 'https://github.com/hanxi/tree-sitter-sproto', + }, + maintainers = { '@hanxi' }, + tier = 2, + }, sql = { install_info = { branch = 'gh-pages', diff --git a/runtime/queries/sproto/folds.scm b/runtime/queries/sproto/folds.scm new file mode 100644 index 000000000..03253d108 --- /dev/null +++ b/runtime/queries/sproto/folds.scm @@ -0,0 +1,6 @@ +[ + (type_definition) + (protocol_definition) + (request_block) + (response_block) +] @fold diff --git a/runtime/queries/sproto/highlights.scm b/runtime/queries/sproto/highlights.scm new file mode 100644 index 000000000..cd86ed22d --- /dev/null +++ b/runtime/queries/sproto/highlights.scm @@ -0,0 +1,47 @@ +(comment) @comment @spell + +[ + "." + ":" +] @punctuation.delimiter + +"*" @operator + +[ + "request" + "response" +] @keyword + +(type_definition + name: (identifier) @type) + +(nested_type_definition + name: (identifier) @type) + +(type_specifier) @type + +[ + "integer" + "boolean" + "string" + "binary" + "double" +] @type.builtin + +(protocol_definition + name: (identifier) @function) + +(field_definition + name: (identifier) @property) + +(map_specifier + key: (identifier) @property) + +(integer) @number + +[ + "(" + ")" + "{" + "}" +] @punctuation.bracket diff --git a/runtime/queries/sproto/indents.scm b/runtime/queries/sproto/indents.scm new file mode 100644 index 000000000..33147d540 --- /dev/null +++ b/runtime/queries/sproto/indents.scm @@ -0,0 +1,10 @@ +[ + (type_definition) + (protocol_definition) + (request_block) + (response_block) +] @indent.begin + +"}" @indent.end @indent.branch + +(comment) @indent.auto diff --git a/runtime/queries/sproto/injections.scm b/runtime/queries/sproto/injections.scm new file mode 100644 index 000000000..2f0e58eb6 --- /dev/null +++ b/runtime/queries/sproto/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment"))