internal/lsp: check the client capabilities before calling workspace/configuration
Change-Id: I88d1142f4737cb74f5d6c9409218dde674dc1834 Reviewed-on: https://go-review.googlesource.com/c/tools/+/170184 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
1bac838f5b
commit
5bca5db4cb
|
@ -145,6 +145,11 @@ func (app *Application) connect(ctx context.Context, client protocol.Client) (pr
|
||||||
}
|
}
|
||||||
params := &protocol.InitializeParams{}
|
params := &protocol.InitializeParams{}
|
||||||
params.RootURI = string(span.FileURI(app.Config.Dir))
|
params.RootURI = string(span.FileURI(app.Config.Dir))
|
||||||
|
params.Capabilities = map[string]interface{}{
|
||||||
|
"workspace": map[string]interface{}{
|
||||||
|
"configuration": true,
|
||||||
|
},
|
||||||
|
}
|
||||||
if _, err := server.Initialize(ctx, params); err != nil {
|
if _, err := server.Initialize(ctx, params); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,8 @@ type Server struct {
|
||||||
|
|
||||||
signatureHelpEnabled bool
|
signatureHelpEnabled bool
|
||||||
snippetsSupported bool
|
snippetsSupported bool
|
||||||
|
configurationSupported bool
|
||||||
|
dynamicConfigurationSupported bool
|
||||||
|
|
||||||
textDocumentSyncKind protocol.TextDocumentSyncKind
|
textDocumentSyncKind protocol.TextDocumentSyncKind
|
||||||
|
|
||||||
|
@ -110,6 +112,18 @@ func (s *Server) Initialize(ctx context.Context, params *protocol.InitializePara
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Check if the client supports configuration messages.
|
||||||
|
if x, ok := params.Capabilities["workspace"].(map[string]interface{}); ok {
|
||||||
|
if x, ok := x["configuration"].(bool); ok {
|
||||||
|
s.configurationSupported = x
|
||||||
|
}
|
||||||
|
if x, ok := x["didChangeConfiguration"].(map[string]interface{}); ok {
|
||||||
|
if x, ok := x["dynamicRegistration"].(bool); ok {
|
||||||
|
s.dynamicConfigurationSupported = x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
s.signatureHelpEnabled = true
|
s.signatureHelpEnabled = true
|
||||||
|
|
||||||
// TODO(rstambler): Change this default to protocol.Incremental (or add a
|
// TODO(rstambler): Change this default to protocol.Incremental (or add a
|
||||||
|
@ -182,12 +196,15 @@ func (s *Server) Initialize(ctx context.Context, params *protocol.InitializePara
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Initialized(ctx context.Context, params *protocol.InitializedParams) error {
|
func (s *Server) Initialized(ctx context.Context, params *protocol.InitializedParams) error {
|
||||||
|
if s.configurationSupported {
|
||||||
|
if s.dynamicConfigurationSupported {
|
||||||
s.client.RegisterCapability(ctx, &protocol.RegistrationParams{
|
s.client.RegisterCapability(ctx, &protocol.RegistrationParams{
|
||||||
Registrations: []protocol.Registration{{
|
Registrations: []protocol.Registration{{
|
||||||
ID: "workspace/didChangeConfiguration",
|
ID: "workspace/didChangeConfiguration",
|
||||||
Method: "workspace/didChangeConfiguration",
|
Method: "workspace/didChangeConfiguration",
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
|
}
|
||||||
for _, view := range s.views {
|
for _, view := range s.views {
|
||||||
config, err := s.client.Configuration(ctx, &protocol.ConfigurationParams{
|
config, err := s.client.Configuration(ctx, &protocol.ConfigurationParams{
|
||||||
Items: []protocol.ConfigurationItem{{
|
Items: []protocol.ConfigurationItem{{
|
||||||
|
@ -202,6 +219,7 @@ func (s *Server) Initialized(ctx context.Context, params *protocol.InitializedPa
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue