Skip to content

Commit

Permalink
fix: display error message when required gopls binary not found on th…
Browse files Browse the repository at this point in the history
…e path, fixes #29
  • Loading branch information
a-h committed Oct 31, 2021
1 parent 64897d9 commit 60b8ccb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/templ/lspcmd/pls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pls

import (
"context"
"errors"
"fmt"
"io"
"os/exec"
Expand Down Expand Up @@ -30,6 +31,14 @@ func (opts Options) AsArguments() []string {

// NewGopls starts gopls and opens up a jsonrpc2 connection to it.
func NewGopls(ctx context.Context, zapLogger *zap.Logger, onGoplsRequest func(ctx context.Context, conn *jsonrpc2.Conn, r *jsonrpc2.Request), opts Options) (conn *jsonrpc2.Conn, err error) {
_, err = exec.LookPath("gopls")
if errors.Is(err, exec.ErrNotFound) {
err = errors.New("templ lsp: cannot find gopls on the path, you can install it with `go install golang.org/x/tools/gopls@latest`")
return
}
if err != nil {
return
}
cmd := exec.Command("gopls", opts.AsArguments()...)
rwc, err := newProcessReadWriteCloser(zapLogger, cmd)
if err != nil {
Expand Down

0 comments on commit 60b8ccb

Please sign in to comment.