From 4ac29434cb99b517dba3752a287c0edfe8679e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Mon, 6 Sep 2021 18:13:52 +0900 Subject: [PATCH] syntax: Add go & rust locals, improve tree-sitter error message --- helix-core/src/syntax.rs | 8 ++++++-- runtime/queries/go/highlights.scm | 6 +++--- runtime/queries/go/locals.scm | 30 ++++++++++++++++++++++++++++++ runtime/queries/rust/locals.scm | 17 +++++++++++++++++ theme.toml | 2 +- 5 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 runtime/queries/go/locals.scm create mode 100644 runtime/queries/rust/locals.scm diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index a7a5d022d..1afe0e25a 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -144,8 +144,12 @@ impl LanguageConfiguration { &highlights_query, &injections_query, &locals_query, - ) - .unwrap(); // TODO: no unwrap + ); + + let config = match config { + Ok(config) => config, + Err(err) => panic!("{}", err), + }; // TODO: avoid panic config.configure(scopes); Some(Arc::new(config)) } diff --git a/runtime/queries/go/highlights.scm b/runtime/queries/go/highlights.scm index 6e5d65a07..3129c4b2b 100644 --- a/runtime/queries/go/highlights.scm +++ b/runtime/queries/go/highlights.scm @@ -21,14 +21,14 @@ (const_spec name: (identifier) @constant) +(parameter_declaration (identifier) @variable.parameter) +(variadic_parameter_declaration (identifier) @variable.parameter) + (type_identifier) @type (field_identifier) @property (identifier) @variable (package_identifier) @variable -(parameter_declaration (identifier) @variable.parameter) -(variadic_parameter_declaration (identifier) @variable.parameter) - ; Operators diff --git a/runtime/queries/go/locals.scm b/runtime/queries/go/locals.scm new file mode 100644 index 000000000..d240e2b78 --- /dev/null +++ b/runtime/queries/go/locals.scm @@ -0,0 +1,30 @@ +; Scopes + +(block) @local.scope + +; Definitions + +(parameter_declaration (identifier) @local.definition) +(variadic_parameter_declaration (identifier) @local.definition) + +(short_var_declaration + left: (expression_list + (identifier) @local.definition)) + +(var_spec + name: (identifier) @local.definition) + +(for_statement + (range_clause + left: (expression_list + (identifier) @local.definition))) + +(const_declaration + (const_spec + name: (identifier) @local.definition)) + +; References + +(identifier) @local.reference +(field_identifier) @local.reference + diff --git a/runtime/queries/rust/locals.scm b/runtime/queries/rust/locals.scm new file mode 100644 index 000000000..6428f9b4a --- /dev/null +++ b/runtime/queries/rust/locals.scm @@ -0,0 +1,17 @@ +; Scopes + +(block) @local.scope + +; Definitions + +(parameter + (identifier) @local.definition) + +(let_declaration + pattern: (identifier) @local.definition) + +(closure_parameters (identifier)) @local.definition + +; References +(identifier) @local.reference + diff --git a/theme.toml b/theme.toml index 3166b2d62..867a0d2cf 100644 --- a/theme.toml +++ b/theme.toml @@ -9,7 +9,7 @@ special = "honey" property = "white" variable = "lavender" # variable = "almond" # TODO: metavariables only -"variable.parameter" = "lavender" +"variable.parameter" = { fg = "lavender", modifiers = ["underlined"] } "variable.builtin" = "mint" type = "white" "type.builtin" = "white" # TODO: distinguish?