-
Notifications
You must be signed in to change notification settings - Fork 714
userpreferences parsing/ls config handing #1729
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 3 commits
2ace8fe
dbfff26
ff140e9
186e6d5
db2f039
c7474b5
54168cb
0dff9de
3fc7b27
aa26910
3febabd
8c33d22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,6 +217,101 @@ func (s *Server) RefreshDiagnostics(ctx context.Context) error { | |
return nil | ||
} | ||
|
||
func (s *Server) Configure(ctx context.Context) (*ls.UserPreferences, error) { | ||
result, err := s.sendRequest(ctx, lsproto.MethodWorkspaceConfiguration, &lsproto.ConfigurationParams{ | ||
Items: []*lsproto.ConfigurationItem{ | ||
{ | ||
Section: ptrTo("typescript"), | ||
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. Unfortunately there is also I think we're going to have to make user prefs have both variants and then return one or the other depending on the situation... |
||
}, | ||
}, | ||
}) | ||
iisaduan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return nil, fmt.Errorf("configure request failed: %w", err) | ||
} | ||
configs := result.([]any) | ||
userPreferences := &ls.UserPreferences{} | ||
for _, config := range configs { | ||
if config == nil { | ||
continue | ||
} | ||
if item, ok := config.(map[string]any); ok { | ||
for name, values := range item { | ||
switch name { | ||
case "inlayHints": | ||
iisaduan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
inlayHintsPreferences := values.(map[string]any) | ||
iisaduan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if v, ok := inlayHintsPreferences["parameterNames"].(map[string]any); ok && v != nil { | ||
if enabled, ok := v["enabled"]; ok { | ||
if enabledStr, ok := enabled.(string); ok { | ||
userPreferences.IncludeInlayParameterNameHints = enabledStr | ||
} else { | ||
userPreferences.IncludeInlayParameterNameHints = "" | ||
} | ||
} | ||
if supressWhenArgumentMatchesName, ok := v["suppressWhenArgumentMatchesName"]; ok { | ||
userPreferences.IncludeInlayParameterNameHintsWhenArgumentMatchesName = ptrTo(!supressWhenArgumentMatchesName.(bool)) | ||
iisaduan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
iisaduan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} | ||
if v, ok := inlayHintsPreferences["parameterTypes"].(map[string]any); ok && v != nil { | ||
if enabled, ok := v["enabled"]; ok { | ||
userPreferences.IncludeInlayFunctionParameterTypeHints = ptrTo(enabled.(bool)) | ||
iisaduan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} | ||
if v, ok := inlayHintsPreferences["variableTypes"].(map[string]any); ok && v != nil { | ||
if enabled, ok := v["enabled"]; ok { | ||
userPreferences.IncludeInlayVariableTypeHints = ptrTo(enabled.(bool)) | ||
} | ||
if supressWhenTypeMatchesName, ok := v["suppressWhenTypeMatchesName"]; ok { | ||
userPreferences.IncludeInlayVariableTypeHintsWhenTypeMatchesName = ptrTo(!supressWhenTypeMatchesName.(bool)) | ||
iisaduan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
iisaduan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} | ||
if v, ok := inlayHintsPreferences["propertyDeclarationTypes"].(map[string]any); ok && v != nil { | ||
if enabled, ok := v["enabled"]; ok { | ||
userPreferences.IncludeInlayPropertyDeclarationTypeHints = ptrTo(enabled.(bool)) | ||
} | ||
} | ||
if v, ok := inlayHintsPreferences["functionLikeReturnTypes"].(map[string]any); ok && v != nil { | ||
if enabled, ok := v["enabled"]; ok { | ||
userPreferences.IncludeInlayFunctionLikeReturnTypeHints = ptrTo(enabled.(bool)) | ||
} | ||
} | ||
if v, ok := inlayHintsPreferences["enumMemberValues"].(map[string]any); ok && v != nil { | ||
if enabled, ok := v["enabled"]; ok { | ||
userPreferences.IncludeInlayEnumMemberValueHints = ptrTo(enabled.(bool)) | ||
iisaduan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
iisaduan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} | ||
userPreferences.InteractiveInlayHints = ptrTo(true) | ||
case "tsserver": | ||
// !!! | ||
case "unstable": | ||
// !!! | ||
case "tsc": | ||
// !!! | ||
case "updateImportsOnFileMove": | ||
// !!! moveToFile | ||
case "preferences": | ||
// !!! | ||
case "experimental": | ||
// !!! | ||
case "organizeImports": | ||
// !!! | ||
case "importModuleSpecifierEnding": | ||
// !!! | ||
} | ||
} | ||
continue | ||
} | ||
if item, ok := config.(ls.UserPreferences); ok { | ||
// case for fourslash | ||
userPreferences = &item | ||
break | ||
} | ||
} | ||
// !!! set defaults for services, remove after extension is updated | ||
userPreferences.IncludeCompletionsForModuleExports = ptrTo(true) | ||
userPreferences.IncludeCompletionsForImportStatements = ptrTo(true) | ||
return userPreferences, nil | ||
} | ||
|
||
func (s *Server) Run() error { | ||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) | ||
defer stop() | ||
|
@@ -440,6 +535,7 @@ var handlers = sync.OnceValue(func() handlerMap { | |
registerRequestHandler(handlers, lsproto.ShutdownInfo, (*Server).handleShutdown) | ||
registerNotificationHandler(handlers, lsproto.ExitInfo, (*Server).handleExit) | ||
|
||
registerNotificationHandler(handlers, lsproto.WorkspaceDidChangeConfigurationInfo, (*Server).handleDidChangeWorkspaceConfiguration) | ||
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. This handler is set up, but I don't think the PR sets up the watch capability yet. |
||
registerNotificationHandler(handlers, lsproto.TextDocumentDidOpenInfo, (*Server).handleDidOpen) | ||
registerNotificationHandler(handlers, lsproto.TextDocumentDidChangeInfo, (*Server).handleDidChange) | ||
registerNotificationHandler(handlers, lsproto.TextDocumentDidSaveInfo, (*Server).handleDidSave) | ||
|
@@ -638,7 +734,6 @@ func (s *Server) handleInitialized(ctx context.Context, params *lsproto.Initiali | |
if shouldEnableWatch(s.initializeParams) { | ||
s.watchEnabled = true | ||
} | ||
|
||
s.session = project.NewSession(&project.SessionInit{ | ||
Options: &project.SessionOptions{ | ||
CurrentDirectory: s.cwd, | ||
|
@@ -655,6 +750,11 @@ func (s *Server) handleInitialized(ctx context.Context, params *lsproto.Initiali | |
NpmExecutor: s, | ||
ParseCache: s.parseCache, | ||
}) | ||
userPreferences, err := s.Configure(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
s.session.Configure(userPreferences) | ||
|
||
// !!! temporary; remove when we have `handleDidChangeConfiguration`/implicit project config support | ||
if s.compilerOptionsForInferredProjects != nil { | ||
s.session.DidChangeCompilerOptionsForInferredProjects(ctx, s.compilerOptionsForInferredProjects) | ||
|
@@ -672,6 +772,16 @@ func (s *Server) handleExit(ctx context.Context, params any) error { | |
return io.EOF | ||
} | ||
|
||
func (s *Server) handleDidChangeWorkspaceConfiguration(ctx context.Context, params *lsproto.DidChangeConfigurationParams) error { | ||
// !!! update user preferences | ||
// !!! only usable by fourslash | ||
if item, ok := params.Settings.(*ls.UserPreferences); ok { | ||
iisaduan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// case for fourslash | ||
s.session.Configure(item) | ||
} | ||
return nil | ||
} | ||
|
||
func (s *Server) handleDidOpen(ctx context.Context, params *lsproto.DidOpenTextDocumentParams) error { | ||
s.session.DidOpenFile(ctx, params.TextDocument.Uri, params.TextDocument.Version, params.TextDocument.Text, params.TextDocument.LanguageId) | ||
return nil | ||
|
@@ -757,10 +867,8 @@ func (s *Server) handleCompletion(ctx context.Context, languageService *ls.Langu | |
params.Position, | ||
params.Context, | ||
getCompletionClientCapabilities(s.initializeParams), | ||
&ls.UserPreferences{ | ||
IncludeCompletionsForModuleExports: ptrTo(true), | ||
IncludeCompletionsForImportStatements: ptrTo(true), | ||
}) | ||
languageService.UserPreferences(), | ||
iisaduan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
} | ||
|
||
func (s *Server) handleCompletionItemResolve(ctx context.Context, params *lsproto.CompletionItem, reqMsg *lsproto.RequestMessage) (lsproto.CompletionResolveResponse, error) { | ||
|
@@ -778,10 +886,7 @@ func (s *Server) handleCompletionItemResolve(ctx context.Context, params *lsprot | |
params, | ||
data, | ||
getCompletionClientCapabilities(s.initializeParams), | ||
&ls.UserPreferences{ | ||
IncludeCompletionsForModuleExports: ptrTo(true), | ||
IncludeCompletionsForImportStatements: ptrTo(true), | ||
}, | ||
languageService.UserPreferences(), | ||
) | ||
} | ||
|
||
|
@@ -855,7 +960,9 @@ func isBlockingMethod(method lsproto.Method) bool { | |
lsproto.MethodTextDocumentDidChange, | ||
lsproto.MethodTextDocumentDidSave, | ||
lsproto.MethodTextDocumentDidClose, | ||
lsproto.MethodWorkspaceDidChangeWatchedFiles: | ||
lsproto.MethodWorkspaceDidChangeWatchedFiles, | ||
lsproto.MethodWorkspaceDidChangeConfiguration, | ||
lsproto.MethodWorkspaceConfiguration: | ||
return true | ||
} | ||
return false | ||
|
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 do think we should move this handling to initialization. Or are going to need to handle other requests as well?
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'm not sure what we will need in the future
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 think you could imagine the fourslash client handling diagnostics refresh requests and potentially even watch requests.
Uh oh!
There was an error while loading. Please reload this page.
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.
If we're going to port the fourslash/server tests, then those probably will have to be handled?