Skip to content

x/tools/gopls: show fmt.Stringer representation of a const on mouse over  #61838

Open
@biohazduck

Description

@biohazduck

What did you do?

Moused over Meters or any of the other consts.

package si

type Distance int64

const (
      Nanometers  = 1
      Micrometers = 1000 * Nanometers
      Millimeters = 1000 * Micrometers
      Meters      = 1000 * Millimeters
)

// String pretty formats the units to a reasonable human readable representation i.e. "100m", "500nm", 
func (v Velocity) String() string {
      return formatWithBase(v, baseNano, 'm')
}

What did you expect to see?

What I want is what is currently done today with the time.Duration type:
image

I understand this implies a HUGE change to gopls, since it would mean somehow running arbitrary code. This carries some worrysome implications:

  • Security risk
  • How to implement this without exploding gopls binary size
  • Recursive risk

I'd understand if this cannot be done today, however I want to start the discussion since this would be a large quality of life improvement for me since I regularly work with SI unit consts to define program behaviour.

I'd also like to refer you all the TinyGo interp package which safely evaluates Go code on initialization: https://github.com/tinygo-org/tinygo/tree/release/interp.

What did you see instead?

Got very long numbers which are not immediately interpretable, much less when defining other more complex consts with the Distance type.
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions