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

Update Unison grammar and queries #12039

Merged
merged 4 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
| typespec | ✓ | ✓ | ✓ | `tsp-server` |
| typst | ✓ | | | `tinymist`, `typst-lsp` |
| ungrammar | ✓ | | | |
| unison | ✓ | | ✓ | |
| unison | ✓ | | ✓ | |
| uxntal | ✓ | | | |
| v | ✓ | ✓ | ✓ | `v-analyzer` |
| vala | ✓ | ✓ | | `vala-language-server` |
Expand Down
2 changes: 1 addition & 1 deletion languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3316,7 +3316,7 @@ indent = { tab-width = 4, unit = " " }

[[grammar]]
name = "unison"
source = { git = "https://github.com/kylegoetz/tree-sitter-unison", rev = "1f505e2447fa876a87aee47ff3d70b9e141c744f" }
source = { git = "https://github.com/kylegoetz/tree-sitter-unison", rev = "3c97db76d3cdbd002dfba493620c2d5df2fd6fa9" }

[[language]]
name = "todotxt"
Expand Down
81 changes: 57 additions & 24 deletions runtime/queries/unison/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,25 @@
;; Keywords
[
(kw_forall)
(type_kw)
(kw_equals)
(do)
(kw_let)
(ability)
(where)
] @keyword

(kw_let) @keyword.function
(type_kw) @keyword.storage.type
(unique) @keyword.storage.modifier
(type_kw) @keyword.storage.modifier
(structural) @keyword.storage.modifier
("use") @keyword.control.import


[
(type_constructor)
] @constructor
(unique) @keyword.storage.modifier

[
(operator)
(pipe)
(arrow_symbol)
(">")
(or)
(and)
(bang)
] @operator

[
Expand All @@ -48,24 +41,62 @@

(blank_pattern) @variable.builtin

(pattern) @variable

(use_clause) @keyword.import

;; Types
(record_field name: (wordy_id) @variable.other.member type: (_) @type)
(type_constructor (type_name (wordy_id) @constructor))
(ability_declaration type_name: (wordy_id) @type type_arg: (wordy_id) @variable.parameter)
(effect (wordy_id) @special) ;; NOTE: an effect is just like a type, but in signature we special case it
(record_field
(field_name) @variable.other.member
type: (regular_identifier) @type)

(type_name) @type

(type_declaration
(regular_identifier) @type.enum.variant)

(ability_name
(path)? @namespace
(regular_identifier) @type)

;; Namespaces
(path) @namespace
(namespace) @namespace
(ability_declaration
(ability_name) @type
(type_argument) @variable.parameter)

;; Terms
(type_signature term_name: (path)? @variable term_name: (wordy_id) @variable)
(type_signature (wordy_id) @type)
(type_signature (term_type(delayed(wordy_id))) @type)
(type_constructor) @constructor

(term_definition param: (wordy_id) @variable.parameter)
(constructor
(constructor_name) @constructor)

(function_application function_name: (path)? function_name: (wordy_id) @function)
(constructor
type: (regular_identifier) @type)

(effect
(regular_identifier) @special) ; NOTE: an effect is a special type

; Namespaces
(path) @module

(namespace) @module

; Terms
(type_signature
term_name: (path) @module
term_name: (regular_identifier) @variable)

(type_signature
term_name: (regular_identifier) @variable)

(term_type) @type

(term_definition
name: (path) @namespace)

(term_definition
name: (regular_identifier) @variable)

(term_definition
param: (regular_identifier) @variable.parameter)

;; Punctuation
[
Expand All @@ -82,4 +113,6 @@
"]"
] @punctuation.bracket

(test_watch_expression (wordy_id) @keyword.directive)
(watch_expression) @keyword.directive

(test_watch_expression) @keyword.directive
5 changes: 0 additions & 5 deletions runtime/queries/unison/indents.scm
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
[
(term_definition)
(type_declaration)
(pattern)
(tuple_or_parenthesized)
(literal_list)
(tuple_pattern)
(function_application)
(exp_if)
(constructor)
(delay_block)
Expand Down
15 changes: 15 additions & 0 deletions runtime/queries/unison/textobjects.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(term_declaration) @function.around

(type_declaration) @class.inside
(record) @class.inside

(comment) @comment.inside
(comment)+ @comment.around

(doc_block) @comment.around

(literal_list) @entry.around

(parenthesized_or_tuple_pattern) @entry.around

(pattern) @entry.around