Subject: bug#61006: 29.0.60; Wrong indentation in go-ts-mode

From: Randy Taylor <[email-masked]>
Date: Wed, 25 Jan 2023 02:46:05 +0000

On Tuesday, January 24th, 2023 at 21:35, Randy Taylor <[email-masked]> wrote:
> 
> On Sunday, January 22nd, 2023 at 05:00, [email-masked] [email-masked] wrote:
> 
> > Hi. Thank you all for great work.
> > In go-ts-mode indentation breaks in function or method definition if
> > arguments placed on separate lines like this:
> > `func transform( s string, ) string {`
> > This code should be indented like this:
> > `func transform( s string, ) string {`
> 
> 
> Thanks for the report. I've attached a patch that fixes this.
> 
> > Also `go-ts-mode-indent-offset' should be 8 by default. In go world there is gofmt which is a real standart for code indentation. It would be great if emacs will provide the same indentation out of the box.
> 
> 
> And addresses this.
> 
> > There is also other issue - sometimes go-ts-mode syntax highliting breaks when I actively use it with `lsp-mode`- refactorings, auto formatting etc. But I can't reproduce it with`eglot`.
> 
> 
> Seems like an `lsp-mode` problem then? I only use `eglot` and haven't noticed anything amiss.

Addendum to my last patch: added indentation support for interfaces as it was missing. Everything else is the same.

From ee72f3ce9afa723ecccc199ed398715ea094d816 Mon Sep 17 00:00:00 2001
From: Randy Taylor <[email-masked]>
Date: Tue, 24 Jan 2023 21:20:48 -0500
Subject: [PATCH] Fix go-ts-mode indentation and set indent offset to 8
 (Bug#61006)

* lisp/progmodes/go-ts-mode.el (go-ts-mode-indent-offset): Change it
to 8.
(go-ts-mode--indent-rules): Add indentation for parameters and interfaces.
---
 lisp/progmodes/go-ts-mode.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el
index d552e1360e0..5f3e1ea3e68 100644
--- a/lisp/progmodes/go-ts-mode.el
+++ b/lisp/progmodes/go-ts-mode.el
@@ -38,7 +38,7 @@
 (declare-function treesit-node-type "treesit.c")
 (declare-function treesit-search-subtree "treesit.c")
 
-(defcustom go-ts-mode-indent-offset 4
+(defcustom go-ts-mode-indent-offset 8
   "Number of spaces for each indentation step in `go-ts-mode'."
   :version "29.1"
   :type 'integer
@@ -78,8 +78,10 @@ go-ts-mode--indent-rules
      ((parent-is "expression_switch_statement") parent-bol 0)
      ((parent-is "field_declaration_list") parent-bol go-ts-mode-indent-offset)
      ((parent-is "import_spec_list") parent-bol go-ts-mode-indent-offset)
+     ((parent-is "interface_type") parent-bol go-ts-mode-indent-offset)
      ((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 "type_spec") parent-bol go-ts-mode-indent-offset)
      ((parent-is "var_declaration") parent-bol go-ts-mode-indent-offset)
      (no-node parent-bol 0)))
-- 
2.39.1