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.devel Subject: Re: Questions about tree-sitter Date: Mon, 11 Sep 2023 17:22:06 -0700 Message-ID: <2E2323FB-1A32-48B6-992E-66F474427199@gmail.com> References: <12fe5895-7d34-4f3e-b1cf-aa133b718c24@mailo.com> <52f09345-85c8-4049-b12d-bf8b84b08f75@mailo.com> <2B46C452-DC8B-4BD0-A64B-8773235C1FA8@gmail.com> <3b3f90e8-a318-4b63-915e-6477701de897@mailo.com> <1F227B69-6195-4115-A7B6-BD2F7EA08E1F@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) 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="19011"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel To: =?utf-8?B?IkF1Z3VzdGluIENow6luZWF1IChCVHVpbiki?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Sep 12 02:23:20 2023 Return-path: Envelope-to: ged-emacs-devel@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 1qfrBX-0004jx-GC for ged-emacs-devel@m.gmane-mx.org; Tue, 12 Sep 2023 02:23:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qfrAd-0002CM-BL; Mon, 11 Sep 2023 20:22:23 -0400 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 1qfrAb-0002Bu-8A for emacs-devel@gnu.org; Mon, 11 Sep 2023 20:22:21 -0400 Original-Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qfrAZ-0001XO-0q for emacs-devel@gnu.org; Mon, 11 Sep 2023 20:22:20 -0400 Original-Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-6c09d760cb9so3486095a34.2 for ; Mon, 11 Sep 2023 17:22:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694478137; x=1695082937; darn=gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=K+mF1CFjcaUykXTScWjeAFG7KRhDoiD/uLYh0x2jDrk=; b=PYOSKfdD53kF/ZSkGr87QfRhfjX3FZDwKXwToMn8EddxeeIewH6mw96TrX9+mX06tj sxlLgBE8ZUrRgNPJJ1zDJHbBz0I6esTdFq6Rd0rHZtExrkO5z1AEgTLZJafW4AhNwK1e eM8fi1WX4qkTJ/pxaSZlnnWj+jp4w69PUG0HIhQQg/8bMt4cFDEF7h2c/ULVZkeKOhvO wEjFXYg9iJnGbs8iZ+eLxqIZXXeGRJnlfHqyJh78Ab9R/xoUiyCvaTc8BA20Y+G7Ewub ZtLQ1m0NxeXm8HkCFgxvwoIsI0ZAZrcNIW7zvsIXizsLsdwGUBo0WprllhFUdadBdvny mTKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694478137; x=1695082937; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K+mF1CFjcaUykXTScWjeAFG7KRhDoiD/uLYh0x2jDrk=; b=nbL1/l3RPDbd4rIPohnbULvmAqXQ4krq6XbGHl4/zyWHQGouq3m+dJ61UUIaW5E6QJ rpH8flSSiyI5YMVPLX/Q29LQvmUAJ9qcTE9lrObOtpA8GcRSPXtpaBhVhXRjnALb1jfB kUBdVCR95QUsrEtRR/mgUSQV3qoE7j2B9MrTvRsB6XS+Q9iex/qfi2aanYTGvI5V8Nlh 2PvB/BT1mTSbGjT2tY0va2mVox/vpjfgwHso98D+6qgT3miL+9SLRU86Ab6mXSrcwEZ+ p128CAOkFNV3yCO0PAFuc123x8g8d746m9tXtl/0tlA9zuczQGSWBKFdVsv+ZX+0kSTp t+Qg== X-Gm-Message-State: AOJu0YwzZjjRHsO/Gd8+4//oUukTnEHf/H/es9rp+otRJ0IxN1YUmAPH vDsIr6xVRIk2PXKjGmIy1gEXTF3rIb8= X-Google-Smtp-Source: AGHT+IFHQo5lBHz7vSSVnYquifjccYr8IvQ01t74sG6QZHuSv9mO2etM/mD+RUvNNhMXJ3X0Vla3JA== X-Received: by 2002:a05:6830:1e96:b0:6b9:1af7:48c5 with SMTP id n22-20020a0568301e9600b006b91af748c5mr10999111otr.9.1694478137701; Mon, 11 Sep 2023 17:22:17 -0700 (PDT) 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 j13-20020aa78d0d000000b00660d80087a8sm6100287pfe.187.2023.09.11.17.22.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Sep 2023 17:22:17 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3731.700.6) Received-SPF: pass client-ip=2607:f8b0:4864:20::32b; envelope-from=casouri@gmail.com; helo=mail-ot1-x32b.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:310489 Archived-At: > On Sep 9, 2023, at 9:39 AM, Augustin Ch=C3=A9neau (BTuin) = wrote: >=20 > Le 08/09/2023 =C3=A0 18:43, Yuan Fu a =C3=A9crit : >>> On Sep 8, 2023, at 4:53 AM, Augustin Ch=C3=A9neau (BTuin) = wrote: >>>=20 >>> Le 06/09/2023 =C3=A0 06:07, Yuan Fu a =C3=A9crit : >>>> I added local parser support to master. If everything goes right, = you just need to add a :local t flag in treesit-range-rules. Check out = the modified bision-ts-mode.el that I hacked up for an example. BTW, = it=E2=80=99s vital that you define treesit-language-at-point-function = for a multi-language mode. >>>> Yuan >>>=20 >>> Thanks a lot! >>>=20 >>> I did some tests and it's working pretty well. >> Awesome! >=20 >=20 > It seems I spoke a bit too soon :( > When I edit the buffer, sometimes there is an offset between the text = and the nodes after modifying the buffer, or the syntax highlighting = breaks in C code. >=20 > I attached an example Bison file if needed. Thanks. I was able to reproduce this, but then can=E2=80=99t. I=E2=80=99ll= keep looking into this, if you found out something new please let me = know. >=20 >>> I have a few issues though: >>>=20 >>> - I first defined `treesit-language-at-point-function` using >>> `treesit-node-at`. However, `treesit-node-at` itself uses >>> `treesit-language-at-point-function` which causes an infinite = recursion. >>> So I instead used `treesit-local-parsers-at` to check if a local = parser is used. Is it a good solution? >> No no, you should use the host langauge=E2=80=99s parser (bison) and = see if point is in an undelimited_code_block, and return c or bison = accordingly. I=E2=80=99m highlight this in the docstring, thanks. >=20 > So I need to call `treesit-node-at` with `'bison` as the value for = PARSER-OR-LANG to see in which node I am? > Then I think there is a problem with `treesit-node-at`, because it = always call `treesit-language-at` even if PARSER-OR-LANG is provided. > I propose a fix in the attached patch. You are right. I applied a similar fix. It should be good now. Thanks! Yuan=