From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Danny Freeman Newsgroups: gmane.emacs.devel Subject: Re: Update on tree-sitter structure navigation Date: Wed, 06 Sep 2023 23:18:42 -0400 Message-ID: <87y1hizl9b.fsf@dfreeman.email> References: <5E7F2A94-4377-45C0-8541-7F59F3B54BA1@gmail.com> <8a5b3b3e-f091-3f38-09d4-c4e26bec97f9@yandex.ru> <87o7igc80a.fsf@dfreeman.email> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39718"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Yuan Fu , emacs-devel , Theodor Thornhill , Jostein =?utf-8?Q?Kj=C3=B8nigsen?= , Randy Taylor , Wilhelm Kirschbaum , Perry Smith To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Sep 07 06:00:33 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 1qe6C1-000A9j-Hk for ged-emacs-devel@m.gmane-mx.org; Thu, 07 Sep 2023 06:00:33 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qe6BG-000128-9J; Wed, 06 Sep 2023 23:59:46 -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 1qe6BE-00011r-Ac for emacs-devel@gnu.org; Wed, 06 Sep 2023 23:59:44 -0400 Original-Received: from out-212.mta1.migadu.com ([2001:41d0:203:375::d4]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qe6BA-00025b-6M for emacs-devel@gnu.org; Wed, 06 Sep 2023 23:59:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dfreeman.email; s=key1; t=1694059173; 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: in-reply-to:in-reply-to:references:references; bh=DD5Y9VbA6y6GI5AiEhHbd4kraRHJS87VX4ivVjwwgpo=; b=pqexaZRLjzLLdE38daGZ69ETsDJskOEqDU6atUEniwlzt2sz+Mfyz2U9yIqz0Ptr5v8UG3 17XnBi0hWELC2lrEaqZsQstPzlzcw668yVMJD8z5caNcpmQ+1SELn4gK/KTz8MyKpurq4u lm6tRjibEz8sKALp1Gce0cUA5Vkfv7E= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:203:375::d4; envelope-from=danny@dfreeman.email; helo=out-212.mta1.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_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:310229 Archived-At: Dmitry Gutov writes: >> clojure-ts-mode keeps a URL for the parser, but doesn't do anything >> about the git revision. It easily could but I don't feel the need (yet) >> since I am also a maintainer of the clojure grammar and know when we're >> about to break grammar consumers. > > Sure, that's easy enough to do when the package is only in ELPA: upgrade the grammar, upgrade the > package, all in lockstep. Yeah, soon after I sent that email I realized there is no reason for me not to specify a version for the grammar so I pushed a change doing just that. > Unless nixos or other distros are going to start distributing it as well, and you'll need to care > about having the recent clojure-ts-mode being loaded with old versions of the grammar. Luckily the grammar has not changed since my package was released. But you are right it will eventually become an issue. >> With the way Emacs can load a grammar provided by the user's >> distribution, keeping information about the version of the grammar in >> the major mode doesn't help all that much. Even if we did it we have no >> idea what version might be have been built used the user's >> .emacs.d/tree-sitter folder. That would require something like putting a >> version number in the file name, or maybe applying a patch to the >> grammar's C source that allowed us to get a version, SHA, something at >> runtime. > > Well, it would at least allow the user to rebuild the grammar to the version best known to work. > Also, perhaps if the mode tracks the changes in the hash over time, it could see whether the grammar > needs to be rebuilt. Finally, treesit-install-language-grammar could track which revision was last > compiled. > > So there is *something* we could do for the users who upgrade their grammars from Git. > > Grammars distributed from distros are more of a problem, because it's not always a good idea to > abort with "wrong version". But perhaps we could do that and recommend installing from Git in such > cases anyway? In some cases, distros might place the grammars in a strange location made accessible on `treesit-extra-load-path`, which takes precedence over the grammars that are installed from git in the user's Emacs directory. This is what nix does, but is probably an outlier. I would guess more conventional distributions might just make them accessible where dynamic libraries are normally located and the grammars installed from git would take precedence. > Another problem is that grammars don't have good versioning, and even if they did, we'd have to > sometimes update the "upper bound" (we'd need coarse ranges, right? rather that one fixed version > requirement) more frequently than Emacs is released. Less of a problem for modes in ELPA, though. Yeah I think ranges would be right. It would be good to say, we tested this with versions N through M, anything else might not work. There would still need to be some checks and patches like what exists in js-ts-mode now. But that seems unavoidable, but could be cleaner if we had a good way to ID grammars. Not sure about how we'd keep up with grammars. Maybe we just can't and would need to have users install older versions. That seems okay? >> I'm not so sure we can have a great way to do this without a change to >> the tree-sitter libraries. I would love to see some kind of increasing >> version number generated in the grammar's C source that we could then >> access. It could be used to make decisions about what queries to use, or >> to warn the user they need to use a different grammar (maybe offering to >> install a compatible version). > > Yes, that would be an improvement, worth being up on the issue tracker maybe. Yeah, I think this is a good move. I opened up one here https://github.com/tree-sitter/tree-sitter/issues/2611 Of course, anyone feel free to chime in. Thank you, -- Danny Freeman