Skip to content

[Feature request] Generate constructor function #609

@teensee

Description

@teensee

Hi, I use go.nvim for my daily golang stuff for personal projects. I love this project.

Is there any plans to add command for generating constructor (NewXxx) from struct?

go.nvim already has GoFillStruct, GoImpl, GoAddTag — so GoCtor (GoConstructor/Goctor/GoConstr...) feels like it shuold be there too, no?

Basically what I mean:

Cursor on struct:

type User struct {
	name  string
	age   int
	email string
}

:GoCtor would generate smth like:

func NewUser(name string, age int, email string) *User {
	return &User{
		name:  name,
		age:   age,
		email: email,
	}
}

How it could work maybe:

  • Parse struct fields via treesitter (same way GoAddTag does it)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions