Skip to content

Conversation

iisaduan
Copy link
Member

@iisaduan iisaduan commented Sep 17, 2025

Goal is to unblock #1705

  • fourslash supports all userpreferences
  • userpreferences implemented into server, session, and snapshot/languageService's lifecycles.
  • only inlay hints preferences are parsed from vscode's client config responses

A full implementation of LSP compliant config getting/updating requires more work in the extension (currently in progress)

@iisaduan iisaduan requested review from Copilot, andrewbranch and gabritto and removed request for Copilot and andrewbranch September 17, 2025 22:06
@jakebailey
Copy link
Member

A full implementation of LSP compliant config getting/updating requires more work in the extension (currently in progress)

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).

@iisaduan
Copy link
Member Author

iisaduan commented Sep 17, 2025

Our userPreferences struct doesn't exist at all in vscode--the previous extension did a lot of processing of the way that vscode's settings.json is represented before it passed a userPreferences to tsserver. We could do this processing on our side, but the code is so much more complicated in go (hence why I didn't implement every preference), and would mean that other clients (if they want to support userPreferences) have to convert their preferences into vscode's preferences, which then our server would convert again. Also, LSP spec says that the client should do this processing.

The other extension changes include to make configuration happen on initialization

@jakebailey
Copy link
Member

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...

Comment on lines +221 to +227
result, err := s.sendRequest(ctx, lsproto.MethodWorkspaceConfiguration, &lsproto.ConfigurationParams{
Items: []*lsproto.ConfigurationItem{
{
Section: ptrTo("typescript"),
},
},
})
Copy link
Member Author

@iisaduan iisaduan Sep 17, 2025

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:

Suggested change
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?

Copy link
Member Author

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

Copy link
Member

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":
Copy link
Member

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.

Copy link
Member Author

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 {
Copy link
Member

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)
Copy link
Member

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.

Copy link
Member Author

@iisaduan iisaduan Sep 18, 2025

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 {
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member Author

@iisaduan iisaduan Sep 30, 2025

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?

@Copilot Copilot AI review requested due to automatic review settings September 18, 2025 20:35
Copy link
Contributor

@Copilot Copilot AI left a 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,
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants