-
Notifications
You must be signed in to change notification settings - Fork 709
fourslash userpreferences (and fetch inlay hints userpreferences from vscode) #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?
Conversation
What is needed? I would think we would just ask for the setting blocks we are interested in and watch them, from the server side (no extension code needed). |
Our The other extension changes include to make configuration happen on initialization |
I feel confused. The LSP config spec is exactly the same as asking VS Code for a setting out of JSON. Putting more code in the client is just going to make that same code repeat across editors... |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I think I see what you mean, are you asking if instead of requesting the config for one entry, "typescript"
, we request a list of preferences, one for every preference area that we expect from vscode:
result, err := s.sendRequest(ctx, lsproto.MethodWorkspaceConfiguration, &lsproto.ConfigurationParams{ | |
Items: []*lsproto.ConfigurationItem{ | |
{ | |
Section: ptrTo("typescript"), | |
}, | |
}, | |
}) | |
result, err := s.sendRequest(ctx, lsproto.MethodWorkspaceConfiguration, &lsproto.ConfigurationParams{ | |
Items: []*lsproto.ConfigurationItem{ | |
{ | |
Section: ptrTo("typescript.inlayHints"), | |
}, | |
{ | |
Section: ptrTo("typescript.preferences"), | |
}, | |
{ | |
Section: ptrTo("typescript.unstable"), | |
}, | |
.... etc | |
}, | |
}) |
and process like that?
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.
or even ask for every individual setting like "typescript.inlayHints.parameterNames.enabled"
, "typescript.inlayHints.supressWhenTypeMatchesName.enabled", etc
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.
Yes, though I think we have to also request javascript
too, and maybe even js/ts
?
Then best case, we register a config watch on them and then keep them up to date.
if item, ok := config.(map[string]any); ok { | ||
for name, values := range item { | ||
switch name { | ||
case "inlayHints": |
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 wonder if we could generate this code, maybe from the package.json
in the extension when we have that.
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.
Yeah, re: the conversation I had with jake above, I'm doing some thinking about other ways we could do this. This function as-is definitely isn't permanent
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 { |
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.
Can't we do the same kind of parsing here that we're doing in Configure
above?
if err != nil { | ||
return err | ||
} | ||
s.session.Configure(userPreferences) |
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.
Don't we also need to register with the client here to be able to actually get config change notifications? Just like we do in WatchFiles
.
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.
Re: this + the comment above (link), I didn't fully implement this function because I wanted to figure out what we're going to process in the extension first and I wasn't sure the range of how much info that the client can pass to the server (will it always pass the entire new config upon changes? or only the differences?)
|
||
// currently, the only request that may be sent by the server during a client request is one `config` request | ||
// !!! remove if `config` is handled in initialization and there are no other server-initiated requests | ||
if resp.Kind == lsproto.MessageKindRequest { |
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.
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?
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.
Pull Request Overview
This PR implements user preferences support throughout the codebase to unblock future work, focusing on fourslash test capabilities and inlay hints configuration from VS Code. The implementation adds user preferences handling to the session lifecycle, language service, and LSP server with initial support for parsing inlay hints settings from VS Code client configuration.
- Adds user preferences threading through session, snapshot, and language service layers
- Implements VS Code configuration parsing for inlay hints preferences
- Extends fourslash testing framework to support user preferences configuration
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.
Show a summary per file
File | Description |
---|---|
internal/project/snapshot.go | Adds user preferences field and getter method to snapshot |
internal/project/session.go | Implements user preferences configuration and change tracking in session |
internal/project/api.go | Updates API calls to include user preferences parameter |
internal/lsp/server.go | Adds configuration request handling and inlay hints parsing from VS Code |
internal/ls/types.go | Extends UserPreferences with inlay hints fields and copy methods |
internal/ls/languageservice.go | Adds user preferences parameter to language service constructor |
internal/fourslash/fourslash.go | Implements user preferences configuration support for testing |
internal/fourslash/tests/autoImportCompletion_test.go | Adds test case for user preferences functionality |
internal/api/api.go | Updates language service instantiation to include user preferences |
session.extendedConfigCache, | ||
nil, | ||
compilerOptionsForInferredProjects, | ||
session.userPreferences, |
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.
This is a race—you only protect the boolean session.pendingChanges
with the mutex while computing whether you need to do a snapshot update. By the time you get here, session.userPreferences
could have changed since that boolean was accessed. You need to lock and extract the actual new value of the user preferences, and then make that part of SnapshotChange
.
Goal is to unblock #1705
A full implementation of LSP compliant config getting/updating requires more work in the extension (currently in progress)