From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#58815: 29.0.50; Small treesitter fixes for js/ts-mode Date: Thu, 27 Oct 2022 11:58:06 +0200 Message-ID: <87edutsi4x.fsf@thornhill.no> Reply-To: Theodor Thornhill Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9213"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Yuan Fu To: 58815@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 27 12:09:17 2022 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 1onzp7-0002Cd-8f for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 27 Oct 2022 12:09:17 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onzfb-0008KW-EI; Thu, 27 Oct 2022 05:59:29 -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 1onzfG-00086J-UT for bug-gnu-emacs@gnu.org; Thu, 27 Oct 2022 05:59:08 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1onzfC-0003Vh-CI for bug-gnu-emacs@gnu.org; Thu, 27 Oct 2022 05:59:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1onzfC-0003PY-1F for bug-gnu-emacs@gnu.org; Thu, 27 Oct 2022 05:59:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 27 Oct 2022 09:59:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 58815 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.166686470513061 (code B ref -1); Thu, 27 Oct 2022 09:59:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 27 Oct 2022 09:58:25 +0000 Original-Received: from localhost ([127.0.0.1]:56190 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1onzeb-0003Ob-3Z for submit@debbugs.gnu.org; Thu, 27 Oct 2022 05:58:25 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:55234) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1onzeX-0003OR-D1 for submit@debbugs.gnu.org; Thu, 27 Oct 2022 05:58:24 -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 1onzeO-0002S3-Js for bug-gnu-emacs@gnu.org; Thu, 27 Oct 2022 05:58:21 -0400 Original-Received: from out0.migadu.com ([94.23.1.103]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onzeL-0003LH-GA for bug-gnu-emacs@gnu.org; Thu, 27 Oct 2022 05:58:12 -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=1666864687; 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; bh=Dft82sfrsC3KCOjbRS6fURly4cKs+NmGIIYDz7kFwsE=; b=NmOMtkKIfGwlJTOWJFB2hUDKe9zrOs44W8Fe3qlm6AmsjWRThZMp9wcgf+Fe77znXn6Js+ 4hO30rkW/ztwnosFScM7wtL3pNk8plEmTn9iQ0w+xjd79xrauYAPmiy1K40LTCpUegSPNz UQ6WoFSFN+j4tr3u91hf3+0REbCCOOEyWj7f7rO8hUyJvhSMWE4yzw6SGH0nkx6AT2Mcdg E8HE1CDoMXWNPdl9mJPo+2+HiANL0JlNNmP6jUuQd7yHKWYNKF7PLrPfhaiRFqHpRj65FI tZk+6Sl6zxZOU6yYkFqcqpF7tFLVs57V0pUHL4D/07K5RrnlCrlC4HZvgt5WjA== X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=94.23.1.103; envelope-from=theo@thornhill.no; helo=out0.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_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Original-Sender: "bug-gnu-emacs" Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:246286 Archived-At: --=-=-= Content-Type: text/plain Hello Yuan! See the attached patch. There's a small fix to ensure the parser, as well as adding in two small, but nice indentation fixes. Thanks, Theo --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Tweak-indentation-and-ensure-parser.patch >From c45f93e3677b3ef66730afd00024933568058755 Mon Sep 17 00:00:00 2001 From: Theodor Thornhill Date: Thu, 27 Oct 2022 11:53:07 +0200 Subject: [PATCH] Tweak indentation and ensure parser * lisp/progmodes/js.el (js--treesit-indent-rules) (js--treesit-cc-indent-rules): Don't use '.' as indent anchor and add in 'program' as root anchor. * lisp/progmodes/ts-mode.el (ts-mode--indent-rules): Don't use '.' as indent anchor and add in 'program' as root anchor. (ts-mode): Create parser so that mode can initialize. --- lisp/progmodes/js.el | 12 +++++++++++- lisp/progmodes/ts-mode.el | 9 +++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 89bd04b231..b940a3a2a4 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -3416,12 +3416,16 @@ js--treesit-backward-up-list (defvar js--treesit-indent-rules `((javascript + ((parent-is "program") parent-bol 0) (no-node (js--treesit-backward-up-list) ,js-indent-level) ((node-is "}") parent-bol 0) ((node-is ")") parent-bol 0) ((node-is "]") parent-bol 0) ((node-is ">") parent-bol 0) - ((node-is ".") parent-bol ,js-indent-level) + ((parent-is "ternary_expression") + parent-bol ,js-indent-level) + ((parent-is "member_expression") + parent-bol ,js-indent-level) ((parent-is "named_imports") parent-bol ,js-indent-level) ((parent-is "statement_block") parent-bol ,js-indent-level) ((parent-is "variable_declarator") parent-bol ,js-indent-level) @@ -3452,6 +3456,7 @@ js--treesit-cc-indent-rules "_clause")) (switch-case-re (rx "switch_" (or "case" "default")))) `((javascript + ((parent-is "program") parent-bol 0) ;; Function declaration. ;; "{" ((match "statement_block" ,function-re) parent defun-open) @@ -3529,6 +3534,11 @@ js--treesit-cc-indent-rules ((node-is "formal_parameters") parent statement-cont) ;; Misc. + ((parent-is "ternary_expression") + parent-bol ,js-indent-level) + ((parent-is "member_expression") + parent-bol ,js-indent-level) + ((parent-is "function_declaration") parent func-decl-cont) ((parent-is "string-fragment") grand-parent string) ((parent-is "comment") grand-parent c) diff --git a/lisp/progmodes/ts-mode.el b/lisp/progmodes/ts-mode.el index 28800e378a..88c93a6e93 100644 --- a/lisp/progmodes/ts-mode.el +++ b/lisp/progmodes/ts-mode.el @@ -55,14 +55,15 @@ ts-mode--syntax-table (defvar ts-mode--indent-rules `((tsx + ((parent-is "program") parent-bol 0) ((node-is "}") parent-bol 0) ((node-is ")") parent-bol 0) ((node-is "]") parent-bol 0) ((node-is ">") parent-bol 0) - ((node-is ".") - parent-bol ,ts-mode-indent-offset) ((parent-is "ternary_expression") parent-bol ,ts-mode-indent-offset) + ((parent-is "member_expression") + parent-bol ,ts-mode-indent-offset) ((parent-is "named_imports") parent-bol ,ts-mode-indent-offset) ((parent-is "statement_block") @@ -261,8 +262,8 @@ ts-mode :syntax-table ts-mode--syntax-table (cond - ((treesit-ready-p nil 'tsx) - ;; Tree-sitter. + ((treesit-ready-p 'ts-mode 'tsx) + (treesit-parser-create 'tsx) ;; Comments. (setq-local comment-start "// ") (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *") -- 2.34.1 --=-=-=--