From fd957b20f9ebb37aacd66fdeee5843762b5b6018 Mon Sep 17 00:00:00 2001 From: Heyward Fann Date: Mon, 7 Jun 2021 11:26:52 +0800 Subject: [PATCH] feat: update preferences.importModuleSpecifier (#295) https://github.com/microsoft/vscode/pull/110536 --- package.json | 26 ++++++++++++++----- .../features/fileConfigurationManager.ts | 6 +++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 0061d70..ab3a716 100644 --- a/package.json +++ b/package.json @@ -277,12 +277,19 @@ }, "typescript.preferences.importModuleSpecifier": { "type": "string", - "default": "auto", + "default": "shortest", "description": "Preferred path style for auto imports.", + "enumDescriptions": [ + "Prefers a non-relative import only if one is available that has fewer path segments than a relative import", + "Prefers a relative path to the imported file location", + "Prefers a non-relative import based on the `baseUrl` or `paths` configured in your `jsconfig.json` / `tsconfig.json`.", + "Prefers a non-relative import only if the relative import path would leave the package or project directory. Requires using TypeScript 4.2+ in the workspace." + ], "enum": [ - "non-relative", + "shortest", "relative", - "auto" + "non-relative", + "project-relative" ] }, "typescript.preferences.importModuleSpecifierEnding": { @@ -475,12 +482,19 @@ }, "javascript.preferences.importModuleSpecifier": { "type": "string", - "default": "auto", + "default": "shortest", "description": "Preferred path style for auto imports.", + "enumDescriptions": [ + "Prefers a non-relative import only if one is available that has fewer path segments than a relative import", + "Prefers a relative path to the imported file location", + "Prefers a non-relative import based on the `baseUrl` or `paths` configured in your `jsconfig.json` / `tsconfig.json`.", + "Prefers a non-relative import only if the relative import path would leave the package or project directory. Requires using TypeScript 4.2+ in the workspace." + ], "enum": [ - "auto", + "shortest", + "relative", "non-relative", - "relative" + "project-relative" ] }, "javascript.preferences.importModuleSpecifierEnding": { diff --git a/src/server/features/fileConfigurationManager.ts b/src/server/features/fileConfigurationManager.ts index f44464a..d465cff 100644 --- a/src/server/features/fileConfigurationManager.ts +++ b/src/server/features/fileConfigurationManager.ts @@ -196,17 +196,19 @@ export default class FileConfigurationManager { } } -type ModuleImportType = 'relative' | 'non-relative' | 'auto' +type ModuleImportType = 'shortest' | 'project-relative' | 'relative' | 'non-relative' function getImportModuleSpecifier(config: WorkspaceConfiguration): ModuleImportType { let val = config.get('importModuleSpecifier') switch (val) { + case 'project-relative': + return 'project-relative' case 'relative': return 'relative' case 'non-relative': return 'non-relative' default: - return 'auto' + return undefined } }