From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Danny Freeman via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#60127: treesit-end-of-defun: possible bug with clojure grammar Date: Fri, 16 Dec 2022 13:12:09 -0500 Message-ID: <87sfhf5ghj.fsf@dfreeman.email> Reply-To: Danny Freeman Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4296"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Yuan Fu To: 60127@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 16 20:09:31 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p6G5K-0000wz-A3 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 16 Dec 2022 20:09:30 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p6Fpo-0000Kz-KG; Fri, 16 Dec 2022 13:53:28 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p6Fpc-0000HV-0i for bug-gnu-emacs@gnu.org; Fri, 16 Dec 2022 13:53:20 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p6FpO-0003Du-5w for bug-gnu-emacs@gnu.org; Fri, 16 Dec 2022 13:53:15 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p6FpO-0005TI-1v for bug-gnu-emacs@gnu.org; Fri, 16 Dec 2022 13:53:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Danny Freeman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 16 Dec 2022 18:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 60127 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.167121676721019 (code B ref -1); Fri, 16 Dec 2022 18:53:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 16 Dec 2022 18:52:47 +0000 Original-Received: from localhost ([127.0.0.1]:50972 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p6Fp9-0005Sx-Ax for submit@debbugs.gnu.org; Fri, 16 Dec 2022 13:52:47 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:33552) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p6Fp7-0005Sr-HX for submit@debbugs.gnu.org; Fri, 16 Dec 2022 13:52:46 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p6Fp5-0008VB-Tg for bug-gnu-emacs@gnu.org; Fri, 16 Dec 2022 13:52:45 -0500 Original-Received: from out2.migadu.com ([188.165.223.204]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p6Fp2-00038S-G3 for bug-gnu-emacs@gnu.org; Fri, 16 Dec 2022 13:52:43 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dfreeman.email; s=key1; t=1671216718; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=q00+QnbtrpycSvThs451G9uGUUG9+aRS1x0DDK1N+BQ=; b=I/X8pI6CEKX3Ud9nVTCGhic/FScLZ9xC5061bKM4xvJ412OQBr4DfhPGbFthlNjbT/8IQE Hi4dcFehWaEoFJf403/0F70jSKq40xEmQ76yabXBGxNEtUsopI8v0YWfnJAjFIKwHxrJYT 31veWAgm3ygASptGKMtW76uAJKi/SQY= X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=188.165.223.204; envelope-from=Danny@dfreeman.email; helo=out2.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:251234 Archived-At: Hello, I have been running into what I believe is a bug with treesit-end-of-defun while developing clojure-ts-mode. There are some positions in clojure buffers where treesit-end-of-defun will jump to the end of the buffer. Steps to reproduce: Checkout the emacs-29 branch. I have built mine with commit b01d0246d71a7a3fd92b2864a3c0c0bc9367ee0b and tree-sitter version 0.20.7 Clone my clojure-mode fork: https://github.com/dannyfreeman/clojure-mode check out the `end-of-defun-bug` branch (master works too, but I added a helpful debug message in this branch) Clone tree-sitter-module repo: https://github.com/casouri/tree-sitter-module Apply the patch `tree-sitter-module-clojure-support.patch` located in clojure-mode repo to the casouri/tree-sitter-module repo. Build the treesitter parser for clojure with $ ./build clojure Start emacs $ emacs -q Evaluate the following, replacing the paths with what is relevant to your system ``` (progn (setq treesit-extra-load-path '("~/path/to/tree-sitter-module/dist")) (add-to-list 'load-path "~/path/to/clojure-mode/") (find-file "~/path/to/clojure-mode/clojure-ts-mode.el") (eval-buffer) (find-file "~/path/to/clojure-mode/test_end_of_defun.clj")) ``` Once you have opened test_end_of_defun.clj you can see the problem by pressing M-< C-M-e C-M-e You should see the cursor move from ``` |(def w 1) (def x 2) (def y 3) (def skip-to-here? 4) ``` to ``` (def w 1) | (def x 2) (def y 3) (def skip-to-here? 4) ``` then it unexpectedly jumps to the end of the buffer ``` (def w 1) (def x 2) (def y 3) (def skip-to-here? 4) | ``` The message buffer shows that when the point is between the forms ``` (def w 1) | (def x 2) ``` that `treesit-end-of-defun` thinks the current node is `(def skip-to-here? 4)`, which does not seem right. When the cursor is at other points in this buffer, this problem doesn't seem to occur. For instance, between the (def x 2) and (def y 3) forms, this doesn't happen. I can also see this happening in the `test.clj` file of the clojure-mode repo in a different spot but there is a lot more going on in that file. (hit C-M-e in it until the problem occurs if you are curious). I have the following vars relevant vars set in clojure-ts-mode. Different combinations of them yield the same results. ``` (setq-local treesit-defun-prefer-top-level t treesit-defun-tactic 'top-level treesit-defun-type-regexp (cons (rx (or "list_lit" "vec_lit" "map_lit")) (lambda (node) (message "Node: %s" (treesit-node-text node t)) t))) ``` The clojure code in question produces an error free parse tree. I can see it with `treesit-explore-mode` and by running the file through `tree-sitter parse`, which gives the following parse tree: ``` (source [0, 0] - [7, 0] (list_lit [0, 0] - [0, 9] value: (sym_lit [0, 1] - [0, 4] name: (sym_name [0, 1] - [0, 4])) value: (sym_lit [0, 5] - [0, 6] name: (sym_name [0, 5] - [0, 6])) value: (num_lit [0, 7] - [0, 8])) (list_lit [2, 0] - [2, 9] value: (sym_lit [2, 1] - [2, 4] name: (sym_name [2, 1] - [2, 4])) value: (sym_lit [2, 5] - [2, 6] name: (sym_name [2, 5] - [2, 6])) value: (num_lit [2, 7] - [2, 8])) (list_lit [4, 0] - [4, 9] value: (sym_lit [4, 1] - [4, 4] name: (sym_name [4, 1] - [4, 4])) value: (sym_lit [4, 5] - [4, 6] name: (sym_name [4, 5] - [4, 6])) value: (num_lit [4, 7] - [4, 8])) (list_lit [6, 0] - [6, 21] value: (sym_lit [6, 1] - [6, 4] name: (sym_name [6, 1] - [6, 4])) value: (sym_lit [6, 5] - [6, 18] name: (sym_name [6, 5] - [6, 18])) value: (num_lit [6, 19] - [6, 20]))) ``` Any help or advice here is appreciated. Thank you, -- Danny Freeman