From 6c8dc8e7c2aa15642a142fd3aeb62a7cc1027e32 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 4 May 2023 09:36:34 -0700 Subject: [PATCH 1/6] GN language support --- languages.toml | 14 +++++++++ runtime/queries/gn/highlights.scm | 50 +++++++++++++++++++++++++++++++ runtime/queries/gn/locals.scm | 16 ++++++++++ 3 files changed, 80 insertions(+) create mode 100644 runtime/queries/gn/highlights.scm create mode 100644 runtime/queries/gn/locals.scm diff --git a/languages.toml b/languages.toml index 81ba471e3c40..a18c3c0581fd 100644 --- a/languages.toml +++ b/languages.toml @@ -2520,3 +2520,17 @@ indent = { tab-width = 4, unit = "\t" } [[grammar]] name = "just" source = { git = "https://github.com/IndianBoy42/tree-sitter-just", rev = "8af0aab79854aaf25b620a52c39485849922f766" } + +[[language]] +name = "gn" +scope = "source.gn" +injection-regex = "gn" +file-types = ["gn", "gni"] +roots = [] +comment-token = "#" +indent = { tab-width = 2, unit = " " } +formatter = { command = "gn", args = ["format", "--stdin"] } + +[[grammar]] +name = "gn" +source = { git = "https://github.com/willcassella/tree-sitter-gn", rev = "e18d6e36a79b20dafb58f19d407bd38b0e60260e" } diff --git a/runtime/queries/gn/highlights.scm b/runtime/queries/gn/highlights.scm new file mode 100644 index 000000000000..0036e31c6781 --- /dev/null +++ b/runtime/queries/gn/highlights.scm @@ -0,0 +1,50 @@ +; Copyright (C) 2021 Will Cassella (github@willcassella.com) +; +; Licensed under the Apache License, Version 2.0 (the "License"); +; you may not use this file except in compliance with the License. +; You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, software +; distributed under the License is distributed on an "AS IS" BASIS, +; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; See the License for the specific language governing permissions and +; limitations under the License. + +(identifier) @variable +;((identifier) @variable (#is? @variable definition)) ; This doesn't work + +; This is really buggy +; (call target: (identifier) @_target (#eq? @_target "declare_args") +; (block (assignment target: (identifier) @parameter))) + +(scope_access field: (_) @field) + +(call target: (_) @function) + +[ "if" "else" ] @conditional + +[ + (assign_op) + (arithmetic_binary_op) + (comparison_binary_op) + (equivalence_binary_op) + (logical_and_binary_op) + (logical_or_binary_op) + (negation_unary_op) +] @operator + +[ "(" ")" "[" "]" "{" "}" ] @punctuation.bracket +[ "." "," ] @punctuation.delimiter + +(string) @string +(string_escape) @string.escape +(string_expansion [ "$" "${" "}" ] @string.escape) +[ (integer) (hex) ] @number +(boolean) @boolean + +(comment) @comment +((comment) @todo (#match? @todo "TODO")) ; This doesn't work + +(ERROR) @error diff --git a/runtime/queries/gn/locals.scm b/runtime/queries/gn/locals.scm new file mode 100644 index 000000000000..032bea695a5d --- /dev/null +++ b/runtime/queries/gn/locals.scm @@ -0,0 +1,16 @@ +; Copyright (C) 2021 Will Cassella (github@willcassella.com) +; +; Licensed under the Apache License, Version 2.0 (the "License"); +; you may not use this file except in compliance with the License. +; You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, software +; distributed under the License is distributed on an "AS IS" BASIS, +; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; See the License for the specific language governing permissions and +; limitations under the License. + +(source_file) @scope +(assignment target: (identifier) @definition.var) From 7e7de9f43b60a0130c9b6713eaf392b0b4023f49 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 4 May 2023 10:15:10 -0700 Subject: [PATCH 2/6] Update runtime/queries/gn/highlights.scm Co-authored-by: Michael Davis --- runtime/queries/gn/highlights.scm | 2 -- 1 file changed, 2 deletions(-) diff --git a/runtime/queries/gn/highlights.scm b/runtime/queries/gn/highlights.scm index 0036e31c6781..77c766674bc0 100644 --- a/runtime/queries/gn/highlights.scm +++ b/runtime/queries/gn/highlights.scm @@ -46,5 +46,3 @@ (comment) @comment ((comment) @todo (#match? @todo "TODO")) ; This doesn't work - -(ERROR) @error From 155df00d7678f39637166fc86be17d21a88ba7ff Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 4 May 2023 14:22:15 -0700 Subject: [PATCH 3/6] Review --- runtime/queries/gn/highlights.scm | 17 ++++++++--------- runtime/queries/gn/locals.scm | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/runtime/queries/gn/highlights.scm b/runtime/queries/gn/highlights.scm index 77c766674bc0..4e6189c0fff0 100644 --- a/runtime/queries/gn/highlights.scm +++ b/runtime/queries/gn/highlights.scm @@ -12,18 +12,18 @@ ; See the License for the specific language governing permissions and ; limitations under the License. -(identifier) @variable +(identifier) @variable.builtin ;((identifier) @variable (#is? @variable definition)) ; This doesn't work ; This is really buggy ; (call target: (identifier) @_target (#eq? @_target "declare_args") ; (block (assignment target: (identifier) @parameter))) -(scope_access field: (_) @field) +(scope_access field: (_) @variable.other.member) (call target: (_) @function) -[ "if" "else" ] @conditional +[ "if" "else" ] @keyword.control.conditional [ (assign_op) @@ -39,10 +39,9 @@ [ "." "," ] @punctuation.delimiter (string) @string -(string_escape) @string.escape -(string_expansion [ "$" "${" "}" ] @string.escape) -[ (integer) (hex) ] @number -(boolean) @boolean +(string_escape) @constant.character.escape +(string_expansion [ "$" "${" "}" ] @constant.character.escape) +[ (integer) (hex) ] @constant.numeric +(boolean) @constant.builtin.boolean -(comment) @comment -((comment) @todo (#match? @todo "TODO")) ; This doesn't work +((comment) @injection.content (#set! injection.language "comment")) diff --git a/runtime/queries/gn/locals.scm b/runtime/queries/gn/locals.scm index 032bea695a5d..026b0b6a272d 100644 --- a/runtime/queries/gn/locals.scm +++ b/runtime/queries/gn/locals.scm @@ -12,5 +12,5 @@ ; See the License for the specific language governing permissions and ; limitations under the License. -(source_file) @scope -(assignment target: (identifier) @definition.var) +(source_file) @local.scope +(assignment target: (identifier) @local.definition.var) From d9bd97fd8cf0560950b7addb806c4bcc56b6c929 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 4 May 2023 14:23:52 -0700 Subject: [PATCH 4/6] docs --- book/src/generated/lang-support.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 0dbbd69d2530..8b204790acb1 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -49,6 +49,7 @@ | git-rebase | ✓ | | | | | gleam | ✓ | ✓ | | `gleam` | | glsl | ✓ | ✓ | ✓ | | +| gn | ✓ | | | | | go | ✓ | ✓ | ✓ | `gopls` | | godot-resource | ✓ | | | | | gomod | ✓ | | | `gopls` | From 409fab81be3124e6b2f6bb6d5e9ab85da082350d Mon Sep 17 00:00:00 2001 From: Dan Field Date: Fri, 5 May 2023 14:38:10 -0700 Subject: [PATCH 5/6] more review --- runtime/queries/gn/highlights.scm | 6 +----- runtime/queries/gn/injections.scm | 15 +++++++++++++++ runtime/queries/gn/locals.scm | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 runtime/queries/gn/injections.scm diff --git a/runtime/queries/gn/highlights.scm b/runtime/queries/gn/highlights.scm index 4e6189c0fff0..84f59e8257a9 100644 --- a/runtime/queries/gn/highlights.scm +++ b/runtime/queries/gn/highlights.scm @@ -13,11 +13,6 @@ ; limitations under the License. (identifier) @variable.builtin -;((identifier) @variable (#is? @variable definition)) ; This doesn't work - -; This is really buggy -; (call target: (identifier) @_target (#eq? @_target "declare_args") -; (block (assignment target: (identifier) @parameter))) (scope_access field: (_) @variable.other.member) @@ -44,4 +39,5 @@ [ (integer) (hex) ] @constant.numeric (boolean) @constant.builtin.boolean +(comment) @comment ((comment) @injection.content (#set! injection.language "comment")) diff --git a/runtime/queries/gn/injections.scm b/runtime/queries/gn/injections.scm new file mode 100644 index 000000000000..55864c293213 --- /dev/null +++ b/runtime/queries/gn/injections.scm @@ -0,0 +1,15 @@ +; Copyright (C) 2021 Will Cassella (github@willcassella.com) +; +; Licensed under the Apache License, Version 2.0 (the "License"); +; you may not use this file except in compliance with the License. +; You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, software +; distributed under the License is distributed on an "AS IS" BASIS, +; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; See the License for the specific language governing permissions and +; limitations under the License. + +((comment) @injection.content (#set! injection.language "comment")) diff --git a/runtime/queries/gn/locals.scm b/runtime/queries/gn/locals.scm index 026b0b6a272d..e8bd995c33ba 100644 --- a/runtime/queries/gn/locals.scm +++ b/runtime/queries/gn/locals.scm @@ -13,4 +13,4 @@ ; limitations under the License. (source_file) @local.scope -(assignment target: (identifier) @local.definition.var) +(assignment target: (identifier) @local.definition) From 68f6a86825be87ba3264f8ecea81273101842880 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Sat, 6 May 2023 09:42:47 -0700 Subject: [PATCH 6/6] Update runtime/queries/gn/highlights.scm Co-authored-by: Michael Davis --- runtime/queries/gn/highlights.scm | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/queries/gn/highlights.scm b/runtime/queries/gn/highlights.scm index 84f59e8257a9..ff619db111f4 100644 --- a/runtime/queries/gn/highlights.scm +++ b/runtime/queries/gn/highlights.scm @@ -40,4 +40,3 @@ (boolean) @constant.builtin.boolean (comment) @comment -((comment) @injection.content (#set! injection.language "comment"))