Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

Editor breaks import path when Go module replacements are used #2572

Closed
@andig

Description

@andig

My code contains various imports:

import (
    "fmt"
    "log"
    "os"
    "strconv"

    "github.com/crabmusket/gosunspec"
    bus "github.com/crabmusket/gosunspec/modbus"
    _ "github.com/crabmusket/gosunspec/models" // import models

    "github.com/grid-x/modbus"
)

I'm also using the types imported from gosunspec in main.go:

in.Do(func(d sunspec.Device) {
	d.Do(func(m sunspec.Model) {
        ...
	})
})

Using go.mod, I have to temporarily replace crabmusket/gosunspec with a custom fork until an upstream issue is resolved:

module github.com/volkszaehler/mbmd

require (
    github.com/crabmusket/gosunspec v0.0.0-20170310004250-4c2adf6161ca
    github.com/eclipse/paho.mqtt.golang v1.2.0
    github.com/goburrow/modbus v0.1.0 // indirect
    github.com/goburrow/serial v0.1.0 // indirect
    ...
)

replace github.com/crabmusket/gosunspec => github.com/andig/gosunspec v0.0.0-20190613063246-3c54c2ccb77a

Now, when editing main.go, two things are happening:

  1. vscode modifies the "github.com/crabmusket/gosunspec" import into the "github.com/andig/gosunspec" replacement
  2. subsequently "github.com/andig/gosunspec" is added to go.mod (I assume rather by go than by vscode)

Synopsis if types are part of a replacement package, import path must match the replaced package instead of the replacement package.

Full source is available in https://github.com/andig/mbmd/blob/scan-sunspec/cmd/scan/main.go

Metadata

Metadata

Assignees

No one assigned

    Labels

    go-modulesRelated to Go modules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions