[typescript-language-features] Fix autoImportFileExcludePatterns format to work on Windows (#202762)

* Do not prefix autoImportFileExcludePatterns with `/`

* Fix autoImportFileExcludePatterns format
This commit is contained in:
Andrew Branch 2024-03-13 00:51:45 -07:00 committed by GitHub
parent 9697534cc0
commit d1498b3a48
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 6 deletions

View File

@ -215,12 +215,16 @@ export default class FileConfigurationManager extends Disposable {
private getAutoImportFileExcludePatternsPreference(config: vscode.WorkspaceConfiguration, workspaceFolder: vscode.Uri | undefined): string[] | undefined {
return workspaceFolder && config.get<string[]>('autoImportFileExcludePatterns')?.map(p => {
// Normalization rules: https://github.com/microsoft/TypeScript/pull/49578
const slashNormalized = p.replace(/\\/g, '/');
const isRelative = /^\.\.?($|\/)/.test(slashNormalized);
const isRelative = /^\.\.?($|[\/\\])/.test(p);
// In TypeScript < 5.3, the first path component cannot be a wildcard, so we need to prefix
// it with a path root (e.g. `/` or `c:\`)
const wildcardPrefix = this.client.apiVersion.gte(API.v540)
? ''
: path.parse(this.client.toTsFilePath(workspaceFolder)!).root;
return path.isAbsolute(p) ? p :
p.startsWith('*') ? '/' + slashNormalized :
isRelative ? vscode.Uri.joinPath(workspaceFolder, p).fsPath :
'/**/' + slashNormalized;
p.startsWith('*') ? wildcardPrefix + p :
isRelative ? this.client.toTsFilePath(vscode.Uri.joinPath(workspaceFolder, p))! :
wildcardPrefix + '**' + path.sep + p;
});
}
}

View File

@ -1534,7 +1534,7 @@ declare module 'vscode' {
* ```ts
* const u = URI.parse('file://server/c$/folder/file.txt')
* u.authority === 'server'
* u.path === '/shares/c$/file.txt'
* u.path === '/c$/folder/file.txt'
* u.fsPath === '\\server\c$\folder\file.txt'
* ```
*/