Skip to content

Commit

Permalink
Add setting for package.json auto imports (#103037)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Jul 22, 2020
1 parent 9fe56bd commit 1c8662b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
16 changes: 16 additions & 0 deletions extensions/typescript-language-features/package.json
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion extensions/typescript-language-features/package.nls.json
Expand Up @@ -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.",
Expand Down
Expand Up @@ -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
};
Expand Down
Expand Up @@ -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();
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1c8662b

Please sign in to comment.