diff --git a/internal/lsp/cmd/check_test.go b/internal/lsp/cmd/check_test.go index 7dc292e2..9f77e820 100644 --- a/internal/lsp/cmd/check_test.go +++ b/internal/lsp/cmd/check_test.go @@ -40,7 +40,11 @@ func (l diagnostics) test(t *testing.T, e *packagestest.Exported) { if len(want) == 1 && want[0].Message == "" { continue } - args := []string{"check", fname} + args := []string{} + if *internalPipe { + args = append(args, "-remote=internal") + } + args = append(args, "check", fname) app := &cmd.Application{} app.Config = *e.Config out := captureStdOut(t, func() { diff --git a/internal/lsp/cmd/cmd.go b/internal/lsp/cmd/cmd.go index afdc7819..e664cd11 100644 --- a/internal/lsp/cmd/cmd.go +++ b/internal/lsp/cmd/cmd.go @@ -119,7 +119,15 @@ func (app *Application) commands() []tool.Application { func (app *Application) connect(ctx context.Context, client protocol.Client) (protocol.Server, error) { var server protocol.Server - if app.Remote != "" { + switch app.Remote { + case "": + server = lsp.NewServer(client) + case "internal": + cr, sw, _ := os.Pipe() + sr, cw, _ := os.Pipe() + _, server = protocol.RunClient(ctx, jsonrpc2.NewHeaderStream(cr, cw), client) + go lsp.RunServer(ctx, jsonrpc2.NewHeaderStream(sr, sw)) + default: conn, err := net.Dial("tcp", app.Remote) if err != nil { return nil, err @@ -129,8 +137,6 @@ func (app *Application) connect(ctx context.Context, client protocol.Client) (pr if err != nil { return nil, err } - } else { - server = lsp.NewServer(client) } params := &protocol.InitializeParams{} params.RootURI = string(span.FileURI(app.Config.Dir)) diff --git a/internal/lsp/cmd/cmd_test.go b/internal/lsp/cmd/cmd_test.go index 8a565871..b67866ea 100644 --- a/internal/lsp/cmd/cmd_test.go +++ b/internal/lsp/cmd/cmd_test.go @@ -5,6 +5,7 @@ package cmd_test import ( + "flag" "io/ioutil" "os" "strings" @@ -23,6 +24,8 @@ const ( expectedFormatCount = 4 ) +var internalPipe = flag.Bool("pipe", false, "connect the command line client to a server through a pipe") + func TestCommandLine(t *testing.T) { packagestest.TestAll(t, testCommandLine) }