Skip to content

Respect configured TypeScript diagnostic locale - #4660

Merged
jakebailey merged 11 commits into
mainfrom
copilot/fix-js-ts-locale-issue
Jul 24, 2026
Merged

Respect configured TypeScript diagnostic locale#4660
jakebailey merged 11 commits into
mainfrom
copilot/fix-js-ts-locale-issue

Conversation

Copilot AI commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

The native extension always used VS Code’s display language for diagnostics, ignoring explicit js/ts.locale and legacy typescript.locale overrides.

  • Locale resolution

    • Prefer js/ts.locale, then typescript.locale.
    • Use the editor display language when set to auto.
  • Configuration updates

    • Restart the running language server when either locale setting changes.
{
  "js/ts.locale": "en"
}

Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix extension not respecting js/ts.locale setting Respect configured TypeScript diagnostic locale Jul 16, 2026
Copilot AI requested a review from DanielRosenwasser July 16, 2026 21:42
Comment thread _extension/src/client.ts Outdated
@DanielRosenwasser
DanielRosenwasser marked this pull request as ready for review July 17, 2026 22:25
Copilot AI review requested due to automatic review settings July 17, 2026 22:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for configured TypeScript diagnostic locales in the native extension.

Changes:

  • Resolves unified and legacy locale settings.
  • Restarts the language server when locale configuration changes.
Show a summary per file
File Description
_extension/src/client.ts Applies configured locale during client initialization.
_extension/src/extension.ts Restarts active sessions after locale changes.

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Medium

Comment thread _extension/src/extension.ts Outdated
…ping restarts

Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
@jakebailey

jakebailey commented Jul 21, 2026

Copy link
Copy Markdown
Member

Maybe it's cleaner to just have a Client hook that sets the current locale, and we update that on user pref change and plumb it that way?

@DanielRosenwasser

Copy link
Copy Markdown
Member

Sure, @copilot do what Jake suggested.

…override

Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>

Copilot AI commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Sure, @copilot do what Jake suggested.

Done. Client.start() now resolves the locale once from config and passes it to NativePreviewLanguageClient as a constructor argument. getLocale() just returns the stored value rather than reading config on every call. The restart on locale change in extension.ts ensures a new Client is created and picks up the updated locale at start time.

@jakebailey

Copy link
Copy Markdown
Member

It didn't understand what I said, I meant the Client in the server, as in project.Client

@DanielRosenwasser

Copy link
Copy Markdown
Member

@copilot sounds like you need to make some adjustments.

…lly from workspace configuration

Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>

Copilot AI commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

@copilot sounds like you need to make some adjustments.

Done. Here's what changed:

  • project.Client (internal/project/client.go): added GetLocale() locale.Locale
  • *Server (internal/lsp/server.go): implements GetLocale() returning s.locale; handleDidChangeWorkspaceConfiguration now also calls localeFromSettings() to update s.locale when the user's locale preference changes — "auto"/missing falls back to s.initLocale (the locale negotiated in initialize, which already resolved "auto" to the editor display language on the extension side)
  • session.publishProjectDiagnostics: injects locale.WithLocale(ctx, s.client.GetLocale()) so push-diagnostic messages are correctly localised even when running on the background context (which has no locale set by the dispatch loop)
  • Extension (extension.ts): removed the locale-change restart handler — locale updates are now handled server-side via workspace/didChangeConfiguration

@jakebailey

Copy link
Copy Markdown
Member

@copilot This is still wrong. There should be no client side element. There should be a UserPreference that reads the locale, and Project should call back through Client to set a new locale, if present.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Comment thread internal/lsp/server.go Outdated

Copilot AI commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

@copilot This is still wrong. There should be no client side element. There should be a UserPreference that reads the locale, and Project should call back through Client to set a new local...

Addressed in e83a1d7. Locale is now parsed as a UserPreferences value, Session.Configure calls project.Client.SetLocale when present, and all extension-side locale handling has been removed.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Comment thread internal/ls/lsutil/userpreferences_test.go Outdated
@jakebailey jakebailey mentioned this pull request Jul 23, 2026
9 tasks
Comment thread internal/project/session.go Outdated
Comment on lines +1689 to +1692
// Inject the current locale so that push-diagnostic messages are formatted
// in the user's chosen language, even when ctx is the background context
// (which does not have a locale set by the LSP dispatch loop).
ctx = locale.WithLocale(ctx, s.client.GetLocale())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot This is new; do we have an existing bug? Should we have attached the locale somewhere else above? What's the deal?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this fixes an existing push-diagnostics bug. Pull diagnostics use request contexts decorated with the current locale, but push diagnostics run from the session background context, which has none. Localization happens here during DiagnosticToLSPPush, and attaching the locale to the background context at session creation would freeze it and miss later preference changes, so reading the current client locale at this conversion boundary is intentional.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Perhaps Session should have a func that returns the background context + this that everyone can use instead of accessing backgroundCtx directly? This seems like a very easy mistake to make

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in 2f11d43, with the queued-locale follow-up in 992a6cf. Session.backgroundContext() now centralizes locale decoration for all background-context access, and diagnostic publication refreshes the locale at conversion time so queued work cannot use a stale preference.

Copilot AI and others added 3 commits July 24, 2026 00:17
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@jakebailey
jakebailey requested a review from andrewbranch July 24, 2026 17:33
@jakebailey
jakebailey enabled auto-merge July 24, 2026 17:38
@jakebailey
jakebailey added this pull request to the merge queue Jul 24, 2026
Merged via the queue into main with commit d423282 Jul 24, 2026
21 checks passed
@jakebailey
jakebailey deleted the copilot/fix-js-ts-locale-issue branch July 24, 2026 18:16
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.

Extension does not respect js/ts.locale

5 participants