diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 6fdc6f1151e16..7f800f0539441 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -98,6 +98,7 @@ | mermaid | ✓ | | | | | meson | ✓ | | ✓ | | | mint | | | | `mint` | +| mojo | ✓ | | | `mojo-lsp-server` | | msbuild | ✓ | | ✓ | | | nasm | ✓ | ✓ | | | | nickel | ✓ | | ✓ | `nls` | diff --git a/languages.toml b/languages.toml index 77c629e494626..43066efe4b40a 100644 --- a/languages.toml +++ b/languages.toml @@ -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" } @@ -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" } + diff --git a/runtime/queries/mojo/highlights.scm b/runtime/queries/mojo/highlights.scm new file mode 100644 index 0000000000000..9488133b97aa9 --- /dev/null +++ b/runtime/queries/mojo/highlights.scm @@ -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