Skip to content

Commit 7274888

Browse files
feat(syntax): add strategy to associate file to language through pattern
File path will match if it ends with any of the file types provided in the config. Also used this feature to add support for the .git/config and .ssh/config files
1 parent 7b287f6 commit 7274888

File tree

4 files changed

+349
-2
lines changed

4 files changed

+349
-2
lines changed

book/src/generated/lang-support.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
| scala || || `metals` |
7979
| solidity || | | `solc` |
8080
| sql || | | |
81+
| sshclientconfig || | | |
8182
| svelte || || `svelteserver` |
8283
| swift || | | `sourcekit-lsp` |
8384
| tablegen |||| |

helix-core/src/syntax.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,10 @@ impl Loader {
462462

463463
for file_type in &config.file_types {
464464
// entry().or_insert(Vec::new).push(language_id);
465+
let file_type = file_type.replace('/', &std::path::MAIN_SEPARATOR.to_string());
465466
loader
466467
.language_config_ids_by_file_type
467-
.insert(file_type.clone(), language_id);
468+
.insert(file_type, language_id);
468469
}
469470
for shebang in &config.shebangs {
470471
loader
@@ -489,6 +490,17 @@ impl Loader {
489490
path.extension()
490491
.and_then(|extension| extension.to_str())
491492
.and_then(|extension| self.language_config_ids_by_file_type.get(extension))
493+
})
494+
.or_else(|| {
495+
self.language_config_ids_by_file_type
496+
.iter()
497+
.find_map(|(file_type, id)| {
498+
if path.to_str()?.ends_with(file_type) {
499+
Some(id)
500+
} else {
501+
None
502+
}
503+
})
492504
});
493505

494506
configuration_id.and_then(|&id| self.language_configs.get(id).cloned())

languages.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ name = "git-config"
947947
scope = "source.gitconfig"
948948
roots = []
949949
# TODO: allow specifying file-types as a regex so we can read directory names (e.g. `.git/config`)
950-
file-types = [".gitmodules", ".gitconfig"]
950+
file-types = [".gitmodules", ".gitconfig", ".git/config", ".config/git/config"]
951951
injection-regex = "git-config"
952952
comment-token = "#"
953953
indent = { tab-width = 4, unit = "\t" }
@@ -1355,3 +1355,13 @@ indent = { tab-width = 2, unit = " " }
13551355
[[grammar]]
13561356
name = "meson"
13571357
source = { git = "https://github.com/bearcove/tree-sitter-meson", rev = "feea83be9225842490066522ced2d13eb9cce0bd" }
1358+
1359+
[[language]]
1360+
name = "sshclientconfig"
1361+
scope = "source.sshclientconfig"
1362+
file-types = [".ssh/config"]
1363+
roots = []
1364+
1365+
[[grammar]]
1366+
name = "sshclientconfig"
1367+
source = { git = "https://github.com/metio/tree-sitter-ssh-client-config.git", rev = "769d7a01a2e5493b4bb5a51096c6bf4be130b024" }
Lines changed: 324 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,324 @@
1+
(host) @keyword
2+
(host_value) @identifier
3+
4+
(match) @keyword
5+
(match_value) @identifier
6+
7+
(add_keys_to_agent) @keyword
8+
(add_keys_to_agent_value) @boolean
9+
10+
(address_family) @keyword
11+
(address_family_value) @type
12+
13+
(batch_mode) @keyword
14+
(batch_mode_value) @boolean
15+
16+
(bind_address) @keyword
17+
(bind_address_value) @string
18+
19+
(bind_interface) @keyword
20+
(bind_interface_value) @string
21+
22+
(canonical_domains) @keyword
23+
(canonical_domains_value) @identifier
24+
25+
(canonicalize_fallback_local) @keyword
26+
(canonicalize_fallback_local_value) @boolean
27+
28+
(canonicalize_hostname) @keyword
29+
(canonicalize_hostname_value) @boolean
30+
31+
(canonicalize_max_dots) @keyword
32+
(canonicalize_max_dots_value) @number
33+
34+
(canonicalize_permitted_cnames) @keyword
35+
(canonicalize_permitted_cnames_value) @identifier
36+
37+
(ca_signature_algorithms) @keyword
38+
(ca_signature_algorithms_value) @identifier
39+
40+
(certificate_file) @keyword
41+
(certificate_file_value) @file
42+
43+
(challenge_response_authentication) @keyword
44+
(challenge_response_authentication_value) @boolean
45+
46+
(check_host_ip) @keyword
47+
(check_host_ip_value) @boolean
48+
49+
(cipher) @keyword
50+
(cipher_value) @identifier
51+
52+
(ciphers) @keyword
53+
(ciphers_value) @identifier
54+
55+
(clear_all_forwardings) @keyword
56+
(clear_all_forwardings_value) @boolean
57+
58+
(comment) @comment
59+
60+
(compression) @keyword
61+
(compression_value) @boolean
62+
63+
(connect_timeout) @keyword
64+
(connect_timeout_value) @number
65+
66+
(connection_attempts) @keyword
67+
(connection_attempts_value) @number
68+
69+
(control_master) @keyword
70+
(control_master_value) @type
71+
72+
(control_path) @keyword
73+
(control_path_value) @file
74+
75+
(control_persist) @keyword
76+
(control_persist_value) @type
77+
78+
(dynamic_forward) @keyword
79+
(dynamic_forward_value) @string
80+
81+
(enable_ssh_keysign) @keyword
82+
(enable_ssh_keysign_value) @boolean
83+
84+
(escape_char) @keyword
85+
(escape_char_value) @string
86+
87+
(exit_on_forward_failure) @keyword
88+
(exit_on_forward_failure_value) @boolean
89+
90+
(fingerprint_hash) @keyword
91+
(fingerprint_hash_value) @identifier
92+
93+
(fork_after_authentication) @keyword
94+
(fork_after_authentication_value) @boolean
95+
96+
(forward_agent) @keyword
97+
(forward_agent_value) @boolean
98+
99+
(forward_x11) @keyword
100+
(forward_x11_value) @boolean
101+
102+
(forward_x11_timeout) @keyword
103+
(forward_x11_timeout_value) @time
104+
105+
(forward_x11_trusted) @keyword
106+
(forward_x11_trusted_value) @boolean
107+
108+
(gateway_ports) @keyword
109+
(gateway_ports_value) @boolean
110+
111+
(global_known_hosts_file) @keyword
112+
(global_known_hosts_file_value) @file
113+
114+
(gssapi_authentication) @keyword
115+
(gssapi_authentication_value) @boolean
116+
117+
(gssapi_client_identity) @keyword
118+
(gssapi_client_identity_value) @string
119+
120+
(gssapi_delegate_credentials) @keyword
121+
(gssapi_delegate_credentials_value) @boolean
122+
123+
(gssapi_kex_algorithms) @keyword
124+
(gssapi_kex_algorithms_value) @identifier
125+
126+
(gssapi_key_exchange) @keyword
127+
(gssapi_key_exchange_value) @boolean
128+
129+
(gssapi_renewal_forces_rekey) @keyword
130+
(gssapi_renewal_forces_rekey_value) @boolean
131+
132+
(gssapi_server_identity) @keyword
133+
(gssapi_server_identity_value) @string
134+
135+
(gssapi_trust_dns) @keyword
136+
(gssapi_trust_dns_value) @boolean
137+
138+
(hash_known_hosts) @keyword
139+
(hash_known_hosts_value) @boolean
140+
141+
(host_key_algorithms) @keyword
142+
(host_key_algorithms_value) @identifier
143+
144+
(host_key_alias) @keyword
145+
(host_key_alias_value) @string
146+
147+
(hostbased_accepted_algorithms) @keyword
148+
(hostbased_accepted_algorithms_value) @identifier
149+
150+
(hostbased_authentication) @keyword
151+
(hostbased_authentication_value) @boolean
152+
153+
(hostname) @keyword
154+
(hostname_value) @string
155+
156+
(identities_only) @keyword
157+
(identities_only_value) @boolean
158+
159+
(identity_agent) @keyword
160+
(identity_agent_value) @string
161+
162+
(identity_file) @keyword
163+
(identity_file_value) @file
164+
165+
(ignore_unknown) @keyword
166+
(ignore_unknown_value) @string
167+
168+
(include) @keyword
169+
(include_value) @file
170+
171+
(ip_qos) @keyword
172+
(ip_qos_value) @type
173+
174+
(kbd_interactive_authentication) @keyword
175+
(kbd_interactive_authentication_value) @boolean
176+
177+
(kbd_interactive_devices) @keyword
178+
(kbd_interactive_devices_value) @type
179+
180+
(kex_algorithms) @keyword
181+
(kex_algorithms_value) @identifier
182+
183+
(known_hosts_command) @keyword
184+
(known_hosts_command_value) @string
185+
186+
(local_command) @keyword
187+
(local_command_value) @string
188+
189+
(local_forward) @keyword
190+
(local_forward_value) @string
191+
192+
(log_level) @keyword
193+
(log_level_value) @type
194+
195+
(log_verbose) @keyword
196+
(log_verbose_value) @string
197+
198+
(macs) @keyword
199+
(macs_value) @identifier
200+
201+
(no_host_authentication_for_localhost) @keyword
202+
(no_host_authentication_for_localhost_value) @boolean
203+
204+
(number_of_password_prompts) @keyword
205+
(number_of_password_prompts_value) @number
206+
207+
(password_authentication) @keyword
208+
(password_authentication_value) @boolean
209+
210+
(permit_local_command) @keyword
211+
(permit_local_command_value) @boolean
212+
213+
(permit_remote_open) @keyword
214+
(permit_remote_open_value) @string
215+
216+
(pkcs11_provider) @keyword
217+
(pkcs11_provider_value) @string
218+
219+
(port) @keyword
220+
(port_value) @number
221+
222+
(preferred_authentications) @keyword
223+
(preferred_authentications_value) @type
224+
225+
(protocol) @keyword
226+
(protocol_value) @number
227+
228+
(proxy_command) @keyword
229+
(proxy_command_value) @string
230+
231+
(proxy_jump) @keyword
232+
(proxy_jump_value) @string
233+
234+
(proxy_use_fdpass) @keyword
235+
(proxy_use_fdpass_value) @boolean
236+
237+
(pubkey_accepted_algorithms) @keyword
238+
(pubkey_accepted_algorithms_value) @identifier
239+
240+
(pubkey_accepted_key_types) @keyword
241+
(pubkey_accepted_key_types_value) @identifier
242+
243+
(pubkey_authentication) @keyword
244+
(pubkey_authentication_value) @boolean
245+
246+
(rekey_limit) @keyword
247+
(rekey_limit_value) @string
248+
249+
(remote_command) @keyword
250+
(remote_command_value) @string
251+
252+
(remote_forward) @keyword
253+
(remote_forward_value) @string
254+
255+
(request_tty) @keyword
256+
(request_tty_value) @type
257+
258+
(revoked_host_keys) @keyword
259+
(revoked_host_keys_value) @file
260+
261+
(security_key_provider) @keyword
262+
(security_key_provider_value) @string
263+
264+
(send_env) @keyword
265+
(send_env_value) @string
266+
267+
(server_alive_count_max) @keyword
268+
(server_alive_count_max_value) @number
269+
270+
(server_alive_interval) @keyword
271+
(server_alive_interval_value) @number
272+
273+
(session_type) @keyword
274+
(session_type_value) @type
275+
276+
(set_env) @keyword
277+
(set_env_value) @string
278+
279+
(stdin_null) @keyword
280+
(stdin_null_value) @boolean
281+
282+
(stream_local_bind_mask) @keyword
283+
(stream_local_bind_mask_value) @string
284+
285+
(stream_local_bind_unlink) @keyword
286+
(stream_local_bind_unlink_value) @boolean
287+
288+
(strict_host_key_checking) @keyword
289+
(strict_host_key_checking_value) @type
290+
291+
(syslog_facility) @keyword
292+
(syslog_facility_value) @type
293+
294+
(tcp_keep_alive) @keyword
295+
(tcp_keep_alive_value) @boolean
296+
(keep_alive) @keyword
297+
(keep_alive_value) @boolean
298+
299+
(tunnel) @keyword
300+
(tunnel_value) @type
301+
302+
(tunnel_device) @keyword
303+
(tunnel_device_value) @string
304+
305+
(update_host_keys) @keyword
306+
(update_host_keys_value) @type
307+
308+
(use_keychain) @keyword
309+
(use_keychain_value) @boolean
310+
311+
(user) @keyword
312+
(user_value) @string
313+
314+
(user_known_hosts_file) @keyword
315+
(user_known_hosts_file_value) @file
316+
317+
(verify_host_key_dns) @keyword
318+
(verify_host_key_dns_value) @type
319+
320+
(visual_host_key) @keyword
321+
(visual_host_key_value) @boolean
322+
323+
(xauth_location) @keyword
324+
(xauth_location_value) @file

0 commit comments

Comments
 (0)