mirror of
https://github.com/golang/go
synced 2024-11-18 18:44:42 -07:00
internal/lsp: remove the Context argument from NewSession
The passed-in Context is not used, and creates the illusion of a startup dependency problem: existing code is careful to pass in the context containing the correct Client instance. This allows passing in a source.Session, rather than a source.Cache, into lsp server constructors. Updates golang/go#34111 Change-Id: I081ad6fa800b846b63e04d7164577e3a32966704 Reviewed-on: https://go-review.googlesource.com/c/tools/+/215740 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
29f64efd55
commit
78d067421b
2
internal/lsp/cache/cache.go
vendored
2
internal/lsp/cache/cache.go
vendored
@ -73,7 +73,7 @@ func (c *cache) GetFile(uri span.URI) source.FileHandle {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *cache) NewSession(ctx context.Context) source.Session {
|
||||
func (c *cache) NewSession() source.Session {
|
||||
index := atomic.AddInt64(&sessionIndex, 1)
|
||||
s := &session{
|
||||
cache: c,
|
||||
|
@ -40,7 +40,7 @@ func TestCapabilities(t *testing.T) {
|
||||
params.Capabilities.Workspace.Configuration = true
|
||||
|
||||
// Send an initialize request to the server.
|
||||
ctx, c.Server = lsp.NewClientServer(ctx, cache.New(app.options), c.Client)
|
||||
ctx, c.Server = lsp.NewClientServer(ctx, cache.New(app.options).NewSession(), c.Client)
|
||||
result, err := c.Server.Initialize(ctx, params)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -192,7 +192,7 @@ func (app *Application) connect(ctx context.Context) (*connection, error) {
|
||||
switch app.Remote {
|
||||
case "":
|
||||
connection := newConnection(app)
|
||||
ctx, connection.Server = lsp.NewClientServer(ctx, cache.New(app.options), connection.Client)
|
||||
ctx, connection.Server = lsp.NewClientServer(ctx, cache.New(app.options).NewSession(), connection.Client)
|
||||
return connection, connection.initialize(ctx, app.options)
|
||||
case "internal":
|
||||
internalMu.Lock()
|
||||
@ -208,7 +208,7 @@ func (app *Application) connect(ctx context.Context) (*connection, error) {
|
||||
ctx, jc, connection.Server = protocol.NewClient(ctx, jsonrpc2.NewHeaderStream(cr, cw), connection.Client)
|
||||
go jc.Run(ctx)
|
||||
go func() {
|
||||
ctx, srv := lsp.NewServer(ctx, cache.New(app.options), jsonrpc2.NewHeaderStream(sr, sw))
|
||||
ctx, srv := lsp.NewServer(ctx, cache.New(app.options).NewSession(), jsonrpc2.NewHeaderStream(sr, sw))
|
||||
srv.Run(ctx)
|
||||
}()
|
||||
if err := connection.initialize(ctx, app.options); err != nil {
|
||||
|
@ -97,7 +97,7 @@ func (s *Serve) Run(ctx context.Context, args ...string) error {
|
||||
if s.Trace {
|
||||
stream = protocol.LoggingStream(stream, out)
|
||||
}
|
||||
ctx, srv := lsp.NewServer(ctx, cache.New(s.app.options), stream)
|
||||
ctx, srv := lsp.NewServer(ctx, cache.New(s.app.options).NewSession(), stream)
|
||||
return prepare(ctx, srv).Run(ctx)
|
||||
}
|
||||
|
||||
|
@ -140,6 +140,7 @@ func (r *runner) RunGoplsCmd(t testing.TB, args ...string) (string, string) {
|
||||
return string(stdout), string(stderr)
|
||||
}
|
||||
|
||||
// NormalizeGoplsCmd runs the gopls command and normalizes its output.
|
||||
func (r *runner) NormalizeGoplsCmd(t testing.TB, args ...string) (string, string) {
|
||||
stdout, stderr := r.RunGoplsCmd(t, args...)
|
||||
return r.Normalize(stdout), r.Normalize(stderr)
|
||||
|
@ -52,7 +52,7 @@ func testLSP(t *testing.T, exporter packagestest.Exporter) {
|
||||
defer data.Exported.Cleanup()
|
||||
|
||||
cache := cache.New(nil)
|
||||
session := cache.NewSession(ctx)
|
||||
session := cache.NewSession()
|
||||
options := tests.DefaultOptions()
|
||||
session.SetOptions(options)
|
||||
options.Env = data.Config.Env
|
||||
@ -928,7 +928,7 @@ func TestModfileSuggestedFixes(t *testing.T) {
|
||||
|
||||
ctx := tests.Context(t)
|
||||
cache := cache.New(nil)
|
||||
session := cache.NewSession(ctx)
|
||||
session := cache.NewSession()
|
||||
options := tests.DefaultOptions()
|
||||
options.TempModfile = true
|
||||
options.Env = append(os.Environ(), "GOPACKAGESDRIVER=off", "GOROOT=")
|
||||
|
@ -29,7 +29,7 @@ func TestMain(m *testing.M) {
|
||||
func TestModfileRemainsUnchanged(t *testing.T) {
|
||||
ctx := tests.Context(t)
|
||||
cache := cache.New(nil)
|
||||
session := cache.NewSession(ctx)
|
||||
session := cache.NewSession()
|
||||
options := tests.DefaultOptions()
|
||||
options.TempModfile = true
|
||||
options.Env = append(os.Environ(), "GOPACKAGESDRIVER=off", "GOROOT=")
|
||||
@ -67,7 +67,7 @@ func TestModfileRemainsUnchanged(t *testing.T) {
|
||||
func TestDiagnostics(t *testing.T) {
|
||||
ctx := tests.Context(t)
|
||||
cache := cache.New(nil)
|
||||
session := cache.NewSession(ctx)
|
||||
session := cache.NewSession()
|
||||
options := tests.DefaultOptions()
|
||||
options.TempModfile = true
|
||||
options.Env = append(os.Environ(), "GOPACKAGESDRIVER=off", "GOROOT=")
|
||||
|
@ -18,23 +18,23 @@ import (
|
||||
)
|
||||
|
||||
// NewClientServer
|
||||
func NewClientServer(ctx context.Context, cache source.Cache, client protocol.Client) (context.Context, *Server) {
|
||||
func NewClientServer(ctx context.Context, session source.Session, client protocol.Client) (context.Context, *Server) {
|
||||
ctx = protocol.WithClient(ctx, client)
|
||||
return ctx, &Server{
|
||||
client: client,
|
||||
session: cache.NewSession(ctx),
|
||||
session: session,
|
||||
delivered: make(map[span.URI]sentDiagnostics),
|
||||
}
|
||||
}
|
||||
|
||||
// NewServer starts an LSP server on the supplied stream, and waits until the
|
||||
// stream is closed.
|
||||
func NewServer(ctx context.Context, cache source.Cache, stream jsonrpc2.Stream) (context.Context, *Server) {
|
||||
// NewServer creates an LSP server and binds it to handle incoming client
|
||||
// messages on on the supplied stream.
|
||||
func NewServer(ctx context.Context, session source.Session, stream jsonrpc2.Stream) (context.Context, *Server) {
|
||||
s := &Server{
|
||||
delivered: make(map[span.URI]sentDiagnostics),
|
||||
session: session,
|
||||
}
|
||||
ctx, s.Conn, s.client = protocol.NewServer(ctx, stream, s)
|
||||
s.session = cache.NewSession(ctx)
|
||||
return ctx, s
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ func RunServerOnAddress(ctx context.Context, cache source.Cache, addr string, h
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h(NewServer(ctx, cache, jsonrpc2.NewHeaderStream(conn, conn)))
|
||||
h(NewServer(ctx, cache.NewSession(), jsonrpc2.NewHeaderStream(conn, conn)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ func testSource(t *testing.T, exporter packagestest.Exporter) {
|
||||
defer data.Exported.Cleanup()
|
||||
|
||||
cache := cache.New(nil)
|
||||
session := cache.NewSession(ctx)
|
||||
session := cache.NewSession()
|
||||
options := tests.DefaultOptions()
|
||||
options.Env = data.Config.Env
|
||||
view, _, err := session.NewView(ctx, "source_test", span.FileURI(data.Config.Dir), options)
|
||||
|
@ -215,7 +215,7 @@ type Cache interface {
|
||||
FileSystem
|
||||
|
||||
// NewSession creates a new Session manager and returns it.
|
||||
NewSession(ctx context.Context) Session
|
||||
NewSession() Session
|
||||
|
||||
// FileSet returns the shared fileset used by all files in the system.
|
||||
FileSet() *token.FileSet
|
||||
|
Loading…
Reference in New Issue
Block a user