From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jacob Leeming Newsgroups: gmane.emacs.bugs Subject: bug#70345: [PATCH] 29.1.50; csharp-ts-mode indentation of if statements with single-statement body Date: Mon, 22 Apr 2024 09:50:23 +0100 Message-ID: <87wmopaii8.fsf@gmail.com> References: <87o7afod31.fsf@gmail.com> <87mspusb5k.fsf@thornhill.no> 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="40326"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 70345@debbugs.gnu.org, Jacob Leeming To: Theodor Thornhill , Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Apr 22 10:51:35 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 1rypOf-000ADO-G7 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 22 Apr 2024 10:51:33 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rypOM-0007Ya-Ly; Mon, 22 Apr 2024 04:51:16 -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 1rypO2-0007Na-Pw for bug-gnu-emacs@gnu.org; Mon, 22 Apr 2024 04:50:55 -0400 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 1rypNv-0002fQ-Qp for bug-gnu-emacs@gnu.org; Mon, 22 Apr 2024 04:50:51 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rypOB-00044x-4s for bug-gnu-emacs@gnu.org; Mon, 22 Apr 2024 04:51:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jacob Leeming Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 22 Apr 2024 08:51:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70345 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 70345-submit@debbugs.gnu.org id=B70345.171377585615629 (code B ref 70345); Mon, 22 Apr 2024 08:51:03 +0000 Original-Received: (at 70345) by debbugs.gnu.org; 22 Apr 2024 08:50:56 +0000 Original-Received: from localhost ([127.0.0.1]:45652 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rypO2-00043r-GN for submit@debbugs.gnu.org; Mon, 22 Apr 2024 04:50:56 -0400 Original-Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]:60464) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rypNw-00042W-Ex for 70345@debbugs.gnu.org; Mon, 22 Apr 2024 04:50:52 -0400 Original-Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2d895e2c6efso62284521fa.0 for <70345@debbugs.gnu.org>; Mon, 22 Apr 2024 01:50:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713775826; x=1714380626; darn=debbugs.gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=WAP/Zck6DTQ2SnyqQq8n2uhWW53ahpQWNI2vrmVCI5Y=; b=Z/i6+21yPizOgp1MEpw1TX9oRopfi17W/hYvJYoeuqpLiWlTWwb7yNXcYN5QBTj7Bu 7+3x+qBoB2aZV6I+gBl1K0FJBBCNKjrV36FCQ/AIKLInr9tOG63CwOKLOzBUJgA25k05 w0GsTHBPywhW8Sms99hXa+xhiV/rwPsnjrsx7WHDxnHhjSeajKtxjmJQ3Yjx9UkCB+5n vGqIBWdhfQv7KgNAzTpc3ck3FYsi8wrbCCZIuoSeBA4ZsG7S39uLb/Xt/XLlWjuSrHNB MqqIQFz2CjSHTzoAHII12XFNwwsqOhnoXqjT2x9jMTpU4196RUrRiKwPTZUHLUZ9jZ6P bhaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713775826; x=1714380626; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WAP/Zck6DTQ2SnyqQq8n2uhWW53ahpQWNI2vrmVCI5Y=; b=XNZxv1iYV+i0S3XVsgNKKaKkRBQy9ObGU5OTVexR67ZH1SPx4Q76oKZwFnTiiaAr1y oY0QER9iPqJ+EPbFrt4R3rlQej4Rfl51QbgNBJ8nd50zZcJTQWpgug1YjI6lzWn9c88V kPX7pzst03XiwaD0YYG0JolyZJx8H1Dd7SXu+vV5QEY0U6+G3UYLx0ZcKofQ0rc5kfcR 4eqDyXcEg/63kLWQ3lbm+EqzRqDLU4WXoIEnPgf4MOsabGv4KBfn0Qzk4J/f7kQ0m2V9 oMI2T/ib8IH/RUuf0HWn76kzQbh8CidNWQIcj1tUGvC8k4+eW7NZrhtylUscS6au3uqM UjdQ== X-Forwarded-Encrypted: i=1; AJvYcCUr581JLK4vPS6wb4LvkHB2KDpe4ialeOMDQkbZoeVapuIG/b0K0fuT1rsiNmDGYDCfM5pinm7TN+L06rrzam7+hM3A1t4= X-Gm-Message-State: AOJu0Yyw5wDb4oB7mvgaO+FOM8kJwW5ZnAAlgzCNKMRPtniT9BMcwzFS gYY4bwDZVQ0a7RUe1WyWn4fYroEjdRVQpmMElknWuNmoFXO+wYV6OVEUDeCe X-Google-Smtp-Source: AGHT+IHnb+9uPM/s9HfUjlXSWTN6JKV7aQvDXEVbHHzz/94C1kbPX812V1wuDFybYAvoh/EzRWzPXA== X-Received: by 2002:a2e:93c7:0:b0:2dd:9d77:bd60 with SMTP id p7-20020a2e93c7000000b002dd9d77bd60mr938587ljh.52.1713775825873; Mon, 22 Apr 2024 01:50:25 -0700 (PDT) Original-Received: from jacobDebianWorkLaptop ([2a00:23c7:238a:701:c982:ec15:697:6050]) by smtp.gmail.com with ESMTPSA id n2-20020a05600c4f8200b0041884b79b81sm15833640wmq.1.2024.04.22.01.50.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 01:50:25 -0700 (PDT) In-Reply-To: <87mspusb5k.fsf@thornhill.no> (Theodor Thornhill's message of "Mon, 15 Apr 2024 21:01:27 +0200") 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:283817 Archived-At: --=-=-= Content-Type: text/plain > Theodor Thornhill writes: >> Hi all, >> > > Hi, Jacob! > >>>>From emacs -Q: >> >> Evaluate this elisp to set up treesitter for csharp: >> >> (setq treesit-language-source-alist '((c-sharp >> "https://github.com/tree-sitter/tree-sitter-c-sharp" "master" "src")) >> treesit-load-name-override-list '((c-sharp >> "libtree-sitter-csharp" "tree_sitter_c_sharp")) >> major-mode-remap-alist '((csharp-mode . csharp-ts-mode))) >> >> Insert the following text into a csharp-ts-mode buffer: >> >> if (true) >> var x = 2; >> >> Try to indent the variable declaration of the function with >> indent-for-tab-command. Nothing will happen. I'd expect to see this: >> >> if (true) >> var x = 2; >> >> This issue can be fixed with the following patch: >> >> diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el >> index 53c52e6..1a7d535 100644 >> --- a/lisp/progmodes/csharp-mode.el >> +++ b/lisp/progmodes/csharp-mode.el >> @@ -678,7 +678,8 @@ csharp-ts-mode--indent-rules >> ((parent-is "binary_expression") parent 0) >> ((parent-is "block") parent-bol csharp-ts-mode-indent-offset) >> ((parent-is "local_function_statement") parent-bol 0) >> - ((parent-is "if_statement") parent-bol 0) >> + ((match "block" "if_statement") parent-bol 0) >> + ((parent-is "if_statement") parent-bol csharp-ts-mode-indent-offset) >> ((parent-is "for_statement") parent-bol 0) >> ((parent-is "for_each_statement") parent-bol 0) >> ((parent-is "while_statement") parent-bol 0) >> > > Looks good to me. Are you willing to pack this up with a nice test > confirming the behavior? > > All the best, > Theo Thanks all, Discovered we had a similar issue for else blocks. Wrote a test that covers both cases. See the attached diff which contains my changes to the indent rules and the test. Cheers, Jacob --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-indent-single-statement-if-in-csharp-ts-mode.patch >From cd86e2e3fbe596b999f4cfd9655f0a37ac3845d2 Mon Sep 17 00:00:00 2001 From: Jacob Leeming Date: Mon, 22 Apr 2024 09:49:15 +0100 Subject: [PATCH] indent single statement if in csharp-ts-mode bug#70345 --- lisp/progmodes/csharp-mode.el | 4 +- .../csharp-ts-mode-resources/indent.erts | 51 +++++++++++++++++++ test/lisp/progmodes/csharp-ts-mode-tests.el | 30 +++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 test/lisp/progmodes/csharp-ts-mode-resources/indent.erts create mode 100644 test/lisp/progmodes/csharp-ts-mode-tests.el diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el index 607360f737a..62bbbfe02ff 100644 --- a/lisp/progmodes/csharp-mode.el +++ b/lisp/progmodes/csharp-mode.el @@ -689,7 +689,9 @@ csharp-ts-mode--indent-rules ((parent-is "binary_expression") parent 0) ((parent-is "block") parent-bol csharp-ts-mode-indent-offset) ((parent-is "local_function_statement") parent-bol 0) - ((parent-is "if_statement") parent-bol 0) + ((match "block" "if_statement") parent-bol 0) + ((match "else" "if_statement") parent-bol 0) + ((parent-is "if_statement") parent-bol csharp-ts-mode-indent-offset) ((parent-is "for_statement") parent-bol 0) ((parent-is "for_each_statement") parent-bol 0) ((parent-is "while_statement") parent-bol 0) diff --git a/test/lisp/progmodes/csharp-ts-mode-resources/indent.erts b/test/lisp/progmodes/csharp-ts-mode-resources/indent.erts new file mode 100644 index 00000000000..3cb23608270 --- /dev/null +++ b/test/lisp/progmodes/csharp-ts-mode-resources/indent.erts @@ -0,0 +1,51 @@ +Code: + (lambda () + (csharp-ts-mode) + (indent-region (point-min) (point-max))) + +Point-Char: | + +Name: Indent single statement body for if/else. (bug#70345) + +=-= + +int x; +int y; + +if (true) + x = 2; + +if (true) +{ + x = 2; +} + +if (true) + x = 2; +else + y = 2; + +if (true) +{ + x = 2; +} +else +{ + y = 2; +} + +if (true) + x = 2; +else +{ + y = 2; +} + +if (true) +{ + x = 2; +} +else + y = 2; + +=-=-= diff --git a/test/lisp/progmodes/csharp-ts-mode-tests.el b/test/lisp/progmodes/csharp-ts-mode-tests.el new file mode 100644 index 00000000000..0df0211d86b --- /dev/null +++ b/test/lisp/progmodes/csharp-ts-mode-tests.el @@ -0,0 +1,30 @@ +;;; csharp-ts-mode-tests.el --- Tests for Tree-sitter-based C# mode -*- lexical-binding: t; -*- + +;; Copyright (C) 2024 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Code: + +(require 'ert) +(require 'ert-x) +(require 'csharp-mode) + +(ert-deftest csharp-ts-mode-test-indentation () + (ert-test-erts-file (ert-resource-file "indent.erts"))) + +(provide 'csharp-ts-mode-tests) +;;; csharp-ts-mode-tests.el ends here -- 2.39.2 --=-=-=--