mirror of
https://github.com/helix-editor/helix.git
synced 2024-08-16 22:30:36 +03:00
Update Swift Grammar and Queries (#10802)
This commit is contained in:
parent
44504b720b
commit
aa1630a41a
@ -190,7 +190,7 @@
|
||||
| supercollider | ✓ | | | |
|
||||
| svelte | ✓ | | ✓ | `svelteserver` |
|
||||
| sway | ✓ | ✓ | ✓ | `forc` |
|
||||
| swift | ✓ | | | `sourcekit-lsp` |
|
||||
| swift | ✓ | ✓ | | `sourcekit-lsp` |
|
||||
| t32 | ✓ | | | |
|
||||
| tablegen | ✓ | ✓ | ✓ | |
|
||||
| tact | ✓ | ✓ | ✓ | |
|
||||
|
@ -1908,16 +1908,17 @@ language-servers = [ "r" ]
|
||||
name = "swift"
|
||||
scope = "source.swift"
|
||||
injection-regex = "swift"
|
||||
file-types = ["swift"]
|
||||
file-types = ["swift", "swiftinterface"]
|
||||
roots = [ "Package.swift" ]
|
||||
comment-token = "//"
|
||||
block-comment-tokens = { start = "/*", end = "*/" }
|
||||
formatter = { command = "swift-format", args = [ "--configuration", ".swift-format"] }
|
||||
auto-format = true
|
||||
language-servers = [ "sourcekit-lsp" ]
|
||||
|
||||
[[grammar]]
|
||||
name = "swift"
|
||||
source = { git = "https://github.com/alex-pinkus/tree-sitter-swift", rev = "b1b66955d420d5cf5ff268ae552f0d6e43ff66e1" }
|
||||
source = { git = "https://github.com/alex-pinkus/tree-sitter-swift", rev = "57c1c6d6ffa1c44b330182d41717e6fe37430704" }
|
||||
|
||||
[[language]]
|
||||
name = "erb"
|
||||
|
@ -1,4 +1,4 @@
|
||||
; Upstream: https://github.com/alex-pinkus/tree-sitter-swift/blob/1c586339fb00014b23d6933f2cc32b588a226f3b/queries/highlights.scm
|
||||
; Upstream: https://github.com/alex-pinkus/tree-sitter-swift/blob/57c1c6d6ffa1c44b330182d41717e6fe37430704/queries/highlights.scm
|
||||
|
||||
(line_string_literal
|
||||
["\\(" ")"] @punctuation.special)
|
||||
@ -10,6 +10,7 @@
|
||||
(attribute) @variable
|
||||
(type_identifier) @type
|
||||
(self_expression) @variable.builtin
|
||||
(user_type (type_identifier) @variable.builtin (#eq? @variable.builtin "Self"))
|
||||
|
||||
; Declarations
|
||||
"func" @keyword.function
|
||||
@ -23,7 +24,9 @@
|
||||
] @keyword
|
||||
|
||||
(function_declaration (simple_identifier) @function.method)
|
||||
(function_declaration "init" @constructor)
|
||||
(init_declaration ["init" @constructor])
|
||||
(deinit_declaration ["deinit" @constructor])
|
||||
|
||||
(throws) @keyword
|
||||
"async" @keyword
|
||||
"await" @keyword
|
||||
@ -48,10 +51,23 @@
|
||||
"override"
|
||||
"convenience"
|
||||
"required"
|
||||
"some"
|
||||
"mutating"
|
||||
"associatedtype"
|
||||
"package"
|
||||
"any"
|
||||
] @keyword
|
||||
|
||||
(opaque_type ["some" @keyword])
|
||||
(existential_type ["any" @keyword])
|
||||
|
||||
(precedence_group_declaration
|
||||
["precedencegroup" @keyword]
|
||||
(simple_identifier) @type)
|
||||
(precedence_group_attribute
|
||||
(simple_identifier) @keyword
|
||||
[(simple_identifier) @type
|
||||
(boolean_literal) @constant.builtin.boolean])
|
||||
|
||||
[
|
||||
(getter_specifier)
|
||||
(setter_specifier)
|
||||
@ -73,6 +89,10 @@
|
||||
((navigation_expression
|
||||
(simple_identifier) @type) ; SomeType.method(): highlight SomeType as a type
|
||||
(#match? @type "^[A-Z]"))
|
||||
(call_expression (simple_identifier) @keyword (#eq? @keyword "defer")) ; defer { ... }
|
||||
|
||||
(try_operator) @operator
|
||||
(try_operator ["try" @keyword])
|
||||
|
||||
(directive) @function.macro
|
||||
(diagnostic) @function.macro
|
||||
@ -136,10 +156,8 @@
|
||||
|
||||
; Operators
|
||||
[
|
||||
"try"
|
||||
"try?"
|
||||
"try!"
|
||||
"!"
|
||||
"?"
|
||||
"+"
|
||||
"-"
|
||||
"*"
|
||||
@ -171,3 +189,8 @@
|
||||
"..."
|
||||
(custom_operator)
|
||||
] @operator
|
||||
|
||||
(value_parameter_pack ["each" @keyword])
|
||||
(value_pack_expansion ["repeat" @keyword])
|
||||
(type_parameter_pack ["each" @keyword])
|
||||
(type_pack_expansion ["repeat" @keyword])
|
||||
|
6
runtime/queries/swift/injections.scm
Normal file
6
runtime/queries/swift/injections.scm
Normal file
@ -0,0 +1,6 @@
|
||||
; Upstream: https://github.com/alex-pinkus/tree-sitter-swift/blob/57c1c6d6ffa1c44b330182d41717e6fe37430704/queries/injections.scm
|
||||
|
||||
; Parse regex syntax within regex literals
|
||||
|
||||
((regex_literal) @injection.content
|
||||
(#set! injection.language "regex"))
|
@ -1,7 +1,19 @@
|
||||
; Upstream: https://github.com/alex-pinkus/tree-sitter-swift/blob/57c1c6d6ffa1c44b330182d41717e6fe37430704/queries/locals.scm
|
||||
(import_declaration (identifier) @definition.import)
|
||||
(function_declaration name: (simple_identifier) @definition.function)
|
||||
|
||||
; Scopes
|
||||
[
|
||||
(for_statement)
|
||||
(while_statement)
|
||||
(repeat_while_statement)
|
||||
(do_statement)
|
||||
(if_statement)
|
||||
(guard_statement)
|
||||
(switch_statement)
|
||||
(property_declaration)
|
||||
(function_declaration)
|
||||
(class_declaration)
|
||||
(protocol_declaration)
|
||||
(lambda_literal)
|
||||
] @local.scope
|
||||
|
||||
(parameter name: (simple_identifier) @local.definition)
|
||||
|
||||
(simple_identifier) @local.reference
|
||||
|
23
runtime/queries/swift/textobjects.scm
Normal file
23
runtime/queries/swift/textobjects.scm
Normal file
@ -0,0 +1,23 @@
|
||||
(class_declaration
|
||||
body: (_) @class.inside) @class.around
|
||||
|
||||
(protocol_declaration
|
||||
body: (_) @class.inside) @class.around
|
||||
|
||||
(function_declaration
|
||||
body: (_) @function.inside) @function.around
|
||||
|
||||
(parameter
|
||||
(_) @parameter.inside) @parameter.around
|
||||
|
||||
(lambda_parameter
|
||||
(_) @parameter.inside) @parameter.around
|
||||
|
||||
[
|
||||
(comment)
|
||||
(multiline_comment)
|
||||
] @comment.inside
|
||||
|
||||
(comment)+ @comment.around
|
||||
|
||||
(multiline_comment) @comment.around
|
Loading…
Reference in New Issue
Block a user