mirror of https://github.com/golang/go.git
internal/lsp: only construct a cache when we need to
we only construct a cache as we build a server, rather than for each instance of Application now. Change-Id: Ic18966906f8f61b18b71fc6d6f7ccc8e9cebbd29 Reviewed-on: https://go-review.googlesource.com/c/tools/+/207904 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
4054736f96
commit
caaa49c6de
|
|
@ -45,8 +45,8 @@ type Application struct {
|
|||
// TODO: Remove this when we stop allowing the serve verb by default.
|
||||
Serve Serve
|
||||
|
||||
// The base cache to use for sessions from this application.
|
||||
cache source.Cache
|
||||
// the options configuring function to invoke when building a server
|
||||
options func(*source.Options)
|
||||
|
||||
// The name of the binary, used in help and telemetry.
|
||||
name string
|
||||
|
|
@ -77,7 +77,7 @@ func New(name, wd string, env []string, options func(*source.Options)) *Applicat
|
|||
wd, _ = os.Getwd()
|
||||
}
|
||||
app := &Application{
|
||||
cache: cache.New(options),
|
||||
options: options,
|
||||
name: name,
|
||||
wd: wd,
|
||||
env: env,
|
||||
|
|
@ -165,7 +165,7 @@ func (app *Application) connect(ctx context.Context) (*connection, error) {
|
|||
switch app.Remote {
|
||||
case "":
|
||||
connection := newConnection(app)
|
||||
ctx, connection.Server = lsp.NewClientServer(ctx, app.cache, connection.Client)
|
||||
ctx, connection.Server = lsp.NewClientServer(ctx, cache.New(app.options), connection.Client)
|
||||
return connection, connection.initialize(ctx)
|
||||
case "internal":
|
||||
internalMu.Lock()
|
||||
|
|
@ -181,7 +181,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, app.cache, jsonrpc2.NewHeaderStream(sr, sw))
|
||||
ctx, srv := lsp.NewServer(ctx, cache.New(app.options), jsonrpc2.NewHeaderStream(sr, sw))
|
||||
srv.Run(ctx)
|
||||
}()
|
||||
if err := connection.initialize(ctx); err != nil {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import (
|
|||
|
||||
"golang.org/x/tools/internal/jsonrpc2"
|
||||
"golang.org/x/tools/internal/lsp"
|
||||
"golang.org/x/tools/internal/lsp/cache"
|
||||
"golang.org/x/tools/internal/lsp/debug"
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
"golang.org/x/tools/internal/lsp/telemetry"
|
||||
|
|
@ -87,16 +88,16 @@ func (s *Serve) Run(ctx context.Context, args ...string) error {
|
|||
}
|
||||
run := func(ctx context.Context, srv *lsp.Server) { go prepare(ctx, srv).Run(ctx) }
|
||||
if s.Address != "" {
|
||||
return lsp.RunServerOnAddress(ctx, s.app.cache, s.Address, run)
|
||||
return lsp.RunServerOnAddress(ctx, cache.New(s.app.options), s.Address, run)
|
||||
}
|
||||
if s.Port != 0 {
|
||||
return lsp.RunServerOnPort(ctx, s.app.cache, s.Port, run)
|
||||
return lsp.RunServerOnPort(ctx, cache.New(s.app.options), s.Port, run)
|
||||
}
|
||||
stream := jsonrpc2.NewHeaderStream(os.Stdin, os.Stdout)
|
||||
if s.Trace {
|
||||
stream = protocol.LoggingStream(stream, out)
|
||||
}
|
||||
ctx, srv := lsp.NewServer(ctx, s.app.cache, stream)
|
||||
ctx, srv := lsp.NewServer(ctx, cache.New(s.app.options), stream)
|
||||
return prepare(ctx, srv).Run(ctx)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue