incu6us / goimports-reviser

Right imports sorting & code formatting tool (goimports alternative)
MIT License
607 stars 72 forks source link

Support workspaces #154

Open ghost opened 7 months ago

ghost commented 7 months ago

goimports-reviser can operate only on files in a Go module, but Go workspaces allow one to write files outside of modules and use the dependencies listed in the module.

To reproduce:

mkdir analysis lib

cat >analysis/main.go <<EOF
package main

import "example.com/hello"

func main() {
  println(hello.Hello("you"))
}
EOF

cat  >go.work <<EOF
go 1.22.2

use ./lib
EOF

cat >lib/lib.go <<EOF
package hello

func Hello(who string) string {
  return "Hello " + who + "!"
}
EOF

cat >lib/go.mod <<EOF
module example.com/hello

go 1.22.1
EOF

# To run the main program:
# go run analysis/main.go

# Revise imports:
goimports-reviser analysis/main.go

Result:

open go.mod: no such file or directory

Usage of .../goimports-reviser:
...