@@ -11,6 +11,7 @@ import (
1111 "os/exec"
1212 "runtime"
1313 "strings"
14+ "sync"
1415
1516 "github.com/a-h/templ"
1617 "github.com/a-h/templ/cmd/templ/lspcmd/pls"
@@ -25,39 +26,42 @@ type Info struct {
2526 GOOS string `json:"goos"`
2627 GOARCH string `json:"goarch"`
2728 } `json:"os"`
28- Go ToolInfo `json:"go"`
29- Gopls ToolInfo `json:"gopls"`
30- Templ ToolInfo `json:"templ"`
29+ Go ToolInfo `json:"go"`
30+ Gopls ToolInfo `json:"gopls"`
31+ Templ ToolInfo `json:"templ"`
32+ Prettier ToolInfo `json:"prettier"`
3133}
3234
3335type ToolInfo struct {
34- Location string `json:"location"`
35- Version string `json:"version"`
36- OK bool `json:"ok "`
37- Message string `json:"message,omitempty"`
36+ Location string `json:"location"`
37+ Version string `json:"version"`
38+ Level slog. Level `json:"level "`
39+ Message string `json:"message,omitempty"`
3840}
3941
4042func getGoInfo () (d ToolInfo ) {
41- // Find Go.
43+ d .Level = slog .LevelError
44+
4245 var err error
4346 d .Location , err = exec .LookPath ("go" )
4447 if err != nil {
4548 d .Message = fmt .Sprintf ("failed to find go: %v" , err )
4649 return
4750 }
48- // Run go to find the version.
4951 cmd := exec .Command (d .Location , "version" )
5052 v , err := cmd .Output ()
5153 if err != nil {
5254 d .Message = fmt .Sprintf ("failed to get go version, check that Go is installed: %v" , err )
5355 return
5456 }
5557 d .Version = strings .TrimSpace (string (v ))
56- d .OK = true
58+ d .Level = slog . LevelInfo
5759 return
5860}
5961
6062func getGoplsInfo () (d ToolInfo ) {
63+ d .Level = slog .LevelError
64+
6165 var err error
6266 d .Location , err = pls .FindGopls ()
6367 if err != nil {
@@ -71,19 +75,19 @@ func getGoplsInfo() (d ToolInfo) {
7175 return
7276 }
7377 d .Version = strings .TrimSpace (string (v ))
74- d .OK = true
78+ d .Level = slog . LevelInfo
7579 return
7680}
7781
7882func getTemplInfo () (d ToolInfo ) {
79- // Find templ.
83+ d .Level = slog .LevelError
84+
8085 var err error
8186 d .Location , err = findTempl ()
8287 if err != nil {
8388 d .Message = err .Error ()
8489 return
8590 }
86- // Run templ to find the version.
8791 cmd := exec .Command (d .Location , "version" )
8892 v , err := cmd .Output ()
8993 if err != nil {
@@ -95,7 +99,7 @@ func getTemplInfo() (d ToolInfo) {
9599 d .Message = fmt .Sprintf ("version mismatch - you're running %q at the command line, but the version in the path is %q" , templ .Version (), d .Version )
96100 return
97101 }
98- d .OK = true
102+ d .Level = slog . LevelInfo
99103 return
100104}
101105
@@ -118,12 +122,49 @@ func findTempl() (location string, err error) {
118122 return "" , fmt .Errorf ("templ is not in the path (%q). You can install templ with `go install github.com/a-h/templ/cmd/templ@latest`" , os .Getenv ("PATH" ))
119123}
120124
125+ func getPrettierInfo () (d ToolInfo ) {
126+ d .Level = slog .LevelWarn
127+
128+ var err error
129+ d .Location , err = exec .LookPath ("prettier" )
130+ if err != nil {
131+ d .Message = fmt .Sprintf ("failed to find prettier: %v" , err )
132+ return
133+ }
134+ cmd := exec .Command (d .Location , "--version" )
135+ v , err := cmd .Output ()
136+ if err != nil {
137+ d .Message = fmt .Sprintf ("failed to get prettier version: %v" , err )
138+ return
139+ }
140+ d .Version = strings .TrimSpace (string (v ))
141+ d .Level = slog .LevelInfo
142+ return
143+ }
144+
121145func getInfo () (d Info ) {
122146 d .OS .GOOS = runtime .GOOS
123147 d .OS .GOARCH = runtime .GOARCH
124- d .Go = getGoInfo ()
125- d .Gopls = getGoplsInfo ()
126- d .Templ = getTemplInfo ()
148+
149+ var wg sync.WaitGroup
150+ wg .Add (4 )
151+ go func () {
152+ defer wg .Done ()
153+ d .Go = getGoInfo ()
154+ }()
155+ go func () {
156+ defer wg .Done ()
157+ d .Gopls = getGoplsInfo ()
158+ }()
159+ go func () {
160+ defer wg .Done ()
161+ d .Templ = getTemplInfo ()
162+ }()
163+ go func () {
164+ defer wg .Done ()
165+ d .Prettier = getPrettierInfo ()
166+ }()
167+ wg .Wait ()
127168 return
128169}
129170
@@ -138,20 +179,17 @@ func Run(ctx context.Context, log *slog.Logger, stdout io.Writer, args Arguments
138179 logInfo (ctx , log , "go" , info .Go )
139180 logInfo (ctx , log , "gopls" , info .Gopls )
140181 logInfo (ctx , log , "templ" , info .Templ )
182+ logInfo (ctx , log , "prettier" , info .Prettier )
141183 return nil
142184}
143185
144186func logInfo (ctx context.Context , log * slog.Logger , name string , ti ToolInfo ) {
145- level := slog .LevelInfo
146- if ! ti .OK {
147- level = slog .LevelError
148- }
149187 args := []any {
150188 slog .String ("location" , ti .Location ),
151189 slog .String ("version" , ti .Version ),
152190 }
153191 if ti .Message != "" {
154192 args = append (args , slog .String ("message" , ti .Message ))
155193 }
156- log .Log (ctx , level , name , args ... )
194+ log .Log (ctx , ti . Level , name , args ... )
157195}
0 commit comments