[typescript-language-features] Add importModuleSpecifierEnding preference (#90405)

* Expose importModuleSpecifierEnding to typescript-language-features

* Add default `auto` setting

* Use string 'auto' for auto setting

* Work with TypeScript 3.8
This commit is contained in:
Andrew Branch 2020-02-28 11:20:50 -08:00 committed by GitHub
parent b1dfe79d37
commit 23850c7990
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 1 deletions

View file

@ -638,6 +638,42 @@
"description": "%typescript.preferences.importModuleSpecifier%",
"scope": "resource"
},
"javascript.preferences.importModuleSpecifierEnding": {
"type": "string",
"enum": [
"auto",
"minimal",
"index",
"js"
],
"markdownEnumDescriptions": [
"%typescript.preferences.importModuleSpecifierEnding.auto%",
"%typescript.preferences.importModuleSpecifierEnding.minimal%",
"%typescript.preferences.importModuleSpecifierEnding.index%",
"%typescript.preferences.importModuleSpecifierEnding.js%"
],
"default": "auto",
"description": "%typescript.preferences.importModuleSpecifierEnding%",
"scope": "resource"
},
"typescript.preferences.importModuleSpecifierEnding": {
"type": "string",
"enum": [
"auto",
"minimal",
"index",
"js"
],
"markdownEnumDescriptions": [
"%typescript.preferences.importModuleSpecifierEnding.auto%",
"%typescript.preferences.importModuleSpecifierEnding.minimal%",
"%typescript.preferences.importModuleSpecifierEnding.index%",
"%typescript.preferences.importModuleSpecifierEnding.js%"
],
"default": "auto",
"description": "%typescript.preferences.importModuleSpecifierEnding%",
"scope": "resource"
},
"javascript.preferences.renameShorthandProperties": {
"type": "boolean",
"default": true,

View file

@ -70,6 +70,11 @@
"typescript.preferences.importModuleSpecifier.auto": "Automatically select import path style. Prefers using a relative import if `baseUrl` is configured and the relative path has fewer segments than the non-relative import.",
"typescript.preferences.importModuleSpecifier.relative": "Relative to the file location.",
"typescript.preferences.importModuleSpecifier.nonRelative": "Based on the `baseUrl` configured in your `jsconfig.json` / `tsconfig.json`.",
"typescript.preferences.importModuleSpecifierEnding": "Preferred path ending for auto imports.",
"typescript.preferences.importModuleSpecifierEnding.auto": "Use project settings to select a default.",
"typescript.preferences.importModuleSpecifierEnding.minimal": "Shorten `./component/index.js` to `./component`.",
"typescript.preferences.importModuleSpecifierEnding.index": "Shorten `./component/index.js` to `./component/index`",
"typescript.preferences.importModuleSpecifierEnding.js": "Do not shorten path endings; include the `.js` extension.",
"typescript.updateImportsOnFileMove.enabled": "Enable/disable automatic updating of import paths when you rename or move a file in VS Code. Requires using TypeScript 2.9 or newer in the workspace.",
"typescript.updateImportsOnFileMove.enabled.prompt": "Prompt on each rename.",
"typescript.updateImportsOnFileMove.enabled.always": "Always update paths automatically.",

View file

@ -179,13 +179,18 @@ export default class FileConfigurationManager extends Disposable {
isTypeScriptDocument(document) ? 'typescript.preferences' : 'javascript.preferences',
document.uri);
return {
// `importModuleSpecifierEnding` added to `Proto.UserPreferences` in TypeScript 3.9:
// remove intersection type after upgrading TypeScript.
const preferences: Proto.UserPreferences & { importModuleSpecifierEnding?: string } = {
quotePreference: this.getQuoteStylePreference(config),
importModuleSpecifierPreference: getImportModuleSpecifierPreference(config),
importModuleSpecifierEnding: getImportModuleSpecifierEndingPreference(config),
allowTextChangesInNewFiles: document.uri.scheme === fileSchemes.file,
providePrefixAndSuffixTextForRename: config.get<boolean>('renameShorthandProperties', true),
allowRenameOfImportPath: true,
};
return preferences;
}
private getQuoteStylePreference(config: vscode.WorkspaceConfiguration) {
@ -204,3 +209,12 @@ function getImportModuleSpecifierPreference(config: vscode.WorkspaceConfiguratio
default: return undefined;
}
}
function getImportModuleSpecifierEndingPreference(config: vscode.WorkspaceConfiguration) {
switch (config.get<string>('importModuleSpecifierEnding')) {
case 'minimal': return 'minimal';
case 'index': return 'index';
case 'js': return 'js';
default: return 'auto';
}
}