@@ -5,14 +5,10 @@ import (
55 "errors"
66 "fmt"
77 "io"
8- "os"
9- "os/exec"
10- "os/signal"
118 "runtime/debug"
129 "slices"
1310 "sync"
1411 "sync/atomic"
15- "syscall"
1612 "time"
1713
1814 "github.com/go-json-experiment/json"
@@ -39,6 +35,7 @@ type ServerOptions struct {
3935 DefaultLibraryPath string
4036 TypingsLocation string
4137 ParseCache * project.ParseCache
38+ NpmInstall func (cwd string , args []string ) ([]byte , error )
4239}
4340
4441func NewServer (opts * ServerOptions ) * Server {
@@ -59,6 +56,7 @@ func NewServer(opts *ServerOptions) *Server {
5956 defaultLibraryPath : opts .DefaultLibraryPath ,
6057 typingsLocation : opts .TypingsLocation ,
6158 parseCache : opts .ParseCache ,
59+ npmInstall : opts .NpmInstall ,
6260 }
6361}
6462
@@ -157,6 +155,8 @@ type Server struct {
157155 compilerOptionsForInferredProjects * core.CompilerOptions
158156 // parseCache can be passed in so separate tests can share ASTs
159157 parseCache * project.ParseCache
158+
159+ npmInstall func (cwd string , args []string ) ([]byte , error )
160160}
161161
162162// WatchFiles implements project.Client.
@@ -218,10 +218,7 @@ func (s *Server) RefreshDiagnostics(ctx context.Context) error {
218218 return nil
219219}
220220
221- func (s * Server ) Run () error {
222- ctx , stop := signal .NotifyContext (context .Background (), os .Interrupt , syscall .SIGTERM )
223- defer stop ()
224-
221+ func (s * Server ) Run (ctx context.Context ) error {
225222 g , ctx := errgroup .WithContext (ctx )
226223 g .Go (func () error { return s .dispatchLoop (ctx ) })
227224 g .Go (func () error { return s .writeLoop (ctx ) })
@@ -877,9 +874,7 @@ func (s *Server) SetCompilerOptionsForInferredProjects(ctx context.Context, opti
877874
878875// NpmInstall implements ata.NpmExecutor
879876func (s * Server ) NpmInstall (cwd string , args []string ) ([]byte , error ) {
880- cmd := exec .Command ("npm" , args ... )
881- cmd .Dir = cwd
882- return cmd .Output ()
877+ return s .npmInstall (cwd , args )
883878}
884879
885880func isBlockingMethod (method lsproto.Method ) bool {
0 commit comments