diff --git a/Readme.md b/Readme.md index 6fc895c..119aec0 100644 --- a/Readme.md +++ b/Readme.md @@ -137,6 +137,9 @@ for guide of coc.nvim's configuration. - `typescript.preferences.importModuleSpecifier` default: `"auto"` - `typescript.preferences.importModuleSpecifierEnding` default: `"auto"` - `typescript.preferences.quoteStyle` default: `"single"` +- `typescript.preferences.includePackageJsonAutoImports`: Enable/disable + searching `package.json` dependencies for available auto imports, default: + `"auto"` - `typescript.suggestionActions.enabled`:Enable/disable suggestion diagnostics for TypeScript files in the editor. Requires using TypeScript 2.8 or newer in the workspace., default: `true` diff --git a/package.json b/package.json index 48f4487..191f5d7 100644 --- a/package.json +++ b/package.json @@ -330,6 +330,22 @@ "description": "Preferred style for JSX attribute completions.", "scope": "resource" }, + "typescript.preferences.includePackageJsonAutoImports": { + "type": "string", + "enum": [ + "auto", + "on", + "off" + ], + "enumDescriptions": [ + "Search dependencies based on estimated performance impact.", + "Always search dependencies.", + "Never search dependencies." + ], + "default": "auto", + "markdownDescription": "Enable/disable searching `package.json` dependencies for available auto imports.", + "scope": "window" + }, "typescript.preferences.quoteStyle": { "type": "string", "default": "auto", diff --git a/src/server/typescriptServiceClient.ts b/src/server/typescriptServiceClient.ts index 301d7f4..b1fb75d 100644 --- a/src/server/typescriptServiceClient.ts +++ b/src/server/typescriptServiceClient.ts @@ -408,6 +408,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient preferences: { providePrefixAndSuffixTextForRename: true, allowRenameOfImportPath: true, + includePackageJsonAutoImports: this._configuration.includePackageJsonAutoImports }, watchOptions } diff --git a/src/server/utils/configuration.ts b/src/server/utils/configuration.ts index c23682b..ec6b6ee 100644 --- a/src/server/utils/configuration.ts +++ b/src/server/utils/configuration.ts @@ -40,14 +40,21 @@ export namespace TsServerLogLevel { export class TypeScriptServiceConfiguration { private _configuration: WorkspaceConfiguration + private _includePackageJsonAutoImports: 'auto' | 'on' | 'off' private constructor() { this._configuration = workspace.getConfiguration('tsserver') + this._includePackageJsonAutoImports = workspace.getConfiguration('typescript').get<'auto' | 'on' | 'off'>('preferences.includePackageJsonAutoImports') workspace.onDidChangeConfiguration(() => { this._configuration = workspace.getConfiguration('tsserver') + this._includePackageJsonAutoImports = workspace.getConfiguration('typescript').get<'auto' | 'on' | 'off'>('preferences.includePackageJsonAutoImports') }) } + public get includePackageJsonAutoImports(): 'auto' | 'on' | 'off' { + return this._includePackageJsonAutoImports + } + public get locale(): string | null { return this._configuration.get('locale', null) }