From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#74386: Tree-sitter javascript indentation Date: Fri, 13 Dec 2024 05:34:02 +0200 Message-ID: References: <2ce8c98e-c399-46f1-a930-04f27a3d56dd@gutov.dev> <389b6090-6ae9-433a-85cc-a2d2eb84751f@gutov.dev> <86r06t82gl.fsf@gnu.org> <4B4B99E7-C4A1-4124-BC85-2AD66EF0871B@gmail.com> <35B61F44-C551-44DB-A334-A893991BC799@gmail.com> <8A7428E6-50EE-4783-82FF-3A62C4756C56@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="12358"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: 74386@debbugs.gnu.org, Eli Zaretskii , Theodor Thornhill , marius.kjeldahl@gmail.com To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 13 04:50:15 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1tLwgv-00032n-GP for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 13 Dec 2024 04:50:14 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLwgn-0002n4-6m; Thu, 12 Dec 2024 22:50:05 -0500 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 1tLwgl-0002mh-NH for bug-gnu-emacs@gnu.org; Thu, 12 Dec 2024 22:50:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tLwgl-0001jB-9f for bug-gnu-emacs@gnu.org; Thu, 12 Dec 2024 22:50:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=In-Reply-To:From:References:MIME-Version:Date:To:Subject; bh=ItSaQM8W9HwgIouWyXSAy5OlgQbDTDd8vbbTMCWLqN8=; b=R2lIY00uWoUvg6W0DMCCGeWaHmRTIlq0LnpHEy7ALCBG4ut8uiBP/gdRyDrPHMoptrjiRqBLWPn5u6JFjOPqj6XKV6imHapWZitSRRBU3laOoWS9mqixSXtYGFsSCo9OaFv4ddktkrJRLL+aqnRyJfA3ukS7eLt0wqFerbNMEexVvHi0gxkTdYCbIT3eHt+UNo+NbGyoToSgwKyyYZugBqgbq+LZEmNOqDqkw7fcxs0RIbz6W9C6L5M4YyoLzicGk08FWTSo0GzqdDYwqZ+Jj3YZ0gFCt38PMIxVxyla/R6qyF165XfO10YkKolCxE/68YizFHkbguXO7OVJRi6n6w==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tLwSE-0002oK-1v for bug-gnu-emacs@gnu.org; Thu, 12 Dec 2024 22:35:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 13 Dec 2024 03:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74386 X-GNU-PR-Package: emacs Original-Received: via spool by 74386-submit@debbugs.gnu.org id=B74386.173406086710742 (code B ref 74386); Fri, 13 Dec 2024 03:35:02 +0000 Original-Received: (at 74386) by debbugs.gnu.org; 13 Dec 2024 03:34:27 +0000 Original-Received: from localhost ([127.0.0.1]:41119 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLwRa-0002n2-A9 for submit@debbugs.gnu.org; Thu, 12 Dec 2024 22:34:26 -0500 Original-Received: from fout-b1-smtp.messagingengine.com ([202.12.124.144]:37985) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLwRT-0002mf-Tz for 74386@debbugs.gnu.org; Thu, 12 Dec 2024 22:34:19 -0500 Original-Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.stl.internal (Postfix) with ESMTP id 27B4A1140136; Thu, 12 Dec 2024 22:34:10 -0500 (EST) Original-Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Thu, 12 Dec 2024 22:34:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1734060850; x=1734147250; bh=ItSaQM8W9HwgIouWyXSAy5OlgQbDTDd8vbbTMCWLqN8=; b= fOXSaKIfbrDZMhUcV8Nh2hb/l6laU/Oq549/Z/MNkZNQDF1dU41Z2wvrC550NctL O3/pNyRC8ep2hrOow0wIrTozxN5C3mpmGmOUbXx3XCCOqrhjJnnzwVYL6JJQy4Nd wgBYxd8jUZXE4hvUGym8DcTALNWiFVy9XbuKptYe0LIl3S0sptrmc73PBjuSocrU Wvlph5xKFyGaIrSYpMUL+BkNizGrjT+X1jM1YAkyXwkyxlFQeEfShicdrWCtgw62 xxOyqrtHOedzqUomXQrkZLoy2/wg+q8sWW2nKmk/sUa3NvGrCNzwOF+NS+7/Nhr4 sZM67IRABkrYn6YykSxuvQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1734060850; x= 1734147250; bh=ItSaQM8W9HwgIouWyXSAy5OlgQbDTDd8vbbTMCWLqN8=; b=l +7uvI4DaXH50tvDMbYgcUuZ4EH2jHloNOnOyU09kb59DG/z3bAIoBsmuZMMLNjWS qm3sv8e8qjBQ/XxHzeHDLKI7RNsayExpK4VbicOd8/dhscSxu6VXsBtI9gR0IolB YI+tZW8J8kFvGQQfjyT9E7QT+4GZNmC7JajifaBkLCpqrmvOg/neDbEP5zd30+Ve cPkOMgThu0CRB2XbFtARL80daDQf5UuRK0WNf9ci5fbq0lWrPN5rFqdhbSliT+pg QN9l/DUkjGiCJGlQhhc0Xc95vcTPy8jSEk4YKh1iIaFLUYkPlh9z0RYfV7Ns9JUK SGHQ656xePNSulXy/BsYg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrkeeigdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefkffggfgfuvfevfhfhjggtgfesthekredttddvjeen ucfhrhhomhepffhmihhtrhihucfiuhhtohhvuceoughmihhtrhihsehguhhtohhvrdguvg hvqeenucggtffrrghtthgvrhhnpeegleefteekgffhvdfhtdegveevveetteegteevgeet tdehhfdukeetheffueekkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegumhhithhrhiesghhuthhovhdruggvvhdpnhgspghrtghpthhtohep hedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheptggrshhouhhrihesghhmrghilh drtghomhdprhgtphhtthhopegvlhhiiiesghhnuhdrohhrghdprhgtphhtthhopehthhgv ohesthhhohhrnhhhihhllhdrnhhopdhrtghpthhtohepjeegfeekieesuggvsggsuhhgsh drghhnuhdrohhrghdprhgtphhtthhopehmrghrihhushdrkhhjvghluggrhhhlsehgmhgr ihhlrdgtohhm X-ME-Proxy: Feedback-ID: i07de48aa:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Dec 2024 22:34:08 -0500 (EST) Content-Language: en-US In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:296955 Archived-At: On 12/12/2024 07:28, Yuan Fu wrote: >> What would be our next step in this? Replacing all 'parent-bol' anchors with 'standalone-parent' across most ts modes? > > Speaking of next step, I recently added another handy tool for languages with C-like syntax: c-ts-common-baseline-indent-rule. I figured out an indent logic that can work on all C-like languages and covers a wide range of cases. This one rule can give you all theses indentation: Looks pretty great. I guess it depends on the grammars being to an extent compatible, right? > 1. Statements align to their previous sibling: > > int main() { > int a = 1; > int b = 2; <-- Align to prev line’s sibling. > } > > 2. Indents one level for blocks: function, if, for, struct, etc. > > int main() { > return 0; <-- Indent one level. > { <-- Align to prev line’s sibling. > return 1; <-- Indent one level. > } > } > > 3. Elements in parenthesis and brackets: > > return [1, 2, 3, > 4, 5, 6]; <-- Align to first sibling. > > return [ > 1, 2, 3, <-- Indent one level (option 1). > 4, 5, 6, <-- Align to prev line’s sibling. > ]; > > return [ > 1, 2, 3, <-- Align to opening bracket (option 2). > 4, 5, 6, <-- Align to prev line’s sibling. > ]; <-- Align to opening bracket. > > for (int i = 0; > i < 10; <-- Align to first sibling. > i++) { <-- Align to prev line’s sibling. > continue; > } > > 4. Statement expressions indent one level when it’s broken into two > lines: > > int main() { > int var > = 1287; <-- Indent one level. > int var = > 1287; <-- Indent one level. > } Should there be an example with a method call starting on a new line, line in the arrow literal example (for JS) that we discussed? > Then a C-like language’s major mode only need to add special cases over the baseline indent rule. And if we add the configurable heuristic for standalone-parent, the baseline indent rules would make use of it. Sounds good. > I brought it up because if we’re going to do some renovations to indent rules, might as well make use of c-ts-common-baseline-indent-rule, and we probably don’t even need to replace parent-box with standalone-parent, because the baseline indent rule would cover most cases. I'm now sure how safe that is - my point was that for each of the languages it'd be great to have somebody motivated go over the main syntactic cases and see that the behavior is still reasonable. But we can also make the switch and wait for reports. > I’ve already used it to rewrite c-ts-mode indent rules and it’s been a success; this baseline + override approach has been very helpful. c-ts-mode still has a lot of indent rules because of things like preproc directive, etc, but it’s much more manageable than before. > > I don’t know how much it would help modes that has simpler indent rules. Go-ts-mode and rust-ts-mode only has a handful of indent rules, maybe they don’t really need this baseline rule. OTOH Lua and Ruby has more involved indent rules, maybe they can benefit and reduce the number of rules they need to define. Ruby has different delimiters (do...end or def...end or etc), and the curlies don't do exactly the same job that they do in C. So I'm not sure how feasible it is. A half of the function would be a fit, though.