From 4144c9d2f2e712475d0ee54d029653f2c7dffff5 Mon Sep 17 00:00:00 2001 From: ttys3 <41882455+ttys3@users.noreply.github.com> Date: Thu, 21 Apr 2022 00:16:02 +0800 Subject: [PATCH] feat(lang): add go.mod and go.work support (#2197) --- book/src/generated/lang-support.md | 2 ++ languages.toml | 32 ++++++++++++++++++++++++++- runtime/queries/gomod/highlights.scm | 17 ++++++++++++++ runtime/queries/gomod/injections.scm | 2 ++ runtime/queries/gowork/highlights.scm | 14 ++++++++++++ runtime/queries/gowork/injections.scm | 2 ++ 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 runtime/queries/gomod/highlights.scm create mode 100644 runtime/queries/gomod/injections.scm create mode 100644 runtime/queries/gowork/highlights.scm create mode 100644 runtime/queries/gowork/injections.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index a1746c4c4..ef3c94513 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -24,6 +24,8 @@ | gleam | ✓ | | | | | glsl | ✓ | | ✓ | | | go | ✓ | ✓ | ✓ | `gopls` | +| gomod | ✓ | | | `gopls` | +| gowork | ✓ | | | `gopls` | | graphql | ✓ | | | | | haskell | ✓ | | | `haskell-language-server-wrapper` | | hcl | ✓ | | ✓ | `terraform-ls` | diff --git a/languages.toml b/languages.toml index fdf794a62..76b4ca167 100644 --- a/languages.toml +++ b/languages.toml @@ -268,6 +268,36 @@ args = { mode = "local", processId = "{0}" } name = "go" source = { git = "https://github.com/tree-sitter/tree-sitter-go", rev = "0fa917a7022d1cd2e9b779a6a8fc5dc7fad69c75" } +[[language]] +name = "gomod" +scope = "source.gomod" +injection-regex = "gomod" +file-types = ["go.mod"] +roots = [] +auto-format = true +comment-token = "//" +language-server = { command = "gopls" } +indent = { tab-width = 4, unit = "\t" } + +[[grammar]] +name = "gomod" +source = { git = "https://github.com/camdencheek/tree-sitter-go-mod", rev = "e8f51f8e4363a3d9a427e8f63f4c1bbc5ef5d8d0" } + +[[language]] +name = "gowork" +scope = "source.gowork" +injection-regex = "gowork" +file-types = ["go.work"] +roots = [] +auto-format = true +comment-token = "//" +language-server = { command = "gopls" } +indent = { tab-width = 4, unit = "\t" } + +[[grammar]] +name = "gowork" +source = { git = "https://github.com/omertuc/tree-sitter-go-work", rev = "6dd9dd79fb51e9f2abc829d5e97b15015b6a8ae2" } + [[language]] name = "javascript" scope = "source.js" @@ -998,7 +1028,7 @@ file-types = ["kt", "kts"] roots = ["settings.gradle", "settings.gradle.kts"] comment-token = "//" indent = { tab-width = 4, unit = " " } -language-server = { command = "kotlin-language-server" } +language-server = { command = "kotlin-language-server" } [[grammar]] name = "kotlin" diff --git a/runtime/queries/gomod/highlights.scm b/runtime/queries/gomod/highlights.scm new file mode 100644 index 000000000..63e1f0128 --- /dev/null +++ b/runtime/queries/gomod/highlights.scm @@ -0,0 +1,17 @@ +[ + "require" + "replace" + "go" + "exclude" + "retract" + "module" +] @keyword + +"=>" @operator + +(comment) @comment + +[ +(version) +(go_version) +] @string diff --git a/runtime/queries/gomod/injections.scm b/runtime/queries/gomod/injections.scm new file mode 100644 index 000000000..321c90add --- /dev/null +++ b/runtime/queries/gomod/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment")) diff --git a/runtime/queries/gowork/highlights.scm b/runtime/queries/gowork/highlights.scm new file mode 100644 index 000000000..9c84bcc44 --- /dev/null +++ b/runtime/queries/gowork/highlights.scm @@ -0,0 +1,14 @@ +[ + "replace" + "go" + "use" +] @keyword + +"=>" @operator + +(comment) @comment + +[ +(version) +(go_version) +] @string diff --git a/runtime/queries/gowork/injections.scm b/runtime/queries/gowork/injections.scm new file mode 100644 index 000000000..321c90add --- /dev/null +++ b/runtime/queries/gowork/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment"))