From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill Newsgroups: gmane.emacs.devel Subject: Re: Tree-sitter api Date: Fri, 22 Apr 2022 06:58:50 +0200 Message-ID: <877d7hg1dh.fsf@thornhill.no> 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> Mime-Version: 1.0 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="7941"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Lars Ingebrigtsen , Eli Zaretskii , emacs-devel@gnu.org To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Apr 22 07:01:11 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 1nhlPq-0001sG-To for ged-emacs-devel@m.gmane-mx.org; Fri, 22 Apr 2022 07:01:11 +0200 Original-Received: from localhost ([::1]:52230 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhlPq-000094-1s for ged-emacs-devel@m.gmane-mx.org; Fri, 22 Apr 2022 01:01:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35270) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhlNj-0006LN-FO for emacs-devel@gnu.org; Fri, 22 Apr 2022 00:58:59 -0400 Original-Received: from out1.migadu.com ([91.121.223.63]:63014) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhlNg-0007v7-T8; Fri, 22 Apr 2022 00:58:59 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1650603532; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oXS/da+3wd5w9XQueVjML5y+kX8IUhQEizvV8DcTpCA=; b=lXpvz84cvjR8PoyZ67ZSnm7/u9KGeu53ZuPDoTOQcINWsX90P8bQqwwhOV3y8/dXbhrh/3 2UOQTgZ2JYv6TBbqrNpyBA2fhmYJXtmPg90s0aJEGkhq1E0X4YwP4nDz4kOKnWI0jnMbko SvSG2Rg/BX7iabi/19YOHKFkCh3NqG+sh+EKt5FElDzgpAMsWUayF8SQL8VK4Ys+0hc5xQ n6sgUd6NN3WU/IgbRTdYGJIyYPn4Y4vEMhyT67u5m38Cwn2jwoQwXKpwh51ypoRI5U1g0o YUXLtnAVWK3M42B5sm/KzwDgtUjQLMyMCj6Vz6MLrbPjOmiIdsAR1ZWDqsYWBQ== In-Reply-To: <3560D8FB-9D85-4A04-B6CE-811A6D793B59@gmail.com> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: thornhill.no Received-SPF: pass client-ip=91.121.223.63; envelope-from=theo@thornhill.no; helo=out1.migadu.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, 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:288785 Archived-At: Yuan Fu writes: >> Great! I've started work on using tree-sitter provided by Yuan Fu in >> typescript-mode, and it is working rather well. I'm struggling a little >> with indentation, but I'm sure it's user error. > > I=E2=80=99d love to know how are you struggling, because ideally we=E2=80= =99d want the > indentation engine to be very easy to understand and use. Maybe we can > improve the documentation or something? > 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: ((child-of-and-null "function_declaration") (node-is "function_declaration"= ) 2) This could perhaps be abstracted yet again into a shorthand such as this: (scope-openers '("function_declaration" "class_declaration" "try_statement"= )) My goal is that I get a typing experience where openers always indent: ```typescript function foo() { | <-- point is here } ``` ```typescript function foo() { try { | <-- point is here } } ``` ```typescript foo(() =3D> { | <-- point is here });=20 ``` Does this make any sense? 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. 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: ```typescript const foo =3D someFunction(() =3D> ({ prop: "arst", // <-- indented by two spaces })) ``` ```typescript const foo =3D someFunction( () =3D> ({ prop: "arst", // <-- indented by four spaces }) ) ``` This is the expected indentation. What I'd get is: ```typescript const foo =3D someFunction(() =3D> ({ prop: "arst", })) ``` 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. >> Making a feature branch for this would indeed help a _lot_ as setup >> right now is very finicky. I'll report back any bugs I can find while >> digging. > > So you think there can be any improvements in this regard? (Except for > moving to a feature branch, of course, that=E2=80=99s already on the list= .) > 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. I _really_ think we should distribute a function to get these libraries when emacs ships, as every editor does this. Sorry for the long post, hope some of it makes sense :) Theodor