From f8c2825220bff70919b527ee68fe44e7b1dae4b2 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Thu, 31 Aug 2023 05:28:16 -0400 Subject: [PATCH] feat: add Kconfig --- README.md | 1 + lockfile.json | 3 ++ lua/nvim-treesitter/parsers.lua | 8 ++++ queries/kconfig/folds.scm | 9 ++++ queries/kconfig/highlights.scm | 81 +++++++++++++++++++++++++++++++++ queries/kconfig/indents.scm | 11 +++++ queries/kconfig/injections.scm | 2 + queries/kconfig/locals.scm | 17 +++++++ 8 files changed, 132 insertions(+) create mode 100644 queries/kconfig/folds.scm create mode 100644 queries/kconfig/highlights.scm create mode 100644 queries/kconfig/indents.scm create mode 100644 queries/kconfig/injections.scm create mode 100644 queries/kconfig/locals.scm diff --git a/README.md b/README.md index fcb175bd7..397163984 100644 --- a/README.md +++ b/README.md @@ -271,6 +271,7 @@ We are looking for maintainers to add more parsers and to write query files for - [x] [JSON with comments](https://gitlab.com/WhyNotHugo/tree-sitter-jsonc.git) (maintained by @WhyNotHugo) - [x] [jsonnet](https://github.com/sourcegraph/tree-sitter-jsonnet) (maintained by @nawordar) - [x] [julia](https://github.com/tree-sitter/tree-sitter-julia) (maintained by @theHamsta) +- [x] [kconfig](https://github.com/amaanq/tree-sitter-kconfig) (maintained by @amaanq) - [x] [kdl](https://github.com/amaanq/tree-sitter-kdl) (maintained by @amaanq) - [x] [kotlin](https://github.com/fwcd/tree-sitter-kotlin) (maintained by @SalBakraa) - [x] [lalrpop](https://github.com/traxys/tree-sitter-lalrpop) (maintained by @traxys) diff --git a/lockfile.json b/lockfile.json index 0d32e1b32..907bbf3fa 100644 --- a/lockfile.json +++ b/lockfile.json @@ -293,6 +293,9 @@ "julia": { "revision": "bb7e587837fdeda74dd510256253d60f59a1e2cd" }, + "kconfig": { + "revision": "4242bff4d92964a1cbaa95cb45a87a32b3e1c896" + }, "kdl": { "revision": "e180e05132c4cb229a8ba679b298790ef1eca77c" }, diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 5aa0e13ce..246d41eab 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -899,6 +899,14 @@ list.julia = { maintainers = { "@theHamsta" }, } +list.kconfig = { + install_info = { + url = "https://github.com/amaanq/tree-sitter-kconfig", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@amaanq" }, +} + list.kdl = { install_info = { url = "https://github.com/amaanq/tree-sitter-kdl", diff --git a/queries/kconfig/folds.scm b/queries/kconfig/folds.scm new file mode 100644 index 000000000..980667dfc --- /dev/null +++ b/queries/kconfig/folds.scm @@ -0,0 +1,9 @@ +[ + (config) + (menuconfig) + (choice) + (comment_entry) + (menu) + (if) + (help_text) +] @fold diff --git a/queries/kconfig/highlights.scm b/queries/kconfig/highlights.scm new file mode 100644 index 000000000..c18c69f69 --- /dev/null +++ b/queries/kconfig/highlights.scm @@ -0,0 +1,81 @@ +"source" @include + +[ + "mainmenu" + "config" + "menuconfig" + "choice" + "endchoice" + "comment" + "menu" + "endmenu" + "prompt" + "default" + "range" + "help" + (optional) + (modules) +] @keyword + +[ + "if" + "endif" + "depends on" + "select" + "imply" + "visible if" +] @conditional + +[ + "def_bool" + "def_tristate" +] @keyword.function + +[ + "||" + "&&" + "=" + "!=" + "<" + ">" + "<=" + ">=" + "!" +] @operator + +[ + "bool" + "tristate" + "int" + "hex" + "string" +] @type.builtin + +[ "(" ")" ] @punctuation.bracket + +(macro_variable ["$(" ")"] @punctuation.special) + +(symbol) @variable + +[ + (prompt) + (macro_content) + (text) +] @string + +(config name: (symbol) @constant) +(menuconfig name: (symbol) @constant) +(choice name: (symbol) @constant) + +((symbol) @constant + (#lua-match? @constant "[A-Z0-9]+")) + +(mainmenu name: (prompt) @text.title) +(comment_entry name: (prompt) @text.title) +(menu name: (prompt) @text.title) + +(source (prompt) @text.uri @string.special) + +(comment) @comment + +(ERROR) @error diff --git a/queries/kconfig/indents.scm b/queries/kconfig/indents.scm new file mode 100644 index 000000000..77f02e1f6 --- /dev/null +++ b/queries/kconfig/indents.scm @@ -0,0 +1,11 @@ +(help_text (text) @indent.auto) + +[ + (config) + (menuconfig) + (choice) + (comment_entry) + (menu) + (if) + (help_text) +] @indent.begin diff --git a/queries/kconfig/injections.scm b/queries/kconfig/injections.scm new file mode 100644 index 000000000..2f0e58eb6 --- /dev/null +++ b/queries/kconfig/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment")) diff --git a/queries/kconfig/locals.scm b/queries/kconfig/locals.scm new file mode 100644 index 000000000..3727cd94f --- /dev/null +++ b/queries/kconfig/locals.scm @@ -0,0 +1,17 @@ +[ + (symbol) + (prompt) +] @reference + +[ + (config) + (menuconfig) + (choice) + (comment_entry) + (menu) + (if) +] @scope + +(type_definition (prompt) @definition.var) +(type_definition (input_prompt (prompt) @definition.var)) +(type_definition_default (expression (prompt) @definition.var))