Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions extensions/typescript-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions extensions/typescript-language-features/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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';
}
}