Skip to content

Commit

Permalink
Add support for Inko (helix-editor#10656)
Browse files Browse the repository at this point in the history
This adds formatting and Tree-sitter support for Inko
(https://inko-lang.org/).
  • Loading branch information
yorickpeterse authored and Vulpesx committed Jun 7, 2024
1 parent e22230b commit 6d31e9d
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 0 deletions.
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
| idris | | | | `idris2-lsp` |
| iex || | | |
| ini || | | |
| inko |||| |
| janet || | | |
| java |||| `jdtls` |
| javascript |||| `typescript-language-server` |
Expand Down
15 changes: 15 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
193 changes: 193 additions & 0 deletions runtime/queries/inko/highlights.scm
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions runtime/queries/inko/indents.scm
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions runtime/queries/inko/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((line_comment) @injection.content
(#set! injection.language "comment"))
10 changes: 10 additions & 0 deletions runtime/queries/inko/locals.scm
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions runtime/queries/inko/textobjects.scm
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6d31e9d

Please sign in to comment.