From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Davide Masserut via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#61238: [PATCH] Fix go-ts-mode type switch and select case blocks indentation Date: Sat, 04 Feb 2023 18:21:09 +0100 Message-ID: <87a61t1gq6.fsf@mssdvd.com> References: <87ilgj245n.fsf@mssdvd.com> <87v8khhm8n.fsf@thornhill.no> Reply-To: Davide Masserut 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="13656"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 61238@debbugs.gnu.org, eliz@gnu.org To: Theodor Thornhill Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Feb 04 18:30:22 2023 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 1pOMMn-0003M5-Kb for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 04 Feb 2023 18:30:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pOMMc-0006NF-W2; Sat, 04 Feb 2023 12:30:11 -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 1pOMMW-0006LI-2x for bug-gnu-emacs@gnu.org; Sat, 04 Feb 2023 12:30:05 -0500 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 1pOMMV-0003WY-Lk for bug-gnu-emacs@gnu.org; Sat, 04 Feb 2023 12:30:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pOMMV-0000nu-Ct for bug-gnu-emacs@gnu.org; Sat, 04 Feb 2023 12:30:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Davide Masserut Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 04 Feb 2023 17:30:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61238 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 61238-submit@debbugs.gnu.org id=B61238.16755317983051 (code B ref 61238); Sat, 04 Feb 2023 17:30:03 +0000 Original-Received: (at 61238) by debbugs.gnu.org; 4 Feb 2023 17:29:58 +0000 Original-Received: from localhost ([127.0.0.1]:43371 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pOMMQ-0000n9-C1 for submit@debbugs.gnu.org; Sat, 04 Feb 2023 12:29:58 -0500 Original-Received: from out-21.mta1.migadu.com ([95.215.58.21]:37093) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pOMMN-0000n0-UL for 61238@debbugs.gnu.org; Sat, 04 Feb 2023 12:29:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mssdvd.com; s=key1; t=1675531794; 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: in-reply-to:in-reply-to:references:references; bh=N2pMGdJTnw6ivy7qsZor9DKS8rIjBAL5v8pJR/EFFec=; b=BneC5Ee5PmXofH5SWPq5A3pY/o/RE/I39pstbOeQAXpKGRNqQQK1tV+cxhQa3ulj4nUFfY y/UcqNCcsHkpAUZkytLMwav/wh0XvGZKFX9tu3nlju1/jBVgBTuOU69yzHqhnDWvM74V7W RCLITAKiSlclrQwZi1BjFPZOBzwwtP+JfQK8WOP7vzD0WlwW3VqsYuiE0PNDLpKvYpdVpw i4TTf2O1MiJbC5CLRhs3zHd+iL70urbfH604SbNEFZNyGM1tevOFKJqqR5A7GXjE8viRDA UNS/+ISfWjM1a6g//eTFwH7CkdMaBrpDMxjpqTIzq3TkZzrNOXB45hNR9E8w7A== X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: <87v8khhm8n.fsf@thornhill.no> X-Migadu-Flow: FLOW_OUT 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:254787 Archived-At: --=-=-= Content-Type: text/plain; format=flowed Theodor Thornhill writes: > Hey there, Davide, and thanks for the clear bug-report! > > This looks good to me, but before I install, Maybe you can also > add a > test for this, similar to the ones in c-ts-mode-tests.el? > > Also, just checking - is fsf assignment needed for this change? > Maybe > you've done it already, if so, forgive my ignorance :-) > > Theo I added the tests and also indentation rules for the "case" and "default" keywords so that they are aligned with their parent. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Fix-go-ts-mode-type-switch-and-select-case-blocks-in.patch >From 90b0f6ce31e60ca36f8625e8386379259d75c8a0 Mon Sep 17 00:00:00 2001 From: Davide Masserut Date: Thu, 2 Feb 2023 21:00:02 +0100 Subject: [PATCH] Fix go-ts-mode type switch and select case blocks indentation * lisp/progmodes/go-ts-mode.el (go-ts-mode--indent-rules): Add indentation for type switch and select case blocks * test/lisp/progmodes/go-ts-mode-resources/indent.erts: New .erts file to test indentation of Go constructs and prevent regression of bug fixes. * test/lisp/progmodes/go-ts-mode-tests.el: New file with go-ts-mode tests. --- lisp/progmodes/go-ts-mode.el | 4 ++ .../go-ts-mode-resources/indent.erts | 47 +++++++++++++++++++ test/lisp/progmodes/go-ts-mode-tests.el | 31 ++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 test/lisp/progmodes/go-ts-mode-resources/indent.erts create mode 100644 test/lisp/progmodes/go-ts-mode-tests.el diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el index 5f3e1ea3e68..95dcf653fc6 100644 --- a/lisp/progmodes/go-ts-mode.el +++ b/lisp/progmodes/go-ts-mode.el @@ -72,6 +72,7 @@ go-ts-mode--indent-rules ((node-is "labeled_statement") no-indent) ((parent-is "argument_list") parent-bol go-ts-mode-indent-offset) ((parent-is "block") parent-bol go-ts-mode-indent-offset) + ((parent-is "communication_case") parent-bol go-ts-mode-indent-offset) ((parent-is "const_declaration") parent-bol go-ts-mode-indent-offset) ((parent-is "default_case") parent-bol go-ts-mode-indent-offset) ((parent-is "expression_case") parent-bol go-ts-mode-indent-offset) @@ -82,7 +83,10 @@ go-ts-mode--indent-rules ((parent-is "labeled_statement") parent-bol go-ts-mode-indent-offset) ((parent-is "literal_value") parent-bol go-ts-mode-indent-offset) ((parent-is "parameter_list") parent-bol go-ts-mode-indent-offset) + ((parent-is "select_statement") parent-bol 0) + ((parent-is "type_case") parent-bol go-ts-mode-indent-offset) ((parent-is "type_spec") parent-bol go-ts-mode-indent-offset) + ((parent-is "type_switch_statement") parent-bol 0) ((parent-is "var_declaration") parent-bol go-ts-mode-indent-offset) (no-node parent-bol 0))) "Tree-sitter indent rules for `go-ts-mode'.") diff --git a/test/lisp/progmodes/go-ts-mode-resources/indent.erts b/test/lisp/progmodes/go-ts-mode-resources/indent.erts new file mode 100644 index 00000000000..a89d69b307c --- /dev/null +++ b/test/lisp/progmodes/go-ts-mode-resources/indent.erts @@ -0,0 +1,47 @@ +Code: + (lambda () + (go-ts-mode) + (indent-region (point-min) (point-max))) + +Point-Char: | + +Name: Basic + +=-= +package main + +func main() { +} +=-=-= + +Name: Switch and Select + +=-= +package main + +func main() { + var x any + switch x { + case 1: + println("one") + default: + println("default case") + } + + switch x.(type) { + case int: + println("integer") + default: + println("don't know the type") + } + + var c chan int + select { + case x := <-c: + println(x) + default: + println("no communication") + } +} + +=-=-= diff --git a/test/lisp/progmodes/go-ts-mode-tests.el b/test/lisp/progmodes/go-ts-mode-tests.el new file mode 100644 index 00000000000..4bfebcbaac0 --- /dev/null +++ b/test/lisp/progmodes/go-ts-mode-tests.el @@ -0,0 +1,31 @@ +;;; go-ts-mode-tests.el --- Tests for Tree-sitter-based Go mode -*- lexical-binding: t; -*- + +;; Copyright (C) 2023 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 'treesit) + +(ert-deftest go-ts-mode-test-indentation () + (skip-unless (treesit-ready-p 'c)) + (ert-test-erts-file (ert-resource-file "indent.erts"))) + +(provide 'go-ts-mode-tests) +;;; go-ts-mode-tests.el ends here -- 2.39.1 --=-=-=--