Search code examples
vim-go

don't work command :GoDef in vim-go project


when i move cursor on function or variable in project and run :GoDef command nothing happen.

project have 37000 lines code. this problem dos not exist in every project directory!

move cursor on dto.PaginationRequest and run :GoDef expecting move cursor to deffinition of PaginationRequest but nothing happen when run :GoDef.

package controller
...
func (c *sessionController) GetAllSession(ctx *gin.Context) {
    var req dto.PaginationRequest
    if err := ctx.ShouldBind(&req); err != nil {
        res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_DATA_FROM_BODY, err.Error(), nil)
        ctx.AbortWithStatusJSON(http.StatusBadRequest, res)
        return
    }
    ...
}
...

deffination of PaginationRequest

package dto
type PaginationRequest struct {
    Page    int    `json:"page" form:"page" binding:"-"`
    Search  string `json:"search" form:"search" binding:"-"`
    PerPage int    `json:"per_page" form:"per_page" binding:"-"`
}

project directories:

.
├── Dockerfile
├── controller
│   ├── coupon-controller.go
│   └── session-controller.go
├── dto
│   ├── coupon-dto.go
│   ├── pagination.go
│   └── session-dto.go
...
└── main.go

Solution

  • I just updated gopls with the following command and fix that :)

    go install golang.org/x/tools/gopls@latest