From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#60127: treesit-end-of-defun: possible bug with clojure grammar Date: Fri, 16 Dec 2022 15:20:43 -0800 Message-ID: <42357D6B-C983-4B1F-8857-8C990E848750@gmail.com> References: <87sfhf5ghj.fsf@dfreeman.email> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25855"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 60127@debbugs.gnu.org To: Danny@dfreeman.email Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 17 00:21:20 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 1p6K12-0006Uq-4O for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 17 Dec 2022 00:21:20 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p6K0m-0003cD-Do; Fri, 16 Dec 2022 18:21:04 -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 1p6K0k-0003ap-Ta for bug-gnu-emacs@gnu.org; Fri, 16 Dec 2022 18:21:02 -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 1p6K0k-0005JU-LR for bug-gnu-emacs@gnu.org; Fri, 16 Dec 2022 18:21:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p6K0k-000897-Cd for bug-gnu-emacs@gnu.org; Fri, 16 Dec 2022 18:21:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <87sfhf5ghj.fsf@dfreeman.email> Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 16 Dec 2022 23:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60127 X-GNU-PR-Package: emacs Original-Received: via spool by 60127-submit@debbugs.gnu.org id=B60127.167123285631286 (code B ref 60127); Fri, 16 Dec 2022 23:21:02 +0000 Original-Received: (at 60127) by debbugs.gnu.org; 16 Dec 2022 23:20:56 +0000 Original-Received: from localhost ([127.0.0.1]:52116 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p6K0d-00088Y-Hj for submit@debbugs.gnu.org; Fri, 16 Dec 2022 18:20:55 -0500 Original-Received: from mail-pl1-f182.google.com ([209.85.214.182]:40740) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p6K0b-00088S-9v for 60127@debbugs.gnu.org; Fri, 16 Dec 2022 18:20:53 -0500 Original-Received: by mail-pl1-f182.google.com with SMTP id a9so3751289pld.7 for <60127@debbugs.gnu.org>; Fri, 16 Dec 2022 15:20:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=u98LpS0OOuWq7DdNWuW7V5Va56E8TYlbca8kA9ZTLFY=; b=iQ89sWEz11xBPLjwccJ9e7kjtwyARIJJ5kLc2d3ajts5Gr1Rf5FWSfEAnvGEB7wc8W Kg5nYDzjiiQjWzqu9rdNGsjABfPBrLeCws5GoNqLIUgQM9RW61Fl7uBm4sReLK0zCDOA cf8i8oQgPdyNzQ+zvwLJDhXtg3BIBamBluEZvVMsNQZbC1c7tjeJJxucL+xzgRcAE1xv hriWhEx5QeR+B/M18v2A4Hosrx7h5YWeuD/STNhPTS3OQFmiNL9E8mk3Wtlqmhb8XHn8 0ztt9Nc77psg6MPynrSwpLu7GOXkCBNxrCNGNbBrOJzInKaYG0Lv8pco7VZ1fTYFoi5f 1SWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u98LpS0OOuWq7DdNWuW7V5Va56E8TYlbca8kA9ZTLFY=; b=obMOsiUD4qKKEOF+boBhPZZiQEKG1vJz42unz5nA7c2Ic4sig3Bl79sV+/LkRLl2kO u/SF6lg0HFoQ7Mu9qsV8Cet76Kvps56vfHFy2azYBsfArFmvXrhAYeML5bYdYXDqwuiZ QzSwqBc63Bp4fob2mmZC5MSGQ/p/8c/kmAkMM5MXIrbDHz+Y0UbDAc58gusXvbfbrbmG ltAcA3LgvEHaVnMC1kIILM+qx9kHQkZqGxVg3yhQ1c5H7Y+98L9Ufle/keMJQlxt/0tv CUyvKZc3auMfzXibVcx8dR84gwfMNws+4p19q6a72vzVNUOzJzvurUy55kDXIFw6jncm dRlw== X-Gm-Message-State: ANoB5pnLyzmrEMcv7RqJlHOMMJUD6mdn93fqZtEkyXHvKJbjBbeNm5hM kPhnp7ygMLxXGeYtviaLr5Y5nWlofAeYTw== X-Google-Smtp-Source: AA0mqf6sDTlag2FzfQhAoKp9uZyXrTm+GQnYQkg0nJpk8PEiI2uvXAV4g11WB41Dq1h0hpe1WOwXkQ== X-Received: by 2002:a17:902:f10d:b0:18f:a447:2254 with SMTP id e13-20020a170902f10d00b0018fa4472254mr20514133plb.64.1671232847262; Fri, 16 Dec 2022 15:20:47 -0800 (PST) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id z6-20020a1709027e8600b00172973d3cd9sm2151472pla.55.2022.12.16.15.20.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Dec 2022 15:20:46 -0800 (PST) X-Mailer: Apple Mail (2.3696.120.41.1.1) 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:251245 Archived-At: Danny Freeman writes: > 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, Thank you very much for this detailed report! This seems to be some problem with either tree-sitter or tree-sitter-clojure, where treesit-node-first-child-for-pos gives wrong result. We=E2=80=99ve had = similar problem with bash before[1]. At this point there aren=E2=80=99t much we can do in Emacs. If I find = some time I=E2=80=99ll make a reproduce recipe and submit an issue on = tree-sitter-clojure. [1] https://github.com/tree-sitter/tree-sitter-bash/issues/139 Yuan