From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Augustin_Ch=C3=A9neau_=28BTuin=29?= Newsgroups: gmane.emacs.devel Subject: Re: Questions about tree-sitter Date: Wed, 13 Sep 2023 14:43:09 +0200 Message-ID: <9fef551c-3a8d-4df8-ac1d-a9884b73da5d@mailo.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> <2E2323FB-1A32-48B6-992E-66F474427199@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24209"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: emacs-devel To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Sep 13 14:44:00 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 1qgPDs-00065q-2i for ged-emacs-devel@m.gmane-mx.org; Wed, 13 Sep 2023 14:44:00 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgPDC-0001r0-Eg; Wed, 13 Sep 2023 08:43:18 -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 1qgPDA-0001ql-Mp for emacs-devel@gnu.org; Wed, 13 Sep 2023 08:43:16 -0400 Original-Received: from msg-4.mailo.com ([213.182.54.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgPD7-0008Bi-Cm for emacs-devel@gnu.org; Wed, 13 Sep 2023 08:43:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1694608989; bh=OD+2WqnKMPsU525RZ3vuv2ZyZXT2ukNsuRDOsJkQ42o=; h=X-EA-Auth:Message-ID:Date:MIME-Version:Subject:To:Cc:References: From:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=a+ZltGc+hSQKik3L/+mBc1CJXC61SnLXoWeGyJJen/YO+ArRcNiajrupKyHjNStOQ r82OYBUgUlH9YEynOIwFr9AijRgJR7TaoeZSRolndRanT1IdbiC8DYECZ6Bk/LNbh3 Fdts0pXSpOAtUS3Zw2mryo7IFhxEYnkmz3zutzIM= Original-Received: by b221-4.in.mailobj.net [192.168.90.24] with ESMTP via ip-20.mailobj.net [213.182.54.20] Wed, 13 Sep 2023 14:43:09 +0200 (CEST) X-EA-Auth: h3Lt00sHVqYG9BYbFKtVKtqhxVOj04BB7i1K6yfB4SJ4W/YPajNzmWEhw92rXpAeFhmylCE9ZmtYvObkPy5uVsQv2c+iL8n1 Content-Language: fr, en-US In-Reply-To: <2E2323FB-1A32-48B6-992E-66F474427199@gmail.com> Received-SPF: pass client-ip=213.182.54.15; envelope-from=btuin@mailo.com; helo=msg-4.mailo.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_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:310545 Archived-At: Le 12/09/2023 à 02:22, Yuan Fu a écrit : > > >> On Sep 9, 2023, at 9:39 AM, Augustin Chéneau (BTuin) wrote: >> >> Le 08/09/2023 à 18:43, Yuan Fu a écrit : >>>> On Sep 8, 2023, at 4:53 AM, Augustin Chéneau (BTuin) wrote: >>>> >>>> Le 06/09/2023 à 06:07, Yuan Fu a écrit : >>>>> 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’s vital that you define treesit-language-at-point-function for a multi-language mode. >>>>> Yuan >>>> >>>> Thanks a lot! >>>> >>>> I did some tests and it's working pretty well. >>> Awesome! >> >> >> 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. >> >> I attached an example Bison file if needed. > > Thanks. I was able to reproduce this, but then can’t. I’ll keep looking into this, if you found out something new please let me know. > It may be unrelated, but I have this popping in *Messages* sometimes: Error during redisplay: (jit-lock-function 1410) signaled (treesit-load-language-error not-found ("libtree-sitter-nil" "libtree-sitter-nil.0" "libtree-sitter-nil.0.0" "libtree-sitter-nil.so" "libtree-sitter-nil.so.0" "libtree-sitter-nil.so.0.0") "No such file or directory") >> >>>> I have a few issues though: >>>> >>>> - 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’s parser (bison) and see if point is in an undelimited_code_block, and return c or bison accordingly. I’m highlight this in the docstring, thanks. >> >> 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! Thanks!