emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 89b550eac2: Fix switch statement indentation for go-ts-mode (bu


From: Theodor Thornhill
Subject: emacs-29 89b550eac2: Fix switch statement indentation for go-ts-mode (bug#61238)
Date: Sat, 4 Feb 2023 13:30:45 -0500 (EST)

branch: emacs-29
commit 89b550eac2909f1fcd7cc5eb3dfe81e853bf5ed0
Author: Davide Masserut <dm@mssdvd.com>
Commit: Theodor Thornhill <theo@thornhill.no>

    Fix switch statement indentation for go-ts-mode (bug#61238)
    
    * 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 ++
 .../progmodes/go-ts-mode-resources/indent.erts     | 47 ++++++++++++++++++++++
 test/lisp/progmodes/go-ts-mode-tests.el            | 31 ++++++++++++++
 3 files changed, 82 insertions(+)

diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el
index 5f3e1ea3e6..95dcf653fc 100644
--- a/lisp/progmodes/go-ts-mode.el
+++ b/lisp/progmodes/go-ts-mode.el
@@ -72,6 +72,7 @@
      ((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 @@
      ((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 0000000000..a89d69b307
--- /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 0000000000..548465208f
--- /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 <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(require 'ert-x)
+(require 'treesit)
+
+(ert-deftest go-ts-mode-test-indentation ()
+  (skip-unless (treesit-ready-p 'go))
+  (ert-test-erts-file (ert-resource-file "indent.erts")))
+
+(provide 'go-ts-mode-tests)
+;;; go-ts-mode-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]