Initial public release of Warp.
Repo-Sync-Origin: warpdotdev/warp-internal@12af1d983b
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "languages"
|
||||
edition = "2021"
|
||||
authors = ["Warp Team <dev@warp.dev>"]
|
||||
publish.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
serde.workspace = true
|
||||
serde_yaml.workspace = true
|
||||
rust-embed.workspace = true
|
||||
arborium.workspace = true
|
||||
lazy_static.workspace = true
|
||||
warp_editor = { path = "../editor" }
|
||||
@@ -0,0 +1,21 @@
|
||||
# Language Grammars
|
||||
Example of how to add a new language grammar: https://github.com/warpdotdev/warp-internal/pull/11501/files
|
||||
|
||||
## TSLanguage
|
||||
We need a [TSLanguage(https://tree-sitter.github.io/tree-sitter/using-parsers#the-basic-objects) object to parse a source code file. We use open-source libraries that provide functions that create these objects. These functions are usually written in C but we can use them in Rust crates.
|
||||
|
||||
## config.yaml
|
||||
You can find this information on language specific documentation and style guides.
|
||||
|
||||
Another place to look is at Zed's config.toml files, e.g.: https://github.com/zed-industries/zed/blob/85bdd9329b550475aae34340e50abd4e79f2dd82/crates/languages/src/python/config.toml
|
||||
|
||||
**Note:** We don't use custom highlights.scm files - we use arborium's bundled highlighting queries instead.
|
||||
|
||||
## indents.scm
|
||||
This controls how we know when a cursor should be indented relative to the previous line.
|
||||
|
||||
Other code editors need this information so we can base ours on other open-source code editors. We primarily need to support indent and outdent captures. More full-featured code editors will support more advanced features.
|
||||
|
||||
Some example sources to check include:
|
||||
1. https://github.com/helix-editor/helix/blob/101a74bf6edbbfdf9b0628a0bdbbc307ebe10ff2/runtime/queries/python/indents.scm
|
||||
1. https://github.com/zed-industries/zed/blob/85bdd9329b550475aae34340e50abd4e79f2dd82/crates/languages/src/python/indents.scm
|
||||
@@ -0,0 +1,11 @@
|
||||
display_name: "C"
|
||||
indent_unit:
|
||||
space: 4
|
||||
comment_prefix: "//"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,12 @@
|
||||
(comment) @comment
|
||||
|
||||
; Function declarations
|
||||
(function_declarator declarator: (identifier) @definition)
|
||||
|
||||
; Class declarations
|
||||
(struct_specifier name: (type_identifier) @definition.class body:(_))
|
||||
(declaration type: (union_specifier name: (type_identifier) @definition.class))
|
||||
|
||||
; Type declarations
|
||||
(type_definition declarator: (type_identifier) @definition.type)
|
||||
(enum_specifier name: (type_identifier) @definition.type)
|
||||
@@ -0,0 +1,34 @@
|
||||
[
|
||||
(compound_statement)
|
||||
(declaration_list)
|
||||
(field_declaration_list)
|
||||
(enumerator_list)
|
||||
(parameter_list)
|
||||
(init_declarator)
|
||||
(expression_statement)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"case"
|
||||
"}"
|
||||
"]"
|
||||
")"
|
||||
] @outdent
|
||||
|
||||
(if_statement
|
||||
consequence: (_) @indent
|
||||
(#not-kind-eq? @indent "compound_statement")
|
||||
(#set! "scope" "all"))
|
||||
(while_statement
|
||||
body: (_) @indent
|
||||
(#not-kind-eq? @indent "compound_statement")
|
||||
(#set! "scope" "all"))
|
||||
(do_statement
|
||||
body: (_) @indent
|
||||
(#not-kind-eq? @indent "compound_statement")
|
||||
(#set! "scope" "all"))
|
||||
(for_statement
|
||||
")"
|
||||
(_) @indent
|
||||
(#not-kind-eq? @indent "compound_statement")
|
||||
(#set! "scope" "all"))
|
||||
@@ -0,0 +1,11 @@
|
||||
display_name: "C++"
|
||||
indent_unit:
|
||||
space: 4
|
||||
comment_prefix: "//"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,16 @@
|
||||
(comment) @comment
|
||||
|
||||
; Function declarations and definitions
|
||||
(function_declarator declarator: (identifier) @definition)
|
||||
(function_declarator declarator: (qualified_identifier name: (identifier) @definition))
|
||||
(function_declarator declarator: (field_identifier) @definition)
|
||||
(template_method name: (field_identifier) @definition)
|
||||
|
||||
; Class declarations
|
||||
(struct_specifier name: (type_identifier) @definition.class body:(_))
|
||||
(declaration type: (union_specifier name: (type_identifier) @definition.class))
|
||||
(class_specifier name: (type_identifier) @definition.class)
|
||||
|
||||
; Type declarations
|
||||
(type_definition declarator: (type_identifier) @definition.type)
|
||||
(enum_specifier name: (type_identifier) @definition.type)
|
||||
@@ -0,0 +1,35 @@
|
||||
[
|
||||
(compound_statement)
|
||||
(declaration_list)
|
||||
(field_declaration_list)
|
||||
(enumerator_list)
|
||||
(parameter_list)
|
||||
(init_declarator)
|
||||
(expression_statement)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"case"
|
||||
"}"
|
||||
"]"
|
||||
")"
|
||||
(access_specifier)
|
||||
] @outdent
|
||||
|
||||
(if_statement
|
||||
consequence: (_) @indent
|
||||
(#not-kind-eq? @indent "compound_statement")
|
||||
(#set! "scope" "all"))
|
||||
(while_statement
|
||||
body: (_) @indent
|
||||
(#not-kind-eq? @indent "compound_statement")
|
||||
(#set! "scope" "all"))
|
||||
(do_statement
|
||||
body: (_) @indent
|
||||
(#not-kind-eq? @indent "compound_statement")
|
||||
(#set! "scope" "all"))
|
||||
(for_statement
|
||||
")"
|
||||
(_) @indent
|
||||
(#not-kind-eq? @indent "compound_statement")
|
||||
(#set! "scope" "all"))
|
||||
@@ -0,0 +1,11 @@
|
||||
display_name: "C#"
|
||||
indent_unit:
|
||||
space: 4
|
||||
comment_prefix: "//"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,9 @@
|
||||
(comment) @comment
|
||||
|
||||
; Methods
|
||||
(method_declaration name: (identifier) @definition)
|
||||
(local_function_statement name: (identifier) @definition)
|
||||
|
||||
; Class declarations
|
||||
(class_declaration name: (identifier) @definition.class)
|
||||
(interface_declaration name: (identifier) @definition.interface)
|
||||
@@ -0,0 +1,8 @@
|
||||
[
|
||||
(assignment_expression)
|
||||
(if_statement)
|
||||
(for_statement)
|
||||
] @indent
|
||||
|
||||
(_ "{" "}" @end) @indent
|
||||
(_ "(" ")" @end) @indent
|
||||
@@ -0,0 +1,4 @@
|
||||
display_name: "CSS"
|
||||
indent_unit:
|
||||
space: 4
|
||||
brackets: []
|
||||
@@ -0,0 +1,3 @@
|
||||
(comment) @comment
|
||||
|
||||
(function_name) @definition.function
|
||||
@@ -0,0 +1,7 @@
|
||||
[
|
||||
(block)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"}"
|
||||
] @outdent
|
||||
@@ -0,0 +1,11 @@
|
||||
display_name: "Dockerfile"
|
||||
indent_unit:
|
||||
space: 4
|
||||
comment_prefix: "#"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,11 @@
|
||||
display_name: "Elixir"
|
||||
indent_unit:
|
||||
space: 2
|
||||
comment_prefix: "#"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,54 @@
|
||||
; Definitions
|
||||
|
||||
; * modules and protocols
|
||||
(call
|
||||
target: (identifier) @ignore
|
||||
(arguments (alias) @name)
|
||||
(#any-of? @ignore "defmodule" "defprotocol")) @definition.module
|
||||
|
||||
; * functions/macros
|
||||
(call
|
||||
target: (identifier) @ignore
|
||||
(arguments
|
||||
[
|
||||
; zero-arity functions with no parentheses
|
||||
(identifier) @name
|
||||
; regular function clause
|
||||
(call target: (identifier) @name)
|
||||
; function clause with a guard clause
|
||||
(binary_operator
|
||||
left: (call target: (identifier) @name)
|
||||
operator: "when")
|
||||
])
|
||||
(#any-of? @ignore "def" "defp" "defdelegate" "defguard" "defguardp" "defmacro" "defmacrop" "defn" "defnp")) @definition.function
|
||||
|
||||
; References
|
||||
|
||||
; ignore calls to kernel/special-forms keywords
|
||||
(call
|
||||
target: (identifier) @ignore
|
||||
(#any-of? @ignore "def" "defp" "defdelegate" "defguard" "defguardp" "defmacro" "defmacrop" "defn" "defnp" "defmodule" "defprotocol" "defimpl" "defstruct" "defexception" "defoverridable" "alias" "case" "cond" "else" "for" "if" "import" "quote" "raise" "receive" "require" "reraise" "super" "throw" "try" "unless" "unquote" "unquote_splicing" "use" "with"))
|
||||
|
||||
; ignore module attributes
|
||||
(unary_operator
|
||||
operator: "@"
|
||||
operand: (call
|
||||
target: (identifier) @ignore))
|
||||
|
||||
; * function call
|
||||
(call
|
||||
target: [
|
||||
; local
|
||||
(identifier) @name
|
||||
; remote
|
||||
(dot
|
||||
right: (identifier) @name)
|
||||
]) @reference.call
|
||||
|
||||
; * pipe into function call
|
||||
(binary_operator
|
||||
operator: "|>"
|
||||
right: (identifier) @name) @reference.call
|
||||
|
||||
; * modules
|
||||
(alias) @name @reference.module
|
||||
@@ -0,0 +1,13 @@
|
||||
[
|
||||
(after_block)
|
||||
(anonymous_function)
|
||||
(catch_block)
|
||||
(do_block)
|
||||
(else_block)
|
||||
(rescue_block)
|
||||
(stab_clause)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"end"
|
||||
] @outdent
|
||||
@@ -0,0 +1,10 @@
|
||||
display_name: "Go"
|
||||
indent_unit: tab
|
||||
comment_prefix: "//"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,8 @@
|
||||
(comment) @comment
|
||||
|
||||
; Function definitions
|
||||
(function_declaration name: (identifier) @definition.func)
|
||||
(method_declaration name: (field_identifier) @function.func)
|
||||
|
||||
; Type declarations
|
||||
(type_spec name: (type_identifier) @definition.type)
|
||||
@@ -0,0 +1,25 @@
|
||||
[
|
||||
(import_declaration)
|
||||
(const_declaration)
|
||||
(parameter_list)
|
||||
(type_declaration)
|
||||
(type_spec)
|
||||
(func_literal)
|
||||
(literal_value)
|
||||
(literal_element)
|
||||
(keyed_element)
|
||||
(expression_case)
|
||||
(default_case)
|
||||
(type_case)
|
||||
(communication_case)
|
||||
(argument_list)
|
||||
(field_declaration_list)
|
||||
(block)
|
||||
(var_declaration)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"]"
|
||||
")"
|
||||
"}"
|
||||
] @outdent
|
||||
@@ -0,0 +1,11 @@
|
||||
display_name: "HCL"
|
||||
indent_unit:
|
||||
space: 2
|
||||
comment_prefix: "//"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,16 @@
|
||||
[
|
||||
(block)
|
||||
(object)
|
||||
(tuple)
|
||||
(function_call)
|
||||
] @indent.begin
|
||||
|
||||
[
|
||||
"]"
|
||||
")"
|
||||
"}"
|
||||
] @indent.branch @indent.end
|
||||
|
||||
(comment) @indent.auto
|
||||
|
||||
(ERROR) @indent.auto
|
||||
@@ -0,0 +1,4 @@
|
||||
display_name: "HTML"
|
||||
indent_unit:
|
||||
space: 4
|
||||
brackets: []
|
||||
@@ -0,0 +1,11 @@
|
||||
display_name: "Java"
|
||||
indent_unit:
|
||||
space: 4
|
||||
comment_prefix: "//"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,7 @@
|
||||
(line_comment) @comment
|
||||
|
||||
; Methods
|
||||
(method_declaration name: (identifier) @definition)
|
||||
|
||||
; Class declarations
|
||||
(class_declaration name: (identifier) @definition.class)
|
||||
@@ -0,0 +1,21 @@
|
||||
[
|
||||
(class_body)
|
||||
(enum_body)
|
||||
(interface_body)
|
||||
(constructor_body)
|
||||
(annotation_type_body)
|
||||
(module_body)
|
||||
(block)
|
||||
(switch_block)
|
||||
(array_initializer)
|
||||
(argument_list)
|
||||
(formal_parameters)
|
||||
(annotation_argument_list)
|
||||
(element_value_array_initializer)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"}"
|
||||
")"
|
||||
"]"
|
||||
] @outdent
|
||||
@@ -0,0 +1,11 @@
|
||||
display_name: "JavaScript"
|
||||
indent_unit:
|
||||
space: 4
|
||||
comment_prefix: "//"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,10 @@
|
||||
(comment) @comment
|
||||
|
||||
; Function and method definitions
|
||||
(function_expression name: (identifier) @definition.function)
|
||||
(function_declaration name: (identifier) @definition.function)
|
||||
(method_definition name: (property_identifier) @definition)
|
||||
|
||||
; Class declarations
|
||||
(class name: (_) @definition.class)
|
||||
(class_declaration name: (_) @definition.class)
|
||||
@@ -0,0 +1,44 @@
|
||||
[
|
||||
(array)
|
||||
(object)
|
||||
(arguments)
|
||||
(formal_parameters)
|
||||
|
||||
(statement_block)
|
||||
(switch_statement)
|
||||
(switch_case)
|
||||
(switch_default)
|
||||
(object_pattern)
|
||||
(class_body)
|
||||
(named_imports)
|
||||
|
||||
(binary_expression)
|
||||
(return_statement)
|
||||
(template_substitution)
|
||||
(export_clause)
|
||||
|
||||
(call_expression)
|
||||
(assignment_expression)
|
||||
(member_expression)
|
||||
(lexical_declaration)
|
||||
(variable_declaration)
|
||||
(assignment_expression)
|
||||
|
||||
(if_statement)
|
||||
(for_statement)
|
||||
(for_in_statement)
|
||||
(while_statement)
|
||||
(do_statement)
|
||||
(try_statement)
|
||||
(with_statement)
|
||||
(throw_statement)
|
||||
|
||||
(export_statement)
|
||||
(import_statement)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"}"
|
||||
"]"
|
||||
")"
|
||||
] @outdent
|
||||
@@ -0,0 +1,10 @@
|
||||
display_name: "JSON"
|
||||
indent_unit:
|
||||
space: 4
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,9 @@
|
||||
[
|
||||
(object)
|
||||
(array)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"]"
|
||||
"}"
|
||||
] @outdent
|
||||
@@ -0,0 +1,14 @@
|
||||
display_name: "JSX"
|
||||
indent_unit:
|
||||
space: 2
|
||||
comment_prefix: "//"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
- start: "<"
|
||||
end: ">"
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
(comment) @comment
|
||||
|
||||
; Function and method definitions
|
||||
(function_expression name: (identifier) @definition.function)
|
||||
(function_declaration name: (identifier) @definition.function)
|
||||
(method_definition name: (property_identifier) @definition)
|
||||
|
||||
; Class declarations
|
||||
(class name: (_) @definition.class)
|
||||
(class_declaration name: (_) @definition.class)
|
||||
|
||||
; JSX component definitions
|
||||
(jsx_element
|
||||
open_tag: (jsx_opening_element
|
||||
name: (identifier) @definition.component))
|
||||
(jsx_self_closing_element
|
||||
name: (identifier) @definition.component)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
[
|
||||
(array)
|
||||
(object)
|
||||
(arguments)
|
||||
(formal_parameters)
|
||||
|
||||
(statement_block)
|
||||
(switch_statement)
|
||||
(switch_case)
|
||||
(switch_default)
|
||||
(object_pattern)
|
||||
(class_body)
|
||||
(named_imports)
|
||||
|
||||
(binary_expression)
|
||||
(return_statement)
|
||||
(template_substitution)
|
||||
(export_clause)
|
||||
|
||||
(call_expression)
|
||||
(assignment_expression)
|
||||
(member_expression)
|
||||
(lexical_declaration)
|
||||
(variable_declaration)
|
||||
(assignment_expression)
|
||||
|
||||
(if_statement)
|
||||
(for_statement)
|
||||
(for_in_statement)
|
||||
(while_statement)
|
||||
(do_statement)
|
||||
(try_statement)
|
||||
(with_statement)
|
||||
(throw_statement)
|
||||
|
||||
(export_statement)
|
||||
(import_statement)
|
||||
|
||||
] @indent
|
||||
|
||||
[
|
||||
"}"
|
||||
"]"
|
||||
")"
|
||||
] @outdent
|
||||
@@ -0,0 +1,13 @@
|
||||
display_name: "Kotlin"
|
||||
indent_unit:
|
||||
space: 4
|
||||
comment_prefix: "//"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
- start: "<"
|
||||
end: ">"
|
||||
@@ -0,0 +1,11 @@
|
||||
display_name: "Lua"
|
||||
indent_unit:
|
||||
space: 2
|
||||
comment_prefix: "--"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,47 @@
|
||||
[
|
||||
(function_definition)
|
||||
(function_declaration)
|
||||
(field)
|
||||
(do_statement)
|
||||
(method_index_expression)
|
||||
(while_statement)
|
||||
(repeat_statement)
|
||||
(if_statement)
|
||||
"then"
|
||||
(for_statement)
|
||||
(return_statement)
|
||||
(table_constructor)
|
||||
(arguments)
|
||||
] @indent.begin
|
||||
|
||||
[
|
||||
"end"
|
||||
"}"
|
||||
"]]"
|
||||
] @indent.end
|
||||
|
||||
(")" @indent.end
|
||||
(#not-has-parent? @indent.end parameters))
|
||||
|
||||
(return_statement
|
||||
(expression_list
|
||||
(function_call))) @indent.dedent
|
||||
|
||||
[
|
||||
"end"
|
||||
"then"
|
||||
"until"
|
||||
"}"
|
||||
")"
|
||||
"elseif"
|
||||
(elseif_statement)
|
||||
"else"
|
||||
(else_statement)
|
||||
] @indent.branch
|
||||
|
||||
(comment) @indent.auto
|
||||
|
||||
(string) @indent.auto
|
||||
|
||||
(ERROR
|
||||
"function") @indent.begin
|
||||
@@ -0,0 +1,11 @@
|
||||
display_name: "Objective-C"
|
||||
indent_unit:
|
||||
space: 4
|
||||
comment_prefix: "//"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,21 @@
|
||||
(comment) @comment
|
||||
|
||||
; Function declarations
|
||||
(function_declarator declarator: (identifier) @definition)
|
||||
|
||||
; Class declarations
|
||||
(struct_specifier name: (type_identifier) @definition.class body:(_))
|
||||
(declaration type: (union_specifier name: (type_identifier) @definition.class))
|
||||
|
||||
; Type declarations
|
||||
(type_definition declarator: (type_identifier) @definition.type)
|
||||
(enum_specifier name: (type_identifier) @definition.type)
|
||||
|
||||
; ObjC Classes/Interfaces
|
||||
; (class_interface name: (type_identifier) @definition.class)
|
||||
; (category_interface name: (type_identifier) @definition.class)
|
||||
; (protocol_declaration name: (protocol_name) @definition.interface)
|
||||
|
||||
; ObjC Methods
|
||||
; (method_declaration) @definition.method
|
||||
; (method_definition) @definition.method
|
||||
@@ -0,0 +1,35 @@
|
||||
[
|
||||
(compound_statement)
|
||||
(declaration_list)
|
||||
(field_declaration_list)
|
||||
(enumerator_list)
|
||||
(parameter_list)
|
||||
(init_declarator)
|
||||
(expression_statement)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"case"
|
||||
"}"
|
||||
"]"
|
||||
")"
|
||||
; "@end"
|
||||
] @outdent
|
||||
|
||||
(if_statement
|
||||
consequence: (_) @indent
|
||||
(#not-kind-eq? @indent "compound_statement")
|
||||
(#set! "scope" "all"))
|
||||
(while_statement
|
||||
body: (_) @indent
|
||||
(#not-kind-eq? @indent "compound_statement")
|
||||
(#set! "scope" "all"))
|
||||
(do_statement
|
||||
body: (_) @indent
|
||||
(#not-kind-eq? @indent "compound_statement")
|
||||
(#set! "scope" "all"))
|
||||
(for_statement
|
||||
")"
|
||||
(_) @indent
|
||||
(#not-kind-eq? @indent "compound_statement")
|
||||
(#set! "scope" "all"))
|
||||
@@ -0,0 +1,13 @@
|
||||
display_name: "PHP"
|
||||
indent_unit:
|
||||
space: 2
|
||||
comment_prefix: "//"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
- start: "<"
|
||||
end: ">"
|
||||
@@ -0,0 +1,68 @@
|
||||
[
|
||||
(array_creation_expression)
|
||||
(parenthesized_expression)
|
||||
(compound_statement)
|
||||
(declaration_list)
|
||||
(member_call_expression)
|
||||
(binary_expression)
|
||||
(return_statement)
|
||||
(arguments)
|
||||
(formal_parameters)
|
||||
(enum_declaration_list)
|
||||
(switch_block)
|
||||
(match_block)
|
||||
(case_statement)
|
||||
(default_statement)
|
||||
(property_hook_list)
|
||||
] @indent.begin
|
||||
|
||||
(return_statement
|
||||
[
|
||||
(object_creation_expression)
|
||||
(anonymous_function)
|
||||
(arrow_function)
|
||||
(match_expression)
|
||||
]) @indent.dedent
|
||||
|
||||
[
|
||||
")"
|
||||
"}"
|
||||
"]"
|
||||
] @indent.branch
|
||||
|
||||
(comment) @indent.auto
|
||||
|
||||
(arguments
|
||||
")" @indent.end)
|
||||
|
||||
(formal_parameters
|
||||
")" @indent.end)
|
||||
|
||||
(compound_statement
|
||||
"}" @indent.end)
|
||||
|
||||
(declaration_list
|
||||
"}" @indent.end)
|
||||
|
||||
(enum_declaration_list
|
||||
"}" @indent.end)
|
||||
|
||||
(return_statement
|
||||
";" @indent.end)
|
||||
|
||||
(property_hook_list
|
||||
"}" @indent.end)
|
||||
|
||||
(ERROR
|
||||
"(" @indent.align
|
||||
.
|
||||
(_)
|
||||
(#set! indent.open_delimiter "(")
|
||||
(#set! indent.close_delimiter ")"))
|
||||
|
||||
(ERROR
|
||||
"[" @indent.align
|
||||
.
|
||||
(_)
|
||||
(#set! indent.open_delimiter "[")
|
||||
(#set! indent.close_delimiter "]"))
|
||||
@@ -0,0 +1,11 @@
|
||||
display_name: "PowerShell"
|
||||
indent_unit:
|
||||
space: 4
|
||||
comment_prefix: "#"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,12 @@
|
||||
# source: https://peps.python.org/pep-0008/#indentation
|
||||
display_name: "Python"
|
||||
indent_unit:
|
||||
space: 4
|
||||
comment_prefix: "#"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,7 @@
|
||||
(comment) @comment
|
||||
|
||||
; Function definitions
|
||||
(function_definition name: (identifier) @definition.def)
|
||||
|
||||
; Class declarations
|
||||
(class_definition name: (identifier) @definition.class)
|
||||
@@ -0,0 +1,36 @@
|
||||
[
|
||||
(list)
|
||||
(tuple)
|
||||
(dictionary)
|
||||
(set)
|
||||
|
||||
(if_statement)
|
||||
(for_statement)
|
||||
(while_statement)
|
||||
(with_statement)
|
||||
(try_statement)
|
||||
(match_statement)
|
||||
(case_clause)
|
||||
(import_from_statement)
|
||||
|
||||
(parenthesized_expression)
|
||||
(generator_expression)
|
||||
(list_comprehension)
|
||||
(set_comprehension)
|
||||
(dictionary_comprehension)
|
||||
|
||||
(tuple_pattern)
|
||||
(list_pattern)
|
||||
(argument_list)
|
||||
(parameters)
|
||||
(binary_operator)
|
||||
|
||||
(function_definition)
|
||||
(class_definition)
|
||||
] @indent
|
||||
|
||||
[
|
||||
")"
|
||||
"]"
|
||||
"}"
|
||||
] @outdent
|
||||
@@ -0,0 +1,11 @@
|
||||
display_name: "Ruby"
|
||||
indent_unit:
|
||||
space: 4
|
||||
comment_prefix: "#"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,43 @@
|
||||
[
|
||||
(class)
|
||||
(singleton_class)
|
||||
(method)
|
||||
(singleton_method)
|
||||
(module)
|
||||
(call)
|
||||
(if)
|
||||
(block)
|
||||
(do_block)
|
||||
(hash)
|
||||
(array)
|
||||
(argument_list)
|
||||
(case)
|
||||
(while)
|
||||
(until)
|
||||
(for)
|
||||
(begin)
|
||||
(unless)
|
||||
(assignment)
|
||||
(parenthesized_statements)
|
||||
] @indent.begin
|
||||
|
||||
[
|
||||
"end"
|
||||
")"
|
||||
"}"
|
||||
"]"
|
||||
] @indent.end
|
||||
|
||||
[
|
||||
"end"
|
||||
")"
|
||||
"}"
|
||||
"]"
|
||||
(when)
|
||||
(elsif)
|
||||
(else)
|
||||
(rescue)
|
||||
(ensure)
|
||||
] @indent.branch
|
||||
|
||||
(comment) @indent.ignore
|
||||
@@ -0,0 +1,93 @@
|
||||
; The MIT License (MIT)
|
||||
;
|
||||
; Copyright (c) 2016 Rob Rix
|
||||
;
|
||||
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
; of this software and associated documentation files (the "Software"), to deal
|
||||
; in the Software without restriction, including without limitation the rights
|
||||
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
; copies of the Software, and to permit persons to whom the Software is
|
||||
; furnished to do so, subject to the following conditions:
|
||||
;
|
||||
; The above copyright notice and this permission notice shall be included in all
|
||||
; copies or substantial portions of the Software.
|
||||
;
|
||||
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
; SOFTWARE.
|
||||
; DECLARATIONS AND SCOPES
|
||||
(method) @local.scope
|
||||
|
||||
(class) @local.scope
|
||||
|
||||
[
|
||||
(block)
|
||||
(do_block)
|
||||
] @local.scope
|
||||
|
||||
(identifier) @local.reference
|
||||
|
||||
(constant) @local.reference
|
||||
|
||||
(instance_variable) @local.reference
|
||||
|
||||
(module
|
||||
name: (constant) @local.definition.namespace)
|
||||
|
||||
(class
|
||||
name: (constant) @local.definition.type)
|
||||
|
||||
(method
|
||||
name: [
|
||||
(identifier)
|
||||
(constant)
|
||||
] @local.definition.function)
|
||||
|
||||
(singleton_method
|
||||
name: [
|
||||
(identifier)
|
||||
(constant)
|
||||
] @local.definition.function)
|
||||
|
||||
(method_parameters
|
||||
(identifier) @local.definition.var)
|
||||
|
||||
(lambda_parameters
|
||||
(identifier) @local.definition.var)
|
||||
|
||||
(block_parameters
|
||||
(identifier) @local.definition.var)
|
||||
|
||||
(splat_parameter
|
||||
(identifier) @local.definition.var)
|
||||
|
||||
(hash_splat_parameter
|
||||
(identifier) @local.definition.var)
|
||||
|
||||
(optional_parameter
|
||||
name: (identifier) @local.definition.var)
|
||||
|
||||
(destructured_parameter
|
||||
(identifier) @local.definition.var)
|
||||
|
||||
(block_parameter
|
||||
name: (identifier) @local.definition.var)
|
||||
|
||||
(keyword_parameter
|
||||
name: (identifier) @local.definition.var)
|
||||
|
||||
(assignment
|
||||
left: (_) @local.definition.var)
|
||||
|
||||
(left_assignment_list
|
||||
(identifier) @local.definition.var)
|
||||
|
||||
(rest_assignment
|
||||
(identifier) @local.definition.var)
|
||||
|
||||
(destructured_left_assignment
|
||||
(identifier) @local.definition.var)
|
||||
@@ -0,0 +1,11 @@
|
||||
display_name: "Rust"
|
||||
indent_unit:
|
||||
space: 4
|
||||
comment_prefix: "//"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,19 @@
|
||||
(line_comment) @comment
|
||||
(line_outer_doc_comment) @comment
|
||||
(block_outer_doc_comment) @comment
|
||||
|
||||
; Function definitions
|
||||
(function_item (identifier) @definition.fn)
|
||||
(function_signature_item (identifier) @definition.fn)
|
||||
|
||||
; Struct declarations
|
||||
(struct_item name: (type_identifier) @definition.struct)
|
||||
|
||||
; Enum declarations
|
||||
(enum_item name: (type_identifier) @definition.enum)
|
||||
|
||||
; Trait declarations
|
||||
(trait_item name: (type_identifier) @definition.trait)
|
||||
|
||||
; Type alias declarations
|
||||
(type_item name: (type_identifier) @definition.type)
|
||||
@@ -0,0 +1,33 @@
|
||||
[
|
||||
(use_list)
|
||||
(block)
|
||||
(match_block)
|
||||
(arguments)
|
||||
(parameters)
|
||||
(declaration_list)
|
||||
(field_declaration_list)
|
||||
(field_initializer_list)
|
||||
(struct_pattern)
|
||||
(tuple_pattern)
|
||||
(unit_expression)
|
||||
(enum_variant_list)
|
||||
(call_expression)
|
||||
(binary_expression)
|
||||
(field_expression)
|
||||
(await_expression)
|
||||
(tuple_expression)
|
||||
(array_expression)
|
||||
(where_clause)
|
||||
(type_cast_expression)
|
||||
|
||||
(token_tree)
|
||||
(macro_definition)
|
||||
(token_tree_pattern)
|
||||
(token_repetition)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"}"
|
||||
"]"
|
||||
")"
|
||||
] @outdent
|
||||
@@ -0,0 +1,17 @@
|
||||
display_name: "Scala"
|
||||
indent_unit:
|
||||
space: 2
|
||||
comment_prefix: "//"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
- start: "\""
|
||||
end: "\""
|
||||
- start: "'"
|
||||
end: "'"
|
||||
- start: "`"
|
||||
end: "`"
|
||||
@@ -0,0 +1,32 @@
|
||||
(comment) @comment
|
||||
(block_comment) @comment
|
||||
|
||||
; Class declarations
|
||||
(class_definition name: (identifier) @definition.class)
|
||||
|
||||
; Object declarations
|
||||
(object_definition name: (identifier) @definition.class)
|
||||
|
||||
; Trait declarations
|
||||
(trait_definition name: (identifier) @definition.class)
|
||||
|
||||
; Enum declarations
|
||||
(enum_definition name: (identifier) @definition.class)
|
||||
|
||||
; Function/method declarations
|
||||
(function_declaration name: (identifier) @definition)
|
||||
(function_definition name: (identifier) @definition)
|
||||
|
||||
; Variable definitions
|
||||
(val_definition pattern: (identifier) @definition)
|
||||
(var_definition pattern: (identifier) @definition)
|
||||
(val_declaration name: (identifier) @definition)
|
||||
(var_declaration name: (identifier) @definition)
|
||||
|
||||
; Parameters
|
||||
(parameter name: (identifier) @definition)
|
||||
(binding name: (identifier) @definition)
|
||||
(class_parameter name: (identifier) @definition)
|
||||
|
||||
; Type definitions
|
||||
(type_definition name: (type_identifier) @definition.type)
|
||||
@@ -0,0 +1,30 @@
|
||||
; These indent queries adhere to nvim-tree-sytter syntax.
|
||||
; See `nvim-tree-sitter-indentation-mod` vim help page.
|
||||
|
||||
[
|
||||
(template_body)
|
||||
(block)
|
||||
(parameters)
|
||||
(arguments)
|
||||
(match_expression)
|
||||
(splice_expression)
|
||||
(import_declaration)
|
||||
(function_definition)
|
||||
(ERROR ":")
|
||||
(ERROR "=")
|
||||
("match")
|
||||
(":")
|
||||
("=")
|
||||
] @indent.begin
|
||||
|
||||
(arguments ")" @indent.end)
|
||||
|
||||
"}" @indent.end
|
||||
|
||||
"end" @indent.end
|
||||
|
||||
[
|
||||
")"
|
||||
"]"
|
||||
"}"
|
||||
] @indent.branch
|
||||
@@ -0,0 +1,11 @@
|
||||
display_name: "Shell"
|
||||
indent_unit:
|
||||
space: 4
|
||||
comment_prefix: "#"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,3 @@
|
||||
(comment) @comment
|
||||
|
||||
(function_definition name: (word) @definition.function)
|
||||
@@ -0,0 +1,12 @@
|
||||
[
|
||||
(function_definition)
|
||||
(if_statement)
|
||||
(for_statement)
|
||||
(while_statement)
|
||||
(case_statement)
|
||||
(pipeline)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"}"
|
||||
] @outdent
|
||||
@@ -0,0 +1,11 @@
|
||||
display_name: "SQL"
|
||||
indent_unit:
|
||||
space: 2
|
||||
comment_prefix: "--"
|
||||
brackets:
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
- start: "{"
|
||||
end: "}"
|
||||
@@ -0,0 +1,27 @@
|
||||
[
|
||||
(select)
|
||||
(cte)
|
||||
(column_definitions)
|
||||
(case)
|
||||
(subquery)
|
||||
(insert)
|
||||
] @indent.begin
|
||||
|
||||
|
||||
(block
|
||||
(keyword_begin)
|
||||
) @indent.begin
|
||||
|
||||
(column_definitions ")" @indent.branch)
|
||||
|
||||
(subquery ")" @indent.branch)
|
||||
|
||||
(cte ")" @indent.branch)
|
||||
|
||||
[
|
||||
(keyword_end)
|
||||
(keyword_values)
|
||||
(keyword_into)
|
||||
] @indent.branch
|
||||
|
||||
(keyword_end) @indent.end
|
||||
@@ -0,0 +1,13 @@
|
||||
# Starlark configuration for Warp
|
||||
# Starlark is used by Bazel and has Python-like syntax
|
||||
display_name: "Bazel (Starlark)"
|
||||
indent_unit:
|
||||
space: 4
|
||||
comment_prefix: "#"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,9 @@
|
||||
; Starlark symbol identification
|
||||
(comment) @comment
|
||||
|
||||
; Function definitions
|
||||
(function_definition name: (identifier) @definition.def)
|
||||
|
||||
; Variables assigned at module level (like rules, constants)
|
||||
(assignment
|
||||
left: (identifier) @definition.var)
|
||||
@@ -0,0 +1,24 @@
|
||||
; Starlark indentation rules
|
||||
[
|
||||
(list)
|
||||
(dictionary)
|
||||
|
||||
(if_statement)
|
||||
(for_statement)
|
||||
|
||||
(parenthesized_expression)
|
||||
(list_comprehension)
|
||||
(dictionary_comprehension)
|
||||
|
||||
(argument_list)
|
||||
(parameters)
|
||||
(binary_operator)
|
||||
|
||||
(function_definition)
|
||||
] @indent
|
||||
|
||||
[
|
||||
")"
|
||||
"]"
|
||||
"}"
|
||||
] @outdent
|
||||
@@ -0,0 +1,11 @@
|
||||
display_name: "Swift"
|
||||
indent_unit:
|
||||
space: 4
|
||||
comment_prefix: "//"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,122 @@
|
||||
; format-ignore
|
||||
[
|
||||
; ... refers to the section that will get affected by this indent.begin capture
|
||||
(protocol_body) ; protocol Foo { ... }
|
||||
(class_body) ; class Foo { ... }
|
||||
(enum_class_body) ; enum Foo { ... }
|
||||
(function_declaration) ; func Foo (...) {...}
|
||||
(init_declaration) ; init(...) {...}
|
||||
(deinit_declaration) ; deinit {...}
|
||||
(computed_property) ; { ... }
|
||||
(subscript_declaration) ; subscript Foo(...) { ... }
|
||||
|
||||
(computed_getter) ; get { ... }
|
||||
(computed_setter) ; set { ... }
|
||||
|
||||
(assignment) ; a = b
|
||||
|
||||
(control_transfer_statement) ; return ...
|
||||
(for_statement)
|
||||
(while_statement)
|
||||
(repeat_while_statement)
|
||||
(do_statement)
|
||||
(if_statement)
|
||||
(switch_statement)
|
||||
(guard_statement)
|
||||
|
||||
(type_parameters) ; x<Foo>
|
||||
(tuple_type) ; (...)
|
||||
(array_type) ; [String]
|
||||
(dictionary_type) ; [Foo: Bar]
|
||||
|
||||
(call_expression) ; callFunc(...)
|
||||
(tuple_expression) ; ( foo + bar )
|
||||
(array_literal) ; [ foo, bar ]
|
||||
(dictionary_literal) ; [ foo: bar, x: y ]
|
||||
(lambda_literal)
|
||||
(willset_didset_block)
|
||||
(willset_clause)
|
||||
(didset_clause)
|
||||
] @indent.begin
|
||||
|
||||
(init_declaration) @indent.begin
|
||||
|
||||
(init_declaration
|
||||
[
|
||||
"init"
|
||||
"("
|
||||
] @indent.branch)
|
||||
|
||||
; indentation for init parameters
|
||||
(init_declaration
|
||||
")" @indent.branch @indent.end)
|
||||
|
||||
(init_declaration
|
||||
(parameter) @indent.begin
|
||||
(#set! indent.immediate))
|
||||
|
||||
; @something(...)
|
||||
(modifiers
|
||||
(attribute) @indent.begin)
|
||||
|
||||
(function_declaration
|
||||
(modifiers
|
||||
.
|
||||
(attribute)
|
||||
(_)* @indent.branch)
|
||||
.
|
||||
_ @indent.branch
|
||||
(#not-kind-eq? @indent.branch "type_parameters" "parameter"))
|
||||
|
||||
(ERROR
|
||||
[
|
||||
"<"
|
||||
"{"
|
||||
"("
|
||||
"["
|
||||
]) @indent.begin
|
||||
|
||||
; if-elseif
|
||||
(if_statement
|
||||
(if_statement) @indent.dedent)
|
||||
|
||||
; case Foo:
|
||||
; default Foo:
|
||||
; @attribute default Foo:
|
||||
(switch_entry
|
||||
.
|
||||
_ @indent.branch)
|
||||
|
||||
(function_declaration
|
||||
")" @indent.branch)
|
||||
|
||||
(type_parameters
|
||||
">" @indent.branch @indent.end .)
|
||||
|
||||
(tuple_expression
|
||||
")" @indent.branch @indent.end)
|
||||
|
||||
(value_arguments
|
||||
")" @indent.branch @indent.end)
|
||||
|
||||
(tuple_type
|
||||
")" @indent.branch @indent.end)
|
||||
|
||||
(modifiers
|
||||
(attribute
|
||||
")" @indent.branch @indent.end))
|
||||
|
||||
[
|
||||
"}"
|
||||
"]"
|
||||
] @indent.branch @indent.end
|
||||
|
||||
[
|
||||
; (ERROR)
|
||||
(comment)
|
||||
(multiline_comment)
|
||||
(raw_str_part)
|
||||
(multi_line_string_literal)
|
||||
] @indent.auto
|
||||
|
||||
(directive) @indent.ignore
|
||||
@@ -0,0 +1,4 @@
|
||||
display_name: "TOML"
|
||||
indent_unit:
|
||||
space: 2
|
||||
comment_prefix: "#"
|
||||
@@ -0,0 +1,11 @@
|
||||
[
|
||||
(array)
|
||||
(inline_table)
|
||||
] @indent.begin
|
||||
|
||||
[
|
||||
"["
|
||||
"]"
|
||||
"{"
|
||||
"}"
|
||||
] @indent.branch
|
||||
@@ -0,0 +1,14 @@
|
||||
display_name: "TSX"
|
||||
indent_unit:
|
||||
space: 2
|
||||
comment_prefix: "//"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
- start: "<"
|
||||
end: ">"
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
(comment) @comment
|
||||
|
||||
; Function and method definitions
|
||||
(function_expression name: (identifier) @definition.function)
|
||||
(function_declaration name: (identifier) @definition.function)
|
||||
(method_definition name: (property_identifier) @definition)
|
||||
|
||||
; Class declarations
|
||||
(class name: (_) @definition.class)
|
||||
(class_declaration name: (_) @definition.class)
|
||||
|
||||
; TypeScript specific definitions
|
||||
(interface_declaration name: (type_identifier) @definition.interface)
|
||||
(type_alias_declaration name: (type_identifier) @definition.type)
|
||||
(enum_declaration name: (identifier) @definition.enum)
|
||||
|
||||
; JSX component definitions
|
||||
(jsx_element
|
||||
open_tag: (jsx_opening_element
|
||||
name: (identifier) @definition.component))
|
||||
(jsx_self_closing_element
|
||||
name: (identifier) @definition.component)
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
[
|
||||
(array)
|
||||
(object)
|
||||
(arguments)
|
||||
(formal_parameters)
|
||||
|
||||
(statement_block)
|
||||
(switch_statement)
|
||||
(switch_case)
|
||||
(switch_default)
|
||||
(object_pattern)
|
||||
(class_body)
|
||||
(named_imports)
|
||||
|
||||
(binary_expression)
|
||||
(return_statement)
|
||||
(template_substitution)
|
||||
(export_clause)
|
||||
|
||||
(enum_declaration)
|
||||
(interface_declaration)
|
||||
(object_type)
|
||||
|
||||
(call_expression)
|
||||
(assignment_expression)
|
||||
(member_expression)
|
||||
(lexical_declaration)
|
||||
(variable_declaration)
|
||||
(assignment_expression)
|
||||
|
||||
(if_statement)
|
||||
(for_statement)
|
||||
(for_in_statement)
|
||||
(while_statement)
|
||||
(do_statement)
|
||||
(try_statement)
|
||||
(with_statement)
|
||||
(throw_statement)
|
||||
|
||||
(export_statement)
|
||||
(import_statement)
|
||||
] @indent
|
||||
|
||||
|
||||
[
|
||||
"}"
|
||||
"]"
|
||||
")"
|
||||
] @outdent
|
||||
@@ -0,0 +1,11 @@
|
||||
display_name: "TypeScript"
|
||||
indent_unit:
|
||||
space: 4
|
||||
comment_prefix: "//"
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "["
|
||||
end: "]"
|
||||
@@ -0,0 +1,10 @@
|
||||
(comment) @comment
|
||||
|
||||
; Function and method definitions
|
||||
(function_expression name: (identifier) @definition.function)
|
||||
(function_declaration name: (identifier) @definition.function)
|
||||
(method_definition name: (property_identifier) @definition)
|
||||
|
||||
; Class declarations
|
||||
(class name: (_) @definition.class)
|
||||
(class_declaration name: (_) @definition.class)
|
||||
@@ -0,0 +1,49 @@
|
||||
[
|
||||
(array)
|
||||
(object)
|
||||
(arguments)
|
||||
(formal_parameters)
|
||||
|
||||
(statement_block)
|
||||
(switch_statement)
|
||||
(switch_case)
|
||||
(switch_default)
|
||||
(object_pattern)
|
||||
(class_body)
|
||||
(named_imports)
|
||||
|
||||
(binary_expression)
|
||||
(return_statement)
|
||||
(template_substitution)
|
||||
(export_clause)
|
||||
|
||||
(enum_declaration)
|
||||
(interface_declaration)
|
||||
(object_type)
|
||||
|
||||
(call_expression)
|
||||
(assignment_expression)
|
||||
(member_expression)
|
||||
(lexical_declaration)
|
||||
(variable_declaration)
|
||||
(assignment_expression)
|
||||
|
||||
(if_statement)
|
||||
(for_statement)
|
||||
(for_in_statement)
|
||||
(while_statement)
|
||||
(do_statement)
|
||||
(try_statement)
|
||||
(with_statement)
|
||||
(throw_statement)
|
||||
|
||||
(export_statement)
|
||||
(import_statement)
|
||||
] @indent
|
||||
|
||||
|
||||
[
|
||||
"}"
|
||||
"]"
|
||||
")"
|
||||
] @outdent
|
||||
@@ -0,0 +1,12 @@
|
||||
display_name: "Vue"
|
||||
indent_unit:
|
||||
space: 2
|
||||
brackets:
|
||||
- start: "{"
|
||||
end: "}"
|
||||
- start: "["
|
||||
end: "]"
|
||||
- start: "("
|
||||
end: ")"
|
||||
- start: "<"
|
||||
end: ">"
|
||||
@@ -0,0 +1,7 @@
|
||||
display_name: "XML"
|
||||
indent_unit:
|
||||
space: 2
|
||||
comment_prefix: "<!--"
|
||||
brackets:
|
||||
- start: "<"
|
||||
end: ">"
|
||||
@@ -0,0 +1,4 @@
|
||||
display_name: "YAML"
|
||||
indent_unit:
|
||||
space: 2
|
||||
comment_prefix: "#"
|
||||
@@ -0,0 +1,13 @@
|
||||
[
|
||||
(block_scalar)
|
||||
((block_sequence_item) @item @indent (#not-one-line? @item))
|
||||
(block_mapping_pair
|
||||
key: (_) @key
|
||||
!value
|
||||
)
|
||||
(block_mapping_pair
|
||||
key: (_) @key
|
||||
value: (_) @val
|
||||
(#not-same-line? @key @val)
|
||||
)
|
||||
] @indent
|
||||
@@ -0,0 +1,346 @@
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::HashMap,
|
||||
path::Path,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use arborium::tree_sitter::{Language as ParserGrammar, Query};
|
||||
use lazy_static::lazy_static;
|
||||
use rust_embed::RustEmbed;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use warp_editor::content::text::IndentUnit;
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "grammars"]
|
||||
struct Grammars;
|
||||
|
||||
lazy_static! {
|
||||
static ref LANGUAGE_REGISTRY: LanguageRegistry = LanguageRegistry::new();
|
||||
}
|
||||
|
||||
pub const SUPPORTED_LANGUAGES: [&str; 32] = [
|
||||
"rust",
|
||||
"golang",
|
||||
"yaml",
|
||||
"python",
|
||||
"javascript",
|
||||
"jsx",
|
||||
"typescript",
|
||||
"tsx",
|
||||
"java",
|
||||
"cpp",
|
||||
"shell",
|
||||
"csharp",
|
||||
"html",
|
||||
"css",
|
||||
"c",
|
||||
"json",
|
||||
"hcl",
|
||||
"lua",
|
||||
"ruby",
|
||||
"php",
|
||||
"toml",
|
||||
"swift",
|
||||
"kotlin",
|
||||
"scala",
|
||||
"powershell",
|
||||
"elixir",
|
||||
"sql",
|
||||
"starlark",
|
||||
"objective-c",
|
||||
"xml",
|
||||
"vue",
|
||||
"dockerfile",
|
||||
];
|
||||
|
||||
/// Registry that holds all of the supported languages.
|
||||
pub struct LanguageRegistry {
|
||||
/// List of languages we support mapped from their display name. They are hold in Arc so they could be shared
|
||||
/// between different editors.
|
||||
languages: Mutex<HashMap<String, Arc<Language>>>,
|
||||
}
|
||||
|
||||
impl LanguageRegistry {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
languages: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn language_by_name(&self, name: &str) -> Option<Arc<Language>> {
|
||||
if !SUPPORTED_LANGUAGES.contains(&name) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut languages = self.languages.lock().expect("Mutex should not be poisoned");
|
||||
|
||||
if let Some(lang) = languages.get(name) {
|
||||
return Some(lang.clone());
|
||||
}
|
||||
|
||||
let language = Arc::new(load_language(name)?);
|
||||
languages.insert(name.to_string(), language.clone());
|
||||
Some(language)
|
||||
}
|
||||
}
|
||||
|
||||
/// Normalizes common markdown language aliases to their internal names.
|
||||
/// For example, "go" -> "golang", "bash" -> "shell", etc.
|
||||
fn normalize_language_name(name: &str) -> &str {
|
||||
match name {
|
||||
"go" => "golang",
|
||||
"bash" | "sh" | "zsh" => "shell",
|
||||
"js" => "javascript",
|
||||
"ts" => "typescript",
|
||||
"py" => "python",
|
||||
"rb" => "ruby",
|
||||
"rs" => "rust",
|
||||
"cs" | "c#" => "csharp",
|
||||
"c++" => "cpp",
|
||||
"objc" | "objective_c" => "objective-c",
|
||||
"terraform" | "tf" => "hcl",
|
||||
"kt" => "kotlin",
|
||||
"docker" | "containerfile" => "dockerfile",
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn language_by_name(name: &str) -> Option<Arc<Language>> {
|
||||
let normalized = normalize_language_name(name);
|
||||
LANGUAGE_REGISTRY.language_by_name(normalized)
|
||||
}
|
||||
|
||||
/// Find the corresponding language entry by the filename.
|
||||
pub fn language_by_filename(path: &Path) -> Option<Arc<Language>> {
|
||||
// First check for specific filenames that don't use extensions.
|
||||
if let Some(filename) = path.file_name().and_then(|name| name.to_str()) {
|
||||
match filename {
|
||||
// Bash config files
|
||||
".bashrc" | ".bash_profile" => {
|
||||
return language_by_name("shell");
|
||||
}
|
||||
// ZSH config files
|
||||
".zshrc" | ".zsh_profile" | ".zprofile" => {
|
||||
return language_by_name("shell");
|
||||
}
|
||||
// Bazel build files
|
||||
"BUILD" | "WORKSPACE" => {
|
||||
return language_by_name("starlark");
|
||||
}
|
||||
// Dockerfiles
|
||||
"Dockerfile" | "Containerfile" | "dockerfile" | "containerfile" => {
|
||||
return language_by_name("dockerfile");
|
||||
}
|
||||
_ => {
|
||||
// Also match Dockerfile variants like Dockerfile.dev, Dockerfile.prod
|
||||
if filename.starts_with("Dockerfile.") || filename.starts_with("Containerfile.") {
|
||||
return language_by_name("dockerfile");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let extension = path.extension()?.to_str()?;
|
||||
match extension {
|
||||
"rs" => language_by_name("rust"),
|
||||
"go" => language_by_name("golang"),
|
||||
"yml" | "yaml" => language_by_name("yaml"),
|
||||
"py" | "py3" | "pyw" | "pyi" => language_by_name("python"),
|
||||
"js" | "cjs" | "mjs" => language_by_name("javascript"),
|
||||
"jsx" => language_by_name("jsx"),
|
||||
"tsx" => language_by_name("tsx"),
|
||||
"ts" | "cts" | "mts" => language_by_name("typescript"),
|
||||
"java" | "groovy" | "gvy" | "gy" | "gsh" => language_by_name("java"),
|
||||
"cpp" | "cxx" | "cc" | "h" | "hh" => language_by_name("cpp"),
|
||||
"sh" | "zsh" | "bash" => language_by_name("shell"),
|
||||
"cs" => language_by_name("csharp"),
|
||||
"html" => language_by_name("html"),
|
||||
"css" => language_by_name("css"),
|
||||
"c" => language_by_name("c"),
|
||||
"json" => language_by_name("json"),
|
||||
"tf" | "hcl" | "tfvars" => language_by_name("hcl"),
|
||||
"lua" => language_by_name("lua"),
|
||||
"rb" => language_by_name("ruby"),
|
||||
"php" | "phtml" => language_by_name("php"),
|
||||
"toml" => language_by_name("toml"),
|
||||
"swift" => language_by_name("swift"),
|
||||
"kt" | "kts" => language_by_name("kotlin"),
|
||||
"scala" | "sbt" | "sc" => language_by_name("scala"),
|
||||
"ps1" | "pwsh" => language_by_name("powershell"),
|
||||
"ex" | "exs" => language_by_name("elixir"),
|
||||
"sql" => language_by_name("sql"),
|
||||
"bzl" | "bazel" => language_by_name("starlark"),
|
||||
"m" | "mm" => language_by_name("objective-c"),
|
||||
"xml" => language_by_name("xml"),
|
||||
"vue" => language_by_name("vue"),
|
||||
"dockerfile" => language_by_name("dockerfile"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Captures the language-specific parser grammar and queries for syntax features like highlighting and
|
||||
/// bracket pairing. In the future, this will also be the entry point for LSP.
|
||||
pub struct Language {
|
||||
/// Tree-sitter parser grammar.
|
||||
pub grammar: ParserGrammar,
|
||||
/// Query for syntax highlighting.
|
||||
pub highlight_query: Query,
|
||||
/// Query for auto indent.
|
||||
pub indents_query: Option<Query>,
|
||||
/// Unit for each indent action.
|
||||
pub indent_unit: IndentUnit,
|
||||
/// Comment prefix.
|
||||
pub comment_prefix: Option<String>,
|
||||
/// Language-specific bracket pairs.
|
||||
pub bracket_pairs: Vec<(char, char)>,
|
||||
/// Query for parsing symbols.
|
||||
pub symbols_query: Option<Query>,
|
||||
/// Display name for the language.
|
||||
pub display_name: String,
|
||||
}
|
||||
|
||||
impl Language {
|
||||
/// Returns the display name of the language.
|
||||
pub fn display_name(&self) -> &str {
|
||||
&self.display_name
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct LanguageConfig {
|
||||
display_name: String,
|
||||
indent_unit: IndentUnit,
|
||||
comment_prefix: Option<String>,
|
||||
#[serde(default)]
|
||||
brackets: Vec<BracketPair>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct BracketPair {
|
||||
start: String,
|
||||
end: String,
|
||||
}
|
||||
|
||||
/// Map our internal language name to the canonical arborium language name.
|
||||
fn to_arborium_name(lang: &str) -> &str {
|
||||
match lang {
|
||||
"golang" => "go",
|
||||
"shell" => "bash",
|
||||
"csharp" => "c-sharp",
|
||||
"jsx" => "javascript",
|
||||
"objective-c" => "objc",
|
||||
"sql" => "sql",
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the bundled highlight query from arborium for a given language.
|
||||
fn get_arborium_highlight_query(lang: &str) -> Option<&str> {
|
||||
match lang {
|
||||
"rust" => Some(arborium::lang_rust::HIGHLIGHTS_QUERY),
|
||||
"golang" => Some(arborium::lang_go::HIGHLIGHTS_QUERY),
|
||||
"yaml" => Some(arborium::lang_yaml::HIGHLIGHTS_QUERY),
|
||||
"python" => Some(arborium::lang_python::HIGHLIGHTS_QUERY),
|
||||
"javascript" => Some(arborium::lang_javascript::HIGHLIGHTS_QUERY),
|
||||
"jsx" => Some(arborium::lang_javascript::HIGHLIGHTS_QUERY),
|
||||
"typescript" => Some(&arborium::lang_typescript::HIGHLIGHTS_QUERY),
|
||||
"tsx" => Some(&arborium::lang_tsx::HIGHLIGHTS_QUERY),
|
||||
"java" => Some(arborium::lang_java::HIGHLIGHTS_QUERY),
|
||||
"cpp" => Some(&arborium::lang_cpp::HIGHLIGHTS_QUERY),
|
||||
"shell" => Some(arborium::lang_bash::HIGHLIGHTS_QUERY),
|
||||
"csharp" => Some(arborium::lang_c_sharp::HIGHLIGHTS_QUERY),
|
||||
"html" => Some(arborium::lang_html::HIGHLIGHTS_QUERY),
|
||||
"css" => Some(arborium::lang_css::HIGHLIGHTS_QUERY),
|
||||
"c" => Some(arborium::lang_c::HIGHLIGHTS_QUERY),
|
||||
"json" => Some(arborium::lang_json::HIGHLIGHTS_QUERY),
|
||||
"hcl" => Some(arborium::lang_hcl::HIGHLIGHTS_QUERY),
|
||||
"lua" => Some(arborium::lang_lua::HIGHLIGHTS_QUERY),
|
||||
"ruby" => Some(arborium::lang_ruby::HIGHLIGHTS_QUERY),
|
||||
"php" => Some(arborium::lang_php::HIGHLIGHTS_QUERY),
|
||||
"toml" => Some(arborium::lang_toml::HIGHLIGHTS_QUERY),
|
||||
"swift" => Some(arborium::lang_swift::HIGHLIGHTS_QUERY),
|
||||
"kotlin" => Some(arborium::lang_kotlin::HIGHLIGHTS_QUERY),
|
||||
"scala" => Some(arborium::lang_scala::HIGHLIGHTS_QUERY),
|
||||
"powershell" => Some(arborium::lang_powershell::HIGHLIGHTS_QUERY),
|
||||
"elixir" => Some(arborium::lang_elixir::HIGHLIGHTS_QUERY),
|
||||
"sql" => Some(arborium::lang_sql::HIGHLIGHTS_QUERY),
|
||||
"starlark" => Some(arborium::lang_starlark::HIGHLIGHTS_QUERY),
|
||||
"objective-c" => Some(&arborium::lang_objc::HIGHLIGHTS_QUERY),
|
||||
"xml" => Some(arborium::lang_xml::HIGHLIGHTS_QUERY),
|
||||
"vue" => Some(&arborium::lang_vue::HIGHLIGHTS_QUERY),
|
||||
"dockerfile" => Some(arborium::lang_dockerfile::HIGHLIGHTS_QUERY),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn load_language(lang: &str) -> Option<Language> {
|
||||
let arborium_name = to_arborium_name(lang);
|
||||
let grammar = arborium::get_language(arborium_name)?;
|
||||
|
||||
let config_path = [lang, "config.yaml"].join("\\");
|
||||
let config = load_yaml(&config_path);
|
||||
let indent_unit = config.indent_unit;
|
||||
let comment_prefix = config.comment_prefix;
|
||||
let bracket_pairs = config
|
||||
.brackets
|
||||
.into_iter()
|
||||
.filter_map(|bracket_pair| {
|
||||
let start = bracket_pair.start.chars().next()?;
|
||||
let end = bracket_pair.end.chars().next()?;
|
||||
Some((start, end))
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Use arborium's bundled highlight query instead of loading from custom .scm files
|
||||
let highlight_query_str = get_arborium_highlight_query(lang)?;
|
||||
let highlight_query = Query::new(&grammar, highlight_query_str)
|
||||
.expect("arborium highlight query should be valid");
|
||||
|
||||
let indents_query_path = [lang, "indents.scm"].join("\\");
|
||||
let indents_query = load_query(&indents_query_path, &grammar);
|
||||
|
||||
let symbols_query_path = [lang, "identifiers.scm"].join("\\");
|
||||
let symbols_query = load_query(&symbols_query_path, &grammar);
|
||||
|
||||
Some(Language {
|
||||
highlight_query,
|
||||
indents_query,
|
||||
grammar,
|
||||
indent_unit,
|
||||
comment_prefix,
|
||||
bracket_pairs,
|
||||
symbols_query,
|
||||
display_name: config.display_name,
|
||||
})
|
||||
}
|
||||
|
||||
fn load_yaml(path: &str) -> LanguageConfig {
|
||||
match <Grammars as RustEmbed>::get(path) {
|
||||
Some(file) => {
|
||||
let config: LanguageConfig =
|
||||
serde_yaml::from_slice(&file.data).expect("Unable to deserialize the YAML content");
|
||||
config
|
||||
}
|
||||
None => {
|
||||
panic!("Couldn't initiate yaml config from {path}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn load_query(path: &str, grammar: &ParserGrammar) -> Option<Query> {
|
||||
let file = <Grammars as RustEmbed>::get(path)?;
|
||||
let query_content = match file.data {
|
||||
Cow::Borrowed(inner) => Cow::Borrowed(std::str::from_utf8(inner).unwrap()),
|
||||
Cow::Owned(inner) => Cow::Owned(String::from_utf8(inner).unwrap()),
|
||||
};
|
||||
|
||||
Some(
|
||||
Query::new(grammar, &query_content)
|
||||
.unwrap_or_else(|err| panic!("TSQuery creation should work from {path}: {err}")),
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "lib_tests.rs"]
|
||||
mod tests;
|
||||
@@ -0,0 +1,22 @@
|
||||
use crate::{load_language, SUPPORTED_LANGUAGES};
|
||||
|
||||
/// Validate that every supported language can be loaded successfully.
|
||||
/// This catches invalid node types, syntax errors, and other issues in .scm query files
|
||||
/// (highlights, indents, identifiers) that would otherwise only surface at runtime.
|
||||
#[test]
|
||||
fn all_supported_languages_load_successfully() {
|
||||
let failures: Vec<_> = SUPPORTED_LANGUAGES
|
||||
.iter()
|
||||
.filter(|lang| load_language(lang).is_none())
|
||||
.collect();
|
||||
|
||||
assert!(
|
||||
failures.is_empty(),
|
||||
"The following languages failed to load:\n{}",
|
||||
failures
|
||||
.iter()
|
||||
.map(|lang| format!(" - {lang}"))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user