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: Tree-sitter api Date: Fri, 22 Apr 2022 00:08:37 -0700 Message-ID: <91E89EA1-C3DC-4B78-8549-B9DEC94F6E87@gmail.com> References: <83ilvbpsvl.fsf@gnu.org> <4A6F417A-EF74-40B6-9517-6C0947AB87A6@gmail.com> <83wnjmiork.fsf@gnu.org> <6D1CD758-2C6F-4843-9739-F2A5D5591648@gmail.com> <67183EAB-5D98-4211-B71B-4618D6266A15@gmail.com> <83lews90ft.fsf@gnu.org> <8D3019A6-83EE-42AB-ADFA-7DA6EBB179B3@gmail.com> <83r16h5npi.fsf@gnu.org> <83v8vs4rd9.fsf@gnu.org> <983C9314-B31C-4785-B075-892CDD883DA2@gmail.com> <877d858fj5.fsf@gmail.com> <5D490FCF-7727-44EE-A153-A95C5F572FC4@gmail.com> <87y1zzseaa.fsf@thornhill.no> <838rrzrnp2.fsf@gnu.org> <871qxq8y5y.fsf@gnus.org> <87wnfi1vtm.fsf@thornhill.no> <3560D8FB-9D85-4A04-B6CE-811A6D793B59@gmail.com> <877d7hg1dh.fsf@thornhill.no> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.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="26432"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Lars Ingebrigtsen , Eli Zaretskii , emacs-devel@gnu.org To: Theodor Thornhill Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Apr 22 09:11:50 2022 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 1nhnSI-0006k2-8g for ged-emacs-devel@m.gmane-mx.org; Fri, 22 Apr 2022 09:11:50 +0200 Original-Received: from localhost ([::1]:46068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhnSG-0004OV-OB for ged-emacs-devel@m.gmane-mx.org; Fri, 22 Apr 2022 03:11:48 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhnPG-0002kd-NN for emacs-devel@gnu.org; Fri, 22 Apr 2022 03:08:48 -0400 Original-Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:34437) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhnPE-00017r-RP; Fri, 22 Apr 2022 03:08:42 -0400 Original-Received: by mail-pl1-x631.google.com with SMTP id n8so8960379plh.1; Fri, 22 Apr 2022 00:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=S6NylE9SEJw2NPFkyt9ecywrNlpPsR61hkZAgNYCJk0=; b=MTolsWkeuaEBJ0bLesP3NLU+Xnzhi3zqvKFZS0r2y1pufz/yA9pGf8kWm5CLybgk2y 0VGPELKSWG4qKMC7kueHM1Eljgec7RoTXRcL+/Xv2/7ivxssghN9cz87nlusz9dT9aCq BZleCkJZ1ObCTBaVr8tEi6MSHLRAW8PvtPQdPB1m/fUiQVp4lRUbBvhQgkQUlnDjWBv3 mpU9J3TTND81jFCVRLGuSEJX9NxfvOXTQEkW0TrFNXmloPkyVzCLjq/zHpa3IVjB0cHM M20kwa8h+kItUnW61aO6mQnEdVTrU4zU07/lR/mSjpZdhSLNHb3b0T0ADKBj7TwaNz7B d91A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=S6NylE9SEJw2NPFkyt9ecywrNlpPsR61hkZAgNYCJk0=; b=lL91SCLx/28VRtqMPbkOHl4FmI1xcQrt3T+/oo0Jh9wLvOTGnt6VQX1iJ3kg9UlVJy 2lPalVHIPlqfdAoc0+X5gzJXHL46H4O/8k/qBRfRpMueO+ITst1uDb6BpHZb4VqFqVX0 qfUviHO3RHXnmXoWMUWzeKFP8bo9oKwbvdZJbW6bEW8rvgFbPcbtre/UKuyVeRmQBNGm 29oWoSnZM1XIUgVg0prw3fxBIy+K8bOha2XMFfqyb76Icn5tKYF71TB3LOMmBgBCfWZG FP1nbMyUpKTTpRHT9ix1HWDO2rIolTKv3I0vQ/c1rri6XDRoO3npZJzeHeQ6KCVM33wD Qnrg== X-Gm-Message-State: AOAM533aUrFFWfqQVFgc11NCXIePWCtVOptqEnEX5Wl0PLQPfjFVwXJN fiyyjqxJy3g21+QYyyHZZGw= X-Google-Smtp-Source: ABdhPJzFjbAXSr8zIhgpetGas5MjMdLvn7A4/noFpEHJi1zoRyvJ37sOe/RwlLSWBDuQNcIGFak1pw== X-Received: by 2002:a17:903:d3:b0:158:bffa:b8d1 with SMTP id x19-20020a17090300d300b00158bffab8d1mr3076156plc.26.1650611318841; Fri, 22 Apr 2022 00:08:38 -0700 (PDT) Original-Received: from smtpclient.apple ([2600:1700:2ec7:8c90:3c5f:289e:2027:573d]) by smtp.gmail.com with ESMTPSA id p1-20020a62ab01000000b0050acad694a3sm1310039pff.206.2022.04.22.00.08.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Apr 2022 00:08:38 -0700 (PDT) In-Reply-To: <877d7hg1dh.fsf@thornhill.no> X-Mailer: Apple Mail (2.3696.80.82.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=casouri@gmail.com; helo=mail-pl1-x631.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, T_SCC_BODY_TEXT_LINE=-0.01 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" Xref: news.gmane.io gmane.emacs.devel:288794 Archived-At: Thanks, your feedback is very valuable. > I find the way MATCHER -> ANCHOR -> OFFSET technique a little hard to > parse. Ideally I'd like to say something like: "Every direct child of > node FOO should be indented 2 spaces, including the null node". This = is > the general case of indentation as far as I can tell. I'm thinking = such > a rule could look like: >=20 > ((child-of-and-null "function_declaration") (node-is = "function_declaration") 2) IIUC, you are thinking about the following, which matches with whatever = point that is a child of function_declaration and indents 2 columns, is = that true? ((parent-is "function_declaration") parent 2) I am indeed guilty of throwing that wall of text when introducing the = indent engine. I=E2=80=99ll see if I can make it more approachable. I = could probably start by showing an example and how to use it, rather = than explaining all the details. >=20 > This could perhaps be abstracted yet again into a shorthand such as > this: >=20 > (scope-openers '("function_declaration" "class_declaration" = "try_statement")) I see what you mean, but that it yet another concept to learn. I=E2=80=99l= l try to add something like that without adding too much complexity. > My goal is that I get a typing experience where openers always indent: >=20 > ```typescript > function foo() { > | <-- point is here > } > ``` >=20 > ```typescript > function foo() { > try { > | <-- point is here > } > } > ``` >=20 > ```typescript > foo(() =3D> { > | <-- point is here > });=20 > ``` >=20 > Does this make any sense? >=20 > I find that most of the time emacs cannot find the anchor (that's at > least what it is logging), and I assume that means it at least matched > something. I don=E2=80=99t quite understand. What do you mean Emacs cannot find the = anchor? To make sure we are on the same page, in a rule (MATCHER ANCHOR = OFFSET), MATCHER determines whether this rule applies to the current = line, ANCHOR tells you indent from this position, and OFFSET tells you = indent this much from ANCHOR. >=20 > In addition - one trouble I've had with indentation using the = libraries > from melpa is that accumulating offsets in a parentwise path add to to > too big of an indent. Here's an example: >=20 > ```typescript > const foo =3D someFunction(() =3D> ({ > prop: "arst", // <-- indented by two spaces > })) > ``` >=20 > ```typescript > const foo =3D someFunction( > () =3D> ({ > prop: "arst", // <-- indented by four spaces > }) > ) > ``` >=20 > This is the expected indentation. What I'd get is: >=20 > ```typescript > const foo =3D someFunction(() =3D> ({ > prop: "arst", > })) > ``` >=20 > What happens is that the arguments list triggers as an indentation = step, > but it should only do so when when on its own line. I believe this is > what SMIE calls "hanging-p" in its engine. I think an anchor preset that finds the parent that=E2=80=99s at the = beginning of a line should solve this. I=E2=80=99ll definitely add that = one. >=20 > The hardest part apart from a feature branch is getting hold of the > definitions. I think your script-package should be added to elpa so > that putting them in a directory emacs can see can be automated. >=20 > I _really_ think we should distribute a function to get these = libraries > when emacs ships, as every editor does this. We thought about it, the main problem is that tree-sitter the library = and tree-sitter language definitions need to be in sync in terms of = version. Since Emacs doesn't distribute tree-sitter the library, if we = distribute language definitions we can=E2=80=99t make sure they are of = the correct version regards to the tree-sitter library on the system. = Dynamic library, being system-dependent, isn=E2=80=99t something ELPA = can easily distribute either. I can cook up some function that = automatically downloads language definitions like my script does but = that feels hacky and incomplete so it isn=E2=80=99t something I want to = put into core Emacs. Maybe I can put such a function on nongnu ELPA? = I=E2=80=99m open to ideas. Ideally distributions just distribute tree-sitter with all the language = definitions, and we just use that. Yuan=