MCPcopy
hub / github.com/wavetermdev/waveterm / ResolveGoFmtPath

Function ResolveGoFmtPath

pkg/waveapputil/waveapputil.go:30–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28}
29
30func ResolveGoFmtPath() (string, error) {
31 settings := wconfig.GetWatcher().GetFullConfig().Settings
32 goPath := settings.TsunamiGoPath
33
34 if goPath == "" {
35 var err error
36 goPath, err = build.FindGoExecutable()
37 if err != nil {
38 return "", err
39 }
40 }
41
42 goDir := filepath.Dir(goPath)
43 gofmtName := "gofmt"
44 if runtime.GOOS == "windows" {
45 gofmtName = "gofmt.exe"
46 }
47 gofmtPath := filepath.Join(goDir, gofmtName)
48
49 info, err := os.Stat(gofmtPath)
50 if err != nil {
51 return "", fmt.Errorf("gofmt not found at %s: %w", gofmtPath, err)
52 }
53
54 if info.IsDir() {
55 return "", fmt.Errorf("gofmt path is a directory: %s", gofmtPath)
56 }
57
58 if info.Mode()&0111 == 0 {
59 return "", fmt.Errorf("gofmt is not executable: %s", gofmtPath)
60 }
61
62 return gofmtPath, nil
63}
64
65func FormatGoCode(contents []byte) []byte {
66 gofmtPath, err := ResolveGoFmtPath()

Callers 2

FormatGoFileFunction · 0.92
FormatGoCodeFunction · 0.85

Calls 5

GetWatcherFunction · 0.92
GetFullConfigMethod · 0.80
StatMethod · 0.80
ModeMethod · 0.80
IsDirMethod · 0.45

Tested by

no test coverage detected