on master help sign in
Add swift language (#2033)
9caf7c0Aaron Housh
book/src/generated/lang-support.md+1
@@ -61,6 +61,7 @@
61| scala | ✓ | | ✓ | `metals` |
61| scala | ✓ | | ✓ | `metals` |
62| solidity | ✓ | | | `solc` |
62| solidity | ✓ | | | `solc` |
63| svelte | ✓ | | ✓ | `svelteserver` |
63| svelte | ✓ | | ✓ | `svelteserver` |
64+| swift | ✓ | | | `sourcekit-lsp` |
64| tablegen | ✓ | ✓ | ✓ | |
65| tablegen | ✓ | ✓ | ✓ | |
65| toml | ✓ | | | |
66| toml | ✓ | | | |
66| tsq | ✓ | | | |
67| tsq | ✓ | | | |
languages.toml+14
@@ -1071,3 +1071,17 @@ roots = []
1071indent = { tab-width = 2, unit = " " }
1071indent = { tab-width = 2, unit = " " }
1072grammar = "markdown"
1072grammar = "markdown"
1073language-server = { command = "R", args = ["--slave", "-e", "languageserver::run()"] }
1073language-server = { command = "R", args = ["--slave", "-e", "languageserver::run()"] }
1074+
1075+[[language]]
1076+name = "swift"
1077+scope = "source.swift"
1078+injection-regex = "swift"
1079+file-types = ["swift"]
1080+roots = [ "Package.swift" ]
1081+comment-token = "//"
1082+auto-format = true
1083+language-server = { command = "sourcekit-lsp" }
1084+
1085+[[grammar]]
1086+name = "swift"
1087+source = { git = "https://github.com/Dispersia/tree-sitter-swift", rev = "e75240f89bb3bfd3396155859ae364e5c58d7377" }
runtime/queries/swift/highlights.scmnew file+158
@@ -0,0 +1,158 @@
1+[ "." ";" ":" "," ] @punctuation.delimiter
2+[ "\\(" "(" ")" "[" "]" "{" "}"] @punctuation.bracket ; TODO: "\\(" ")" in interpolations should be @punctuation.special
3+
4+; Identifiers
5+(attribute) @variable
6+(type_identifier) @type
7+(self_expression) @variable.builtin
8+
9+; Declarations
10+"func" @keyword.function
11+[
12+ (visibility_modifier)
13+ (member_modifier)
14+ (function_modifier)
15+ (property_modifier)
16+ (parameter_modifier)
17+ (inheritance_modifier)
18+] @keyword
19+
20+(function_declaration (simple_identifier) @function.method)
21+(function_declaration ["init" @constructor])
22+(throws) @keyword
23+"async" @keyword
24+(where_keyword) @keyword
25+(parameter external_name: (simple_identifier) @variable.parameter)
26+(parameter name: (simple_identifier) @variable.parameter)
27+(type_parameter (type_identifier) @variable.parameter)
28+(inheritance_constraint (identifier (simple_identifier) @variable.parameter))
29+(equality_constraint (identifier (simple_identifier) @variable.parameter))
30+(non_binding_pattern bound_identifier: (simple_identifier)) @variable
31+
32+[
33+ "typealias"
34+ "struct"
35+ "class"
36+ "enum"
37+ "protocol"
38+ "extension"
39+ "indirect"
40+ "some"
41+] @keyword
42+
43+[
44+ (getter_specifier)
45+ (setter_specifier)
46+ (modify_specifier)
47+] @keyword
48+
49+(class_body (property_declaration (value_binding_pattern (non_binding_pattern (simple_identifier) @variable.other.member))))
50+(protocol_property_declaration (value_binding_pattern (non_binding_pattern (simple_identifier) @variable.other.member)))
51+
52+(import_declaration ["import" @keyword.control.import])
53+
54+(enum_entry ["case" @keyword])
55+
56+; Function calls
57+(call_expression (simple_identifier) @function) ; foo()
58+(call_expression ; foo.bar.baz(): highlight the baz()
59+ (navigation_expression
60+ (navigation_suffix (simple_identifier) @function)))
61+((navigation_expression
62+ (simple_identifier) @type) ; SomeType.method(): highlight SomeType as a type
63+ (#match? @type "^[A-Z]"))
64+
65+(directive) @function.macro
66+(diagnostic) @function.macro
67+
68+; Statements
69+(for_statement ["for" @keyword.control.repeat])
70+(for_statement ["in" @keyword.control.repeat])
71+(for_statement item: (simple_identifier) @variable)
72+(else) @keyword
73+(as_operator) @keyword
74+
75+["while" "repeat" "continue" "break"] @keyword.control.repeat
76+
77+["let" "var"] @keyword
78+(non_binding_pattern (simple_identifier) @variable)
79+
80+(guard_statement ["guard" @keyword.control.conditional])
81+(if_statement ["if" @keyword.control.conditional])
82+(switch_statement ["switch" @keyword.control.conditional])
83+(switch_entry ["case" @keyword])
84+(switch_entry ["fallthrough" @keyword])
85+(switch_entry (default_keyword) @keyword)
86+"return" @keyword.control.return
87+(ternary_expression
88+ ["?" ":"] @keyword.control.conditional)
89+
90+["do" (throw_keyword) (catch_keyword)] @keyword
91+
92+(statement_label) @label
93+
94+; Comments
95+(comment) @comment.line
96+(multiline_comment) @comment.block
97+
98+; String literals
99+(line_str_text) @string
100+(str_escaped_char) @string
101+(multi_line_str_text) @string
102+(raw_str_part) @string
103+(raw_str_end_part) @string
104+(raw_str_interpolation_start) @string.special
105+["\"" "\"\"\""] @string
106+
107+; Lambda literals
108+(lambda_literal ["in" @keyword.operator])
109+
110+; Basic literals
111+(integer_literal) @constant.numeric.integer
112+[
113+ (hex_literal)
114+ (oct_literal)
115+ (bin_literal)
116+] @constant.numeric
117+(real_literal) @constant.numeric.float
118+(boolean_literal) @constant.builtin.boolean
119+"nil" @variable.builtin
120+
121+; Operators
122+(custom_operator) @operator
123+[
124+ "try"
125+ "try?"
126+ "try!"
127+ "!"
128+ "+"
129+ "-"
130+ "*"
131+ "/"
132+ "%"
133+ "="
134+ "+="
135+ "-="
136+ "*="
137+ "/="
138+ "<"
139+ ">"
140+ "<="
141+ ">="
142+ "++"
143+ "--"
144+ "&"
145+ "~"
146+ "%="
147+ "!="
148+ "!=="
149+ "=="
150+ "==="
151+ "??"
152+
153+ "->"
154+
155+ "..<"
156+ "..."
157+] @operator
158+
runtime/queries/swift/locals.scmnew file+18
@@ -0,0 +1,18 @@
1+(import_declaration (identifier) @definition.import)
2+(function_declaration name: (simple_identifier) @definition.function)
3+
4+; Scopes
5+[
6+ (statements)
7+ (for_statement)
8+ (while_statement)
9+ (repeat_while_statement)
10+ (do_statement)
11+ (if_statement)
12+ (guard_statement)
13+ (switch_statement)
14+ (property_declaration)
15+ (function_declaration)
16+ (class_declaration)
17+ (protocol_declaration)
18+] @scope