Help adding tree-sitter symbols

I’m trying to add symbols to the nova-elixir-ls extension which uses tree-sitter. The symbols.scm file in the extension looks like it came directly from the project that adds Elixir support to GitHub so I assume it’s correct.

I’ve added <symbols /> in the <tree-sitter> section of Elixir.xml and now I’m trying to add something like (#set! role function) so that the symbols will show up in the Symbols sidebar. Here’s example change that has no effect:

Original:

; * functions/macros
(call
  target: (identifier) @ignore
  (arguments
    [
      ; zero-arity functions with no parentheses
      (identifier) @name
      ; regular function clause
      (call target: (identifier) @name @displayname)
      ; function clause with a guard clause
      (binary_operator
        left: (call target: (identifier) @name)
        operator: "when")
    ])
  (#match? @ignore "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @definition.function

Changed:

; * functions/macros
(call
  target: (identifier) @ignore
  (arguments
    [
      ; zero-arity functions with no parentheses
      (identifier) @name
      ; regular function clause
      (call target: (identifier) @name @displayname)
      ; function clause with a guard clause
      (binary_operator
        left: (call target: (identifier) @name)
        operator: "when")
    ])
  (#match? @ignore "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")
  (#set! role function)) @definition.function

Any ideas? Debugging hints?

Nova’s symbol queries are not necessarily compatible with those used with GitHub, so files taken from a repository targeting it won’t be guaranteed to work with our support.

Nova requires three things be set for any symbol query:

  • a name (which you’re doing with @name)
  • a role (which you’re setting with function)
  • a region of the document to encompass, using either @subtree or a combination of the @start- and @end-type captures.

I believe the issue may be that you are not setting a region of text to symbolicate. Unlike GitHub, which only pulls out symbol names, we pull out the entire symbol region to calculate scope depths for building a symbol tree.

See the documentation here on setting a region: Tree-sitter - Nova.

That solved it — thanks for the quick response!