Customize debugger values presentation?

Answered

hi

Doesn't golang IDE have Customize debugger presentation?
Jetbrain Rider has a feature
https://www.jetbrains.com/help/rider/Inspecting_Variables.html#pinned_items
I wish golang had this feature too.
Or, if the string() function is declared like visual code, I want it to be expressed in the watch expression.

thanks a lot

2
4 comments

Hi,

Pin to top action is not implemented in GoLand yet, please see and follow GO-9922.

You can emulate Stringer.String() in the debugger, please see examples and limitations here (blog post).

I hope it helps.

0

I used the string() function you told me. But even with a little modification, it doesn't work.

func (u User) String() string {
//if u.company == nil {
// return fmt.Sprintf("%s <%s> (nil)", u.name, u.email)
//}
return fmt.Sprintf("%s <%s> (%s)", u.name, u.email, u.company.name)
}

func main() {
u := User{"Joe", "joe@acme.com", nil} //<--- company is null
println(u.String()) //breakpoint
}

As you can see above, if you put nil in compay, it doesn't work.

Error handling for nil does not work. In this case, it cannot be used in actual debugging.

Is there something I'm using wrong?

0

Currently, only methods with a single return statement without any logic (including flow conditions) are supported. The closest ticket is GO-7821.

As a workaround, you can evaluate u.String() in the debugger manually (Evaluate Expression action).

0

I've extracted a case with flow conditionals to a new ticket. Please follow GO-11692 as well.

0

Please sign in to leave a comment.