From b437b8b0eed868078ea97737d919a95eca4b7cb0 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 6 May 2024 18:04:32 +0200 Subject: [PATCH] Add support for Inko (#10656) This adds formatting and Tree-sitter support for Inko (https://inko-lang.org/). --- book/src/generated/lang-support.md | 1 + languages.toml | 15 +++ runtime/queries/inko/highlights.scm | 193 +++++++++++++++++++++++++++ runtime/queries/inko/indents.scm | 36 +++++ runtime/queries/inko/injections.scm | 2 + runtime/queries/inko/locals.scm | 10 ++ runtime/queries/inko/textobjects.scm | 38 ++++++ 7 files changed, 295 insertions(+) create mode 100644 runtime/queries/inko/highlights.scm create mode 100644 runtime/queries/inko/indents.scm create mode 100644 runtime/queries/inko/injections.scm create mode 100644 runtime/queries/inko/locals.scm create mode 100644 runtime/queries/inko/textobjects.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index f9d3dab20..27fd583c2 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -90,6 +90,7 @@ | idris | | | | `idris2-lsp` | | iex | ✓ | | | | | ini | ✓ | | | | +| inko | ✓ | ✓ | ✓ | | | janet | ✓ | | | | | java | ✓ | ✓ | ✓ | `jdtls` | | javascript | ✓ | ✓ | ✓ | `typescript-language-server` | diff --git a/languages.toml b/languages.toml index ace01e968..498e9c717 100644 --- a/languages.toml +++ b/languages.toml @@ -2691,6 +2691,21 @@ indent = { tab-width = 4, unit = "\t" } name = "ini" source = { git = "https://github.com/justinmk/tree-sitter-ini", rev = "4d247fb876b4ae6b347687de4a179511bf67fcbc" } +[[language]] +name = "inko" +auto-format = true +scope = "source.inko" +injection-regex = "inko" +file-types = ["inko"] +roots = ["inko.pkg"] +comment-token = "#" +indent = { tab-width = 2, unit = " " } +formatter = { command = "inko", args = ["fmt", "-"] } + +[[grammar]] +name = "inko" +source = { git = "https://github.com/inko-lang/tree-sitter-inko", rev = "6983354c13a14bc621d7a3619f1790149e901187" } + [[language]] name = "bicep" scope = "source.bicep" diff --git a/runtime/queries/inko/highlights.scm b/runtime/queries/inko/highlights.scm new file mode 100644 index 000000000..2f1cdc127 --- /dev/null +++ b/runtime/queries/inko/highlights.scm @@ -0,0 +1,193 @@ +; Brackets and operators +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ + "," + "." + ":" +] @punctuation.delimiter + +[ + "!=" + "%" + "%=" + "&" + "&=" + "*" + "**" + "**=" + "*=" + "+" + "+=" + "-" + "-=" + "/" + "/=" + "<" + "<<" + "<<=" + "<=" + "<=" + "==" + ">" + ">=" + ">=" + ">>" + ">>=" + ">>>" + ">>>=" + "^" + "^=" + "|" + "|=" +] @operator + +; Keywords +[ + "as" + "for" + "impl" + "let" + "mut" + "ref" + "uni" + "move" + "recover" +] @keyword + +"fn" @keyword.function + +"import" @keyword.control.import + +[ + "and" + "or" +] @keyword.operator + +[ + "class" + "trait" +] @keyword.storage.type + +[ + "extern" + (modifier) + (visibility) +] @keyword.storage.modifier + +[ + "loop" + "while" + (break) + (next) +] @keyword.control.repeat + +"return" @keyword.control.return + +[ + "throw" + "try" +] @keyword.control.exception + +[ + "case" + "else" + "if" + "match" +] @keyword.control.conditional + +; Comments +(line_comment) @comment.line + +; Literals +(self) @variable.builtin + +(nil) @constant.builtin + +[ + (true) + (false) +] @constant.builtin.boolean + +(integer) @constant.numeric.integer + +(float) @constant.numeric.float + +(string) @string + +(escape_sequence) @constant.character.escape + +(interpolation + "${" @punctuation.special + "}" @punctuation.special) + +(constant) @constant + +; Patterns +(integer_pattern) @constant.numeric.integer + +(string_pattern) @string + +(constant_pattern) @constant + +; Types +(generic_type + name: _ @type) + +(type) @type + +; Imports +(extern_import + path: _ @string) + +; Classes +(class + name: _ @type) + +(define_field + name: _ @variable.other.member) + +; Traits +(trait + name: _ @type) + +; Implementations +(implement_trait + class: _ @type) + +(reopen_class + name: _ @type) + +(bound + name: _ @type) + +; Methods +(method + name: _ @function) + +(external_function + name: _ @function) + +(argument + name: _ @variable.parameter) + +(named_argument + name: _ @variable.parameter) + +(call + name: _ @function) + +(field) @variable.other.member + +; Identifiers/variable references +((identifier) @function + (#is-not? local)) + +(identifier) @variable diff --git a/runtime/queries/inko/indents.scm b/runtime/queries/inko/indents.scm new file mode 100644 index 000000000..973e21269 --- /dev/null +++ b/runtime/queries/inko/indents.scm @@ -0,0 +1,36 @@ +[ + (arguments) + (array) + (assign_field) + (assign_local) + (assign_receiver_field) + (binary) + (block) + (bounds) + (cast) + (class) + (class_pattern) + (compound_assign_field) + (compound_assign_local) + (compound_assign_receiver_field) + (define_constant) + (define_variable) + (grouped_expression) + (implement_trait) + (match) + (or_pattern) + (reopen_class) + (replace_field) + (replace_local) + (symbols) + (trait) + (tuple) + (tuple_pattern) + (type_arguments) +] @indent + +[ + ")" + "]" + "}" +] @outdent diff --git a/runtime/queries/inko/injections.scm b/runtime/queries/inko/injections.scm new file mode 100644 index 000000000..36849c873 --- /dev/null +++ b/runtime/queries/inko/injections.scm @@ -0,0 +1,2 @@ +((line_comment) @injection.content + (#set! injection.language "comment")) diff --git a/runtime/queries/inko/locals.scm b/runtime/queries/inko/locals.scm new file mode 100644 index 000000000..3266bcae0 --- /dev/null +++ b/runtime/queries/inko/locals.scm @@ -0,0 +1,10 @@ +[ + (method) + (block) +] @local.scope + +(argument name: _ @local.definition) +(define_variable name: _ @local.definition) +(named_argument name: _ @local.definition) + +(identifier) @local.reference diff --git a/runtime/queries/inko/textobjects.scm b/runtime/queries/inko/textobjects.scm new file mode 100644 index 000000000..304333808 --- /dev/null +++ b/runtime/queries/inko/textobjects.scm @@ -0,0 +1,38 @@ +(class + body: (_) @class.inside) @class.around + +(trait + body: (_) @class.inside) @class.around + +(method + body: (_) @function.inside) @function.around + +(reopen_class + body: (_) @class.inside) @class.around + +(implement_trait + body: (_) @class.inside) @class.around + +(external_function + body: (_) @function.inside) @function.around + +(closure + body: (_) @function.inside) @function.around + +(arguments + ((_) @parameter.inside . ","? @parameter.around) @parameter.around) + +(type_arguments + ((_) @parameter.inside . ","? @parameter.around) @parameter.around) + +(line_comment) @comment.inside + +(line_comment)+ @comment.around + +(array (_) @entry.around) + +(tuple (_) @entry.around) + +(tuple_pattern (_) @entry.around) + +(define_field (_) @entry.inside) @entry.around