AndrewRadev/splitjoin.vim

Go: can't split/join var, const, type declarations inside block (not global scope)

ArtAndreev opened this issue · 2 comments

Better to start with example. I have the following code:

package main

var globalVar = 0 // OK, split/join works.

const globalConst = 1 // OK, split/join works.

type t2 string // OK, split/join works.

func main() {
	var anotherLocalVar = 3 // Can't split, nothing happens.
	const bb = 4            // Can't split, nothing happens.

	// Can't join correctly, does `var (localVar = 5)`.
	var (
		localVar = 5
	)
	// Can't join, does `const (constVar = 6)`.
	const (
		constVar = 6
	)

	type t7 string // Can't split, nothing happens.

	// Can't join, does `type (t8 string)`.
	type (
		t8 string
	)

	_ = localVar
	_ = anotherLocalVar
}

When I try to split var, const, type declarations inside block (function, for example, see 3, 4, 7), it does nothing.
When I try to join them (see 5, 6, 8), it simply joins three lines to one, but doesn't remove the brackets.

It will be useful to fix this bug, brackets are used for grouping variables, consts with same logic.

Edit: add type declarations.

Thanks for reporting, this seems like a pretty obvious case I've missed. I've pushed a fix, could you try it out?

Works now, thank you!