Skip to content

Commit

Permalink
Fix Golang textobject queries (#2153)
Browse files Browse the repository at this point in the history
* 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))))))
  • Loading branch information
the-mikedavis authored Apr 18, 2022
1 parent 449d1df commit 4e877de
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion helix-core/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@ impl LanguageConfiguration {
let lang_name = self.language_id.to_ascii_lowercase();
let query_text = read_query(&lang_name, "textobjects.scm");
let lang = self.highlight_config.get()?.as_ref()?.language;
let query = Query::new(lang, &query_text).ok()?;
let query = Query::new(lang, &query_text)
.map_err(|e| log::error!("Failed to parse textobjects.scm queries: {}", e))
.ok()?;
Some(TextObjectQuery { query })
})
.as_ref()
Expand Down
2 changes: 1 addition & 1 deletion runtime/queries/go/textobjects.scm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
(type_spec (type_identifier) (struct_type (field_declaration_list (_)?) @class.inside))) @class.around

(type_declaration
(type_spec (type_identifier) (interface_type (method_spec_list (_)?) @class.inside))) @class.around
(type_spec (type_identifier) (interface_type (method_spec)+ @class.inside))) @class.around

(parameter_list
(_) @parameter.inside)
Expand Down

0 comments on commit 4e877de

Please sign in to comment.