Merge pull request #256256 from andy0130tw/andy0130tw/support-locale-argument-in-tsserver-web

Support the locale argument of TypeScript language server on the web version (#256252)
This commit is contained in:
Matt Bierner
2025-07-16 13:35:44 -07:00
committed by GitHub
2 changed files with 11 additions and 1 deletions

View File

@@ -16,7 +16,7 @@ export class PathMapper {
* Copied from toResource in typescriptServiceClient.ts
*/
toResource(filepath: string): URI {
if (looksLikeLibDtsPath(filepath)) {
if (looksLikeLibDtsPath(filepath) || looksLikeLocaleResourcePath(filepath)) {
return URI.from({
scheme: this.extensionUri.scheme,
authority: this.extensionUri.authority,
@@ -83,6 +83,10 @@ export function looksLikeLibDtsPath(filepath: string) {
return filepath.startsWith('/lib.') && filepath.endsWith('.d.ts');
}
export function looksLikeLocaleResourcePath(filepath: string) {
return !!filepath.match(/^\/[a-zA-Z]+(-[a-zA-Z]+)?\/diagnosticMessages\.generated\.json$/);
}
export function looksLikeNodeModules(filepath: string) {
return filepath.includes('/node_modules');
}

View File

@@ -41,6 +41,12 @@ async function initializeSession(
removeEventListener('message', listener);
});
setSys(sys);
const localeStr = findArgument(args, '--locale');
if (localeStr) {
ts.validateLocaleAndSetLanguage(localeStr, sys);
}
startWorkerSession(ts, sys, fs, sessionOptions, ports.tsserver, pathMapper, logger);
}