bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#58711: Treesit hangs when calling treesit-search-forward


From: Wilhelm Hugo Kirschbaum
Subject: bug#58711: Treesit hangs when calling treesit-search-forward
Date: Mon, 24 Oct 2022 19:06:58 +0200

On Monday, 24 October 2022 01:20:01 SAST Yuan Fu wrote:
> > On Oct 22, 2022, at 11:42 PM, Yuan Fu <casouri@gmail.com> wrote:
> >> On Oct 22, 2022, at 2:53 AM, Wilhelm Kirschbaum <wkirschbaum@gmail.com>
> >> wrote:
> >> 
> >> I am attempting to implement treesit for the current elixir-mode using
> >> the branch feature/trees-sitter. For implementing
> >> beginning-of-defun-function using treesit I am running into an issue
> >> where the Emacs will hang indefinitely. Using (setq-local
> >> treesit-defun-type-regexp (rx (or "call"))) yields the same result.
> >> 
> >> For the following node-at-point output
> >> 
> >> (do_block (call target: (identifier)))
> >> 
> >> with Elixir code
> >> 
> >> # foo.ex
> >> defmodule Foo do
> >> 
> >>  <<point/cursor here>>def bar(), do: "bar"
> >> 
> >> end
> >> 
> >> When I call `(treesit-search-forward-goto (rx (or "call")) 'start nil t)`
> >> the function `treesit-search-forward` seems to get stuck.
> >> 
> >> Elixir does not strictly have a begin function, but can be determined as
> >> one of the following: ; * modules and protocols
> >> (call
> >> 
> >>  target: (identifier) @ignore
> >>  (arguments (alias) @name)
> >>  (#match? @ignore "^(defmodule|defprotocol)$")) @definition.module
> >> 
> >> ; * functions/macros
> >> (call
> >> 
> >>  target: (identifier) @ignore
> >>  (arguments
> >>  
> >>    [
> >>    
> >>      ; zero-arity functions with no parentheses
> >>      (identifier) @name
> >>      ; regular function clause
> >>      (call target: (identifier) @name)
> >>      ; 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|defn
> >>  p)$")) @definition.function>> 
> >> The elixir tree sitter implementation is here:
> >> https://github.com/elixir-lang/tree-sitter-elixir
> >> 
> >> I lack the knowledge to further debug this or find a clean workaround,
> >> but I'm almost sure that treesit-search-forward should never hang.> 
> > Thanks for reporting this. The way treesit-search-forward-goto works makes
> > it very to have infinite loops. I revised the way it traverses the tree
> > and now it should be impossible to fall into infinite loops.
> > 
> > Yuan
> 
> Just a heads up: I changed the function signature of
> treesit-search-forward-goto in the latest commit.
> 
> Yuan

Thanks, I would need some time to have a proper look. The reporting issue 
seems to have been fixed. There are some complications to identify the 
appropriate node for defun in elixir as a "call" node might, or might not be 
defun, depending on its child identifier ( i currently have to do a query on 
cycling up the parent ), but will try the respond in more detail in another 
thread.  








reply via email to

[Prev in Thread] Current Thread [Next in Thread]