From 9437f7d02e348f034f057afa75b65f6405fee064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Sun, 31 May 2026 21:30:13 +0900 Subject: [PATCH] lang: Update swift --- languages.toml | 2 +- runtime/queries/swift/highlights.scm | 26 ++++++++++++++++++++++++-- runtime/queries/swift/textobjects.scm | 17 +++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/languages.toml b/languages.toml index 78d59eac..5fbe1754 100644 --- a/languages.toml +++ b/languages.toml @@ -2544,7 +2544,7 @@ language-servers = [ "sourcekit-lsp" ] [[grammar]] name = "swift" -source = { git = "https://github.com/alex-pinkus/tree-sitter-swift", rev = "57c1c6d6ffa1c44b330182d41717e6fe37430704" } +source = { git = "https://github.com/alex-pinkus/tree-sitter-swift", rev = "7b7909f2f6b9414be0958275f4c8e5d69c3bca43" } [[language]] name = "erb" diff --git a/runtime/queries/swift/highlights.scm b/runtime/queries/swift/highlights.scm index ecafde40..758a71ac 100644 --- a/runtime/queries/swift/highlights.scm +++ b/runtime/queries/swift/highlights.scm @@ -1,4 +1,12 @@ -; Upstream: https://github.com/alex-pinkus/tree-sitter-swift/blob/57c1c6d6ffa1c44b330182d41717e6fe37430704/queries/highlights.scm +; Upstream: https://github.com/alex-pinkus/tree-sitter-swift/blob/7b7909f2f6b9414be0958275f4c8e5d69c3bca43/queries/highlights.scm + +; Typed throws (SE-0413), `func f() throws(MyError)`: the `throws` keyword is a +; hidden token inside `throws_clause`, so it has no node of its own to capture. +; Capturing the whole clause as a base layer up here, before the punctuation and +; type rules below, leaves only the bare `throws` word coloured: the parens fall +; back to @punctuation.bracket and the error type to @type via those later, more +; specific rules. +(throws_clause) @keyword (line_string_literal ["\\(" ")"] @punctuation.special) @@ -142,10 +150,20 @@ (directive) @function.macro (diagnostic) @function.macro +; Freestanding macro expansion (`#myMacro(…)`): colour the macro name. The `.` +; anchors to the direct-child name so the call arguments are unaffected. +(macro_invocation . (simple_identifier) @function.macro) +; Playground literals: `#colorLiteral(…)`, `#imageLiteral(…)`, `#fileLiteral(…)`. +(playground_literal + ["colorLiteral" "fileLiteral" "imageLiteral"] @function.macro) + ; Statements (for_statement "for" @keyword.control.repeat) (for_statement "in" @keyword.control.repeat) -(for_statement item: (simple_identifier) @variable) +; The loop variable is now an `item: (pattern …)` (was a bare `simple_identifier` +; pre-0.7). `for x in xs` is caught by the `pattern bound_identifier` rule above +; and tuple bindings `for (k, v) in …` by the general `(simple_identifier)` rule, +; so no dedicated rule is needed here. (else) @keyword (as_operator) @keyword @@ -194,6 +212,10 @@ (boolean_literal) @constant.builtin.boolean "nil" @constant.builtin +; Magic compile-time literals: `#file`, `#fileID`, `#filePath`, `#line`, +; `#column`, `#function`, `#dsohandle`. Colour the whole node (incl. the `#`). +(special_literal) @constant.builtin + (value_parameter_pack ["each" @keyword]) (value_pack_expansion ["repeat" @keyword]) (type_parameter_pack ["each" @keyword]) diff --git a/runtime/queries/swift/textobjects.scm b/runtime/queries/swift/textobjects.scm index 2a9938bf..65009547 100644 --- a/runtime/queries/swift/textobjects.scm +++ b/runtime/queries/swift/textobjects.scm @@ -7,12 +7,29 @@ (function_declaration body: (_) @function.inside) @function.around +(init_declaration + body: (_) @function.inside) @function.around + +(deinit_declaration + body: (_) @function.inside) @function.around + +(subscript_declaration + (computed_property) @function.inside) @function.around + +; Closures: the body lives in a `statements` child (the `{ … in }` signature is +; separate), so `*.inside` is the body alone; optional so empty closures match. +(lambda_literal + (statements)? @function.inside) @function.around + (parameter (_) @parameter.inside) @parameter.around (lambda_parameter (_) @parameter.inside) @parameter.around +(value_argument + (_) @parameter.inside) @parameter.around + [ (comment) (multiline_comment) -- 2.51.2