Add setting for package.json auto imports (#103037)

This commit is contained in:
Andrew Branch 2020-07-22 15:28:22 -07:00 committed by GitHub
parent 9fe56bdaac
commit 1c8662b8bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 2 deletions

View file

@ -686,6 +686,22 @@
"description": "%typescript.preferences.importModuleSpecifierEnding%",
"scope": "resource"
},
"typescript.preferences.includePackageJsonAutoImports": {
"type": "string",
"enum": [
"all",
"exclude-dev",
"none"
],
"enumDescriptions": [
"%typescript.preferences.includePackageJsonAutoImports.all%",
"%typescript.preferences.includePackageJsonAutoImports.excludeDev%",
"%typescript.preferences.includePackageJsonAutoImports.none%"
],
"default": "exclude-dev",
"markdownDescription": "%typescript.preferences.includePackageJsonAutoImports%",
"scope": "window"
},
"javascript.preferences.renameShorthandProperties": {
"type": "boolean",
"default": true,

View file

@ -74,8 +74,12 @@
"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.index": "Shorten `./component/index.js` to `./component/index`.",
"typescript.preferences.importModuleSpecifierEnding.js": "Do not shorten path endings; include the `.js` extension.",
"typescript.preferences.includePackageJsonAutoImports": "Enable/disable processing `package.json` dependencies for available auto imports.",
"typescript.preferences.includePackageJsonAutoImports.all": "Include all listed dependencies.",
"typescript.preferences.includePackageJsonAutoImports.excludeDev": "Exclude devDependencies.",
"typescript.preferences.includePackageJsonAutoImports.none": "Disable package.json dependency processing.",
"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

@ -526,6 +526,8 @@ export default class TypeScriptServiceClient extends Disposable implements IType
preferences: {
providePrefixAndSuffixTextForRename: true,
allowRenameOfImportPath: true,
// @ts-expect-error, remove after 4.0 protocol update
includePackageJsonAutoImports: this._configuration.includePackageJsonAutoImports,
},
watchOptions
};

View file

@ -66,6 +66,7 @@ export class TypeScriptServiceConfiguration {
public readonly maxTsServerMemory: number;
public readonly enablePromptUseWorkspaceTsdk: boolean;
public readonly watchOptions: protocol.WatchOptions | undefined;
public readonly includePackageJsonAutoImports: string | undefined;
public static loadFromWorkspace(): TypeScriptServiceConfiguration {
return new TypeScriptServiceConfiguration();
@ -88,6 +89,7 @@ export class TypeScriptServiceConfiguration {
this.maxTsServerMemory = TypeScriptServiceConfiguration.readMaxTsServerMemory(configuration);
this.enablePromptUseWorkspaceTsdk = TypeScriptServiceConfiguration.readEnablePromptUseWorkspaceTsdk(configuration);
this.watchOptions = TypeScriptServiceConfiguration.readWatchOptions(configuration);
this.includePackageJsonAutoImports = TypeScriptServiceConfiguration.readIncludePackageJsonAutoImports(configuration);
}
public isEqualTo(other: TypeScriptServiceConfiguration): boolean {
@ -104,7 +106,8 @@ export class TypeScriptServiceConfiguration {
&& this.enableProjectDiagnostics === other.enableProjectDiagnostics
&& this.maxTsServerMemory === other.maxTsServerMemory
&& objects.equals(this.watchOptions, other.watchOptions)
&& this.enablePromptUseWorkspaceTsdk === other.enablePromptUseWorkspaceTsdk;
&& this.enablePromptUseWorkspaceTsdk === other.enablePromptUseWorkspaceTsdk
&& this.includePackageJsonAutoImports === other.includePackageJsonAutoImports;
}
private static fixPathPrefixes(inspectValue: string): string {
@ -178,6 +181,10 @@ export class TypeScriptServiceConfiguration {
return configuration.get<protocol.WatchOptions>('typescript.tsserver.watchOptions');
}
private static readIncludePackageJsonAutoImports(configuration: vscode.WorkspaceConfiguration): string | undefined {
return configuration.get<string>('typescript.preferences.includePackageJsonAutoImports');
}
private static readMaxTsServerMemory(configuration: vscode.WorkspaceConfiguration): number {
const defaultMaxMemory = 3072;
const minimumMaxMemory = 128;