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:
Ian Cottrell 2019-04-01 14:56:49 -04:00
Родитель 1bac838f5b
Коммит 5bca5db4cb
2 изменённых файлов: 42 добавлений и 19 удалений

Просмотреть файл

@ -145,6 +145,11 @@ func (app *Application) connect(ctx context.Context, client protocol.Client) (pr
}
params := &protocol.InitializeParams{}
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 {
return nil, err
}

Просмотреть файл

@ -75,8 +75,10 @@ type Server struct {
initializedMu sync.Mutex
initialized bool // set once the server has received "initialize" request
signatureHelpEnabled bool
snippetsSupported bool
signatureHelpEnabled bool
snippetsSupported bool
configurationSupported bool
dynamicConfigurationSupported bool
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
// TODO(rstambler): Change this default to protocol.Incremental (or add a
@ -182,24 +196,28 @@ func (s *Server) Initialize(ctx context.Context, params *protocol.InitializePara
}
func (s *Server) Initialized(ctx context.Context, params *protocol.InitializedParams) error {
s.client.RegisterCapability(ctx, &protocol.RegistrationParams{
Registrations: []protocol.Registration{{
ID: "workspace/didChangeConfiguration",
Method: "workspace/didChangeConfiguration",
}},
})
for _, view := range s.views {
config, err := s.client.Configuration(ctx, &protocol.ConfigurationParams{
Items: []protocol.ConfigurationItem{{
ScopeURI: protocol.NewURI(view.Folder),
Section: "gopls",
}},
})
if err != nil {
return err
if s.configurationSupported {
if s.dynamicConfigurationSupported {
s.client.RegisterCapability(ctx, &protocol.RegistrationParams{
Registrations: []protocol.Registration{{
ID: "workspace/didChangeConfiguration",
Method: "workspace/didChangeConfiguration",
}},
})
}
if err := s.processConfig(view, config[0]); err != nil {
return err
for _, view := range s.views {
config, err := s.client.Configuration(ctx, &protocol.ConfigurationParams{
Items: []protocol.ConfigurationItem{{
ScopeURI: protocol.NewURI(view.Folder),
Section: "gopls",
}},
})
if err != nil {
return err
}
if err := s.processConfig(view, config[0]); err != nil {
return err
}
}
}
return nil