on master help sign in
Fix Golang textobject queries (#2153)

* log textobject query construction errors The current behavior is that invalid queries are discarded silently which makes it difficult to debug invalid textobjects (either invalid syntax or an update may have come through that changed the valid set of nodes). * fix golang textobject query `method_spec_list` used to be a named node but was removed (I think for Helix, it was when updated to pull in the support for generics). Instead of a named node for the list of method specs we have a bunch of `method_spec` children nodes now. We can match on the set of them with a `+` wildcard. Example go for this query: type Shape interface { area() float64 perimeter() float64 } Which is parsed as: (source_file (type_declaration (type_spec name: (type_identifier) type: (interface_type (method_spec name: (field_identifier) parameters: (parameter_list) result: (type_identifier)) (method_spec name: (field_identifier) parameters: (parameter_list) result: (type_identifier))))))

commit4e877de54d4ad79cf5dafca6642f63ee1a8d5ae4 authorMichael Davis <mcarsondavis@gmail.com> dateMon 18 Apr 2022, 10:14 (5 years ago) parent449d1df
2 files changed+4−2
helix-core/src/syntax.rs+3−1 runtime/queries/go/textobjects.scm+1−1
helix-core/src/syntax.rs+3−1
@@ -413,7 +413,9 @@ impl LanguageConfiguration {
413413 let lang_name = self.language_id.to_ascii_lowercase();
414414 let query_text = read_query(&lang_name, "textobjects.scm");
415415 let lang = self.highlight_config.get()?.as_ref()?.language;
416− let query = Query::new(lang, &query_text).ok()?;
416+ let query = Query::new(lang, &query_text)
417+ .map_err(|e| log::error!("Failed to parse textobjects.scm queries: {}", e))
418+ .ok()?;
417419 Some(TextObjectQuery { query })
418420 })
419421 .as_ref()
runtime/queries/go/textobjects.scm+1−1
@@ -12,7 +12,7 @@
1212 (type_spec (type_identifier) (struct_type (field_declaration_list (_)?) @class.inside))) @class.around
1313
1414(type_declaration
15− (type_spec (type_identifier) (interface_type (method_spec_list (_)?) @class.inside))) @class.around
15+ (type_spec (type_identifier) (interface_type (method_spec)+ @class.inside))) @class.around
1616
1717(parameter_list
1818 (_) @parameter.inside)