-
Notifications
You must be signed in to change notification settings - Fork 839
parse formatting options in initialization, and pull editor scope during Configuration
#2717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
fef4cfe
2ff673e
e8e72cd
ceba8ff
1914c0c
e9481a0
1b96c37
88d467b
9426276
e7ed013
82e4b48
7780e2c
799981e
15909a1
892e2b0
0160286
20a27fb
776163d
5916c4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -284,7 +284,18 @@ func (s *Server) RefreshCodeLens(ctx context.Context) error { | |
| func (s *Server) RequestConfiguration(ctx context.Context) (*lsutil.UserConfig, error) { | ||
| caps := lsproto.GetClientCapabilities(ctx) | ||
| if !caps.Workspace.Configuration { | ||
| // if no configuration request capapbility, return default config | ||
| if s.initializeParams != nil && s.initializeParams.InitializationOptions != nil && s.initializeParams.InitializationOptions.UserPreferences != nil { | ||
| s.logger.Logf( | ||
| "received formatting options from initialization: %T\n%+v", | ||
| *s.initializeParams.InitializationOptions.UserPreferences, | ||
| *s.initializeParams.InitializationOptions.UserPreferences, | ||
| ) | ||
| // Any options received via initializationOptions will be used for both `js` and `ts` options | ||
| if config, ok := (*s.initializeParams.InitializationOptions.UserPreferences).(map[string]any); ok { | ||
| return lsutil.NewUserConfig(lsutil.NewDefaultUserPreferences().ParseWorker(config)), nil | ||
| } | ||
| } | ||
| // if no configuration request capability, return default config | ||
| return lsutil.NewUserConfig(nil), nil | ||
| } | ||
| configs, err := sendClientRequest(ctx, s, lsproto.WorkspaceConfigurationInfo, &lsproto.ConfigurationParams{ | ||
|
|
@@ -298,12 +309,35 @@ func (s *Server) RequestConfiguration(ctx context.Context) (*lsutil.UserConfig, | |
| { | ||
| Section: new("javascript"), | ||
| }, | ||
| { | ||
| Section: new("editor"), | ||
| }, | ||
iisaduan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }) | ||
| if err != nil { | ||
| return &lsutil.UserConfig{}, fmt.Errorf("configure request failed: %w", err) | ||
| } | ||
| return lsutil.ParseNewUserConfig(configs), nil | ||
| configMap := map[string]any{} | ||
| for i, config := range configs { | ||
| switch i { | ||
| case 0: | ||
| configMap["js/ts"] = config | ||
| case 1: | ||
| configMap["typescript"] = config | ||
| case 2: | ||
| configMap["javascript"] = config | ||
| case 3: | ||
| configMap["editor"] = config | ||
| } | ||
| } | ||
| s.logger.Logf( | ||
| "received options from workspace/configuration request:\njs/ts: %+v\n\ntypescript: %+v\n\njavascript: %+v\n\neditor: %+v\n", | ||
| configMap["js/ts"], | ||
| configMap["typescript"], | ||
| configMap["javascript"], | ||
| configMap["editor"], | ||
| ) | ||
| return lsutil.ParseNewUserConfig(configMap), nil | ||
| } | ||
|
|
||
| func (s *Server) Run(ctx context.Context) error { | ||
|
|
@@ -1049,7 +1083,7 @@ func (s *Server) handleInitialized(ctx context.Context, params *lsproto.Initiali | |
| RegisterOptions: &lsproto.RegisterOptions{ | ||
| DidChangeConfiguration: &lsproto.DidChangeConfigurationRegistrationOptions{ | ||
| Section: &lsproto.StringOrStrings{ | ||
| Strings: &[]string{"js/ts", "typescript", "javascript"}, | ||
| Strings: &[]string{"js/ts", "typescript", "javascript", "editor"}, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
@@ -1081,14 +1115,10 @@ func (s *Server) handleExit(ctx context.Context, params any) error { | |
| } | ||
|
|
||
| func (s *Server) handleDidChangeWorkspaceConfiguration(ctx context.Context, params *lsproto.DidChangeConfigurationParams) error { | ||
| // !!! only implemented because needed for fourslash | ||
| if params.Settings == nil { | ||
| return nil | ||
| } else if settings, ok := params.Settings.([]any); ok { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this actually never send as an array?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assumed vscode would do that because that's what the response was for |
||
| s.session.Configure(lsutil.ParseNewUserConfig(settings)) | ||
| } else if settings, ok := params.Settings.(map[string]any); ok { | ||
| // fourslash case | ||
| s.session.Configure(lsutil.ParseNewUserConfig([]any{settings["js/ts"], settings["typescript"], settings["javascript"]})) | ||
| s.session.Configure(lsutil.ParseNewUserConfig(settings)) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel a little nervous about
any, but it's probably fine given how we are walking it. In the future I'd like to define a type for this (but that can probably come in my PR if I ever get around to fixing it)