Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree-sitter: Add the .slint UI language #3025

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [#3026](https://github.com/lapce/lapce/pull/3026): Add missing file explorer context menu entries
- [#3047](https://github.com/lapce/lapce/pull/3047): Add support for different CrLf/Lf line endings per-file
- [#3053](https://github.com/lapce/lapce/pull/3053): Add tooltips to various places
- [2407](https://github.com/lapce/lapce/pull/2407): Add support for slint UI language

### Bug Fixes
- [#2779](https://github.com/lapce/lapce/pull/2779): Fix files detection on fresh git/VCS repository
Expand Down
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lapce-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ all-languages = [
"lapce-core/lang-markdown",
"lapce-core/lang-python",
"lapce-core/lang-rust",
"lapce-core/lang-slint",
"lapce-core/lang-toml",
"lapce-core/lang-yaml",
]
Expand Down
2 changes: 2 additions & 0 deletions lapce-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json.git"
tree-sitter-md = { git = "https://github.com/MDeiml/tree-sitter-markdown.git", rev = "272e080bca0efd19a06a7f4252d746417224959e", optional = true }
tree-sitter-python = { version = "0.20.4", optional = true }
tree-sitter-rust = { version = "0.20.4", optional = true }
tree-sitter-slint = { git = "https://github.com/slint-ui/tree-sitter-slint.git", optional = true }
tree-sitter-toml = { version = "0.20.0", optional = true }
tree-sitter-yaml = { git = "https://github.com/panekj/tree-sitter-yaml", rev = "80c8d76847f03e772c5c524cf29bafb56858a8d1", optional = true }

Expand All @@ -57,6 +58,7 @@ lang-json = ["dep:tree-sitter-json"]
lang-markdown = ["dep:tree-sitter-md"]
lang-python = ["dep:tree-sitter-python"]
lang-rust = ["dep:tree-sitter-rust"]
lang-slint = ["dep:tree-sitter-slint"]
lang-toml = ["dep:tree-sitter-toml"]
lang-yaml = ["dep:tree-sitter-yaml"]

Expand Down
11 changes: 11 additions & 0 deletions lapce-core/queries/slint/folds.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
(anon_struct_block)
(block)
(callback_event)
(component)
(enum_block)
(function_definition)
(global_definition)
(imperative_block)
(struct_block)
] @fold
261 changes: 261 additions & 0 deletions lapce-core/queries/slint/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
(comment) @comment @spell

; Different types:
(string_value) @string @spell

(escape_sequence) @string.escape

(color_value) @constant

[
(children_identifier)
(easing_kind_identifier)
] @constant.builtin

(bool_value) @boolean

[
(int_value)
(physical_length_value)
] @number

[
(angle_value)
(duration_value)
(float_value)
(length_value)
(percent_value)
(relative_font_size_value)
] @number.float

(purity) @type.qualifier

(function_visibility) @type.qualifier

(property_visibility) @type.qualifier

(builtin_type_identifier) @type.builtin

(reference_identifier) @variable.builtin

(type
[
(type_list)
(user_type_identifier)
(anon_struct_block)
]) @type

(user_type_identifier) @type

; Functions and callbacks
(argument) @variable.parameter

(function_call
name: (_) @function.call)

; definitions
(callback
name: (_) @function)

(callback_alias
name: (_) @function)

(callback_event
name: (simple_identifier) @function.call)

(component
id: (_) @variable)

(enum_definition
name: (_) @type)

(function_definition
name: (_) @function)

(struct_definition
name: (_) @type)

(typed_identifier
type: (_) @type)

; Operators
(binary_expression
op: (_) @operator)

(unary_expression
op: (_) @operator)

[
(comparison_operator)
(mult_prec_operator)
(add_prec_operator)
(unary_prec_operator)
(assignment_prec_operator)
] @operator

[
":="
"=>"
"->"
"<=>"
] @operator

; Punctuation
[
";"
"."
","
":"
] @punctuation.delimiter

[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket

(property
[
"<"
">"
] @punctuation.bracket)

; Properties, Variables and Constants:
(component
id: (simple_identifier) @constant)

(property
name: (simple_identifier) @property)

(binding_alias
name: (simple_identifier) @property)

(binding
name: (simple_identifier) @property)

(struct_block
(simple_identifier) @variable.member)

(anon_struct_block
(simple_identifier) @variable.member)

(property_assignment
property: (simple_identifier) @property)

(states_definition
name: (simple_identifier) @variable)

(callback
name: (simple_identifier) @variable)

(typed_identifier
name: (_) @variable)

(simple_indexed_identifier
name: (simple_identifier) @variable
index_var: (simple_identifier) @variable)

(expression
(simple_identifier) @variable)

(member_access
member:
(expression
(simple_identifier) @property))

(states_definition
name: (simple_identifier) @constant)

; Attributes:
[
(linear_gradient_identifier)
(radial_gradient_identifier)
(radial_gradient_kind)
] @attribute

(image_call
"@image-url" @attribute)

(tr
"@tr" @attribute)

; Keywords:
(animate_option_identifier) @keyword

(export) @keyword

(if_statement
"if" @keyword.conditional)

(if_expr
[
"if"
"else"
] @keyword.conditional)

(ternary_expression
[
"?"
":"
] @keyword.conditional.ternary)

(animate_statement
"animate" @keyword)

(callback
"callback" @keyword)

(component_definition
[
"component"
"inherits"
] @keyword)

(enum_definition
"enum" @keyword)

(for_loop
[
"for"
"in"
] @keyword.repeat)

(function_definition
"function" @keyword.function)

(global_definition
"global" @keyword)

(imperative_block
"return" @keyword.return)

(import_statement
[
"import"
"from"
] @keyword.import)

(import_type
"as" @keyword.import)

(property
"property" @keyword)

(states_definition
[
"states"
"when"
] @keyword)

(struct_definition
"struct" @keyword)

(transitions_definition
[
"transitions"
"in"
"out"
] @keyword)
26 changes: 26 additions & 0 deletions lapce-core/queries/slint/indents.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
(arguments)
(block)
(enum_block)
(global_block)
(imperative_block)
(struct_block)
(typed_identifier)
] @indent.begin

([
(block)
(enum_block)
(global_block)
(imperative_block)
(struct_block)
]
"}" @indent.end)

([
(arguments)
(typed_identifier)
]
")" @indent.end)

(string_value) @indent.auto
2 changes: 2 additions & 0 deletions lapce-core/queries/slint/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @injection.content
(#set! injection.language "comment"))