internal/lsp: set initialized state
Set the server state to initialized so that dynamic configuration requests will be sent to the client. Rename the mutex that guards state. The state field was previously named initialized, so it only makes sense to similarly rename the mutex that guards the state field. Always unlock stateMu before calling other functions so that callees that need to check state can acquire the lock. Change-Id: Ia5592ca1dedfc6f004ae6b61548890624ae98d59 Reviewed-on: https://go-review.googlesource.com/c/tools/+/188097 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
a81e99d748
commit
09f9cfa882
|
@ -21,12 +21,15 @@ import (
|
|||
)
|
||||
|
||||
func (s *Server) initialize(ctx context.Context, params *protocol.InitializeParams) (*protocol.InitializeResult, error) {
|
||||
s.initializedMu.Lock()
|
||||
defer s.initializedMu.Unlock()
|
||||
if s.state >= serverInitializing {
|
||||
s.stateMu.Lock()
|
||||
state := s.state
|
||||
s.stateMu.Unlock()
|
||||
if state >= serverInitializing {
|
||||
return nil, jsonrpc2.NewErrorf(jsonrpc2.CodeInvalidRequest, "server already initialized")
|
||||
}
|
||||
s.stateMu.Lock()
|
||||
s.state = serverInitializing
|
||||
s.stateMu.Unlock()
|
||||
|
||||
// TODO: Remove the option once we are certain there are no issues here.
|
||||
s.textDocumentSyncKind = protocol.Incremental
|
||||
|
@ -127,6 +130,10 @@ func (s *Server) setClientCapabilities(caps protocol.ClientCapabilities) {
|
|||
}
|
||||
|
||||
func (s *Server) initialized(ctx context.Context, params *protocol.InitializedParams) error {
|
||||
s.stateMu.Lock()
|
||||
s.state = serverInitialized
|
||||
s.stateMu.Unlock()
|
||||
|
||||
if s.configurationSupported {
|
||||
if s.dynamicConfigurationSupported {
|
||||
s.client.RegisterCapability(ctx, &protocol.RegistrationParams{
|
||||
|
@ -249,8 +256,8 @@ func (s *Server) processConfig(ctx context.Context, view source.View, config int
|
|||
}
|
||||
|
||||
func (s *Server) shutdown(ctx context.Context) error {
|
||||
s.initializedMu.Lock()
|
||||
defer s.initializedMu.Unlock()
|
||||
s.stateMu.Lock()
|
||||
defer s.stateMu.Unlock()
|
||||
if s.state < serverInitialized {
|
||||
return jsonrpc2.NewErrorf(jsonrpc2.CodeInvalidRequest, "server not initialized")
|
||||
}
|
||||
|
@ -261,6 +268,8 @@ func (s *Server) shutdown(ctx context.Context) error {
|
|||
}
|
||||
|
||||
func (s *Server) exit(ctx context.Context) error {
|
||||
s.stateMu.Lock()
|
||||
defer s.stateMu.Unlock()
|
||||
if s.state != serverShutDown {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -73,8 +73,8 @@ type Server struct {
|
|||
Conn *jsonrpc2.Conn
|
||||
client protocol.Client
|
||||
|
||||
initializedMu sync.Mutex
|
||||
state serverState
|
||||
stateMu sync.Mutex
|
||||
state serverState
|
||||
|
||||
// Configurations.
|
||||
// TODO(rstambler): Separate these into their own struct?
|
||||
|
|
|
@ -32,7 +32,10 @@ func (s *Server) changeFolders(ctx context.Context, event protocol.WorkspaceFold
|
|||
|
||||
func (s *Server) addView(ctx context.Context, name string, uri span.URI) error {
|
||||
view := s.session.NewView(ctx, name, uri)
|
||||
if s.state >= serverInitialized {
|
||||
s.stateMu.Lock()
|
||||
state := s.state
|
||||
s.stateMu.Unlock()
|
||||
if state >= serverInitialized {
|
||||
s.fetchConfig(ctx, view)
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue