Skip to content

Commit

Permalink
feat: adds mojo language support
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Davis <[email protected]>
  • Loading branch information
mabasic and the-mikedavis committed Oct 29, 2023
1 parent 31f50bf commit d3bd1c5
Show file tree
Hide file tree
Showing 3 changed files with 155 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 @@ -98,6 +98,7 @@
| mermaid || | | |
| meson || || |
| mint | | | | `mint` |
| mojo || | | `mojo-lsp-server` |
| msbuild || || |
| nasm ||| | |
| nickel || || `nls` |
Expand Down
16 changes: 16 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ltex-ls = { command = "ltex-ls" }
markdoc-ls = { command = "markdoc-ls", args = ["--stdio"] }
marksman = { command = "marksman", args = ["server"] }
metals = { command = "metals", config = { "isHttpEnabled" = true } }
mojo = { command = "mojo-lsp-server" }
mint = { command = "mint", args = ["ls"] }
nil = { command = "nil" }
nimlangserver = { command = "nimlangserver" }
Expand Down Expand Up @@ -3012,3 +3013,18 @@ language-servers = [ "templ" ]
[[grammar]]
name = "templ"
source = { git = "https://github.com/vrischmann/tree-sitter-templ", rev = "ea56ac0655243490a4929a988f4eaa91dfccc995" }

[[language]]
name = "mojo"
scope = "source.mojo"
roots = []
injection-regex = "mojo"
file-types = ["mojo", "🔥"]
comment-token = "#"
indent = { tab-width = 4, unit = " " }
language-servers = [ "mojo" ]

[[grammar]]
name = "mojo"
source = { git = "https://github.com/realprogrammersusevim/tree-sitter-mojo", rev = "f241530d0197c0ddfc0372c60be39221693f9196" }

138 changes: 138 additions & 0 deletions runtime/queries/mojo/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
; Identifier naming conventions

((identifier) @constructor
(#match? @constructor "^[A-Z]"))

((identifier) @constant
(#match? @constant "^[A-Z][A-Z_]*$"))

; Builtin functions

((call
function: (identifier) @function.builtin)
(#match?
@function.builtin
"^(abs|all|any|ascii|bin|bool|breakpoint|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dict|dir|divmod|enumerate|eval|exec|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|isinstance|issubclass|iter|len|list|locals|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|range|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|vars|zip|__import__|__mlir_attr|__mlir_op|__mlir_type)$"))

; Function calls

(decorator) @function

(call
function: (attribute attribute: (identifier) @function.method))
(call
function: (identifier) @function)

; Function definitions

(function_definition
name: (identifier) @function)

(identifier) @variable
(attribute attribute: (identifier) @variable.other.member)
(type (identifier) @type)

; Literals

[
(none)
(true)
(false)
] @constant.builtin

(integer) @constant.numeric.integer
(float) @constant.numeric.float

(comment) @comment
(string) @string
(escape_sequence) @constant.character.escape

(interpolation
"{" @punctuation.special
"}" @punctuation.special) @embedded

[
"-"
"-="
"!="
"*"
"**"
"**="
"*="
"/"
"//"
"//="
"/="
"&"
"&="
"%"
"%="
"^"
"^="
"+"
"->"
"+="
"<"
"<<"
"<<="
"<="
"<>"
"="
":="
"=="
">"
">="
">>"
">>="
"|"
"|="
"~"
"@="
"and"
"in"
"is"
"not"
"or"
] @operator

[
"as"
"assert"
"async"
"await"
"break"
"class"
"continue"
"def"
"del"
"elif"
"else"
"except"
"exec"
"finally"
"for"
"from"
"global"
"if"
"import"
"lambda"
"nonlocal"
"pass"
"print"
"raise"
"return"
"try"
"while"
"with"
"yield"
"match"
"case" ; New keywords
"struct",
"fn",
"var",
"let",
"alias"
"owned",
"borrowed",
"inout"
] @keyword

0 comments on commit d3bd1c5

Please sign in to comment.