diff --git a/Readme.md b/Readme.md index 737d2f9..8594133 100644 --- a/Readme.md +++ b/Readme.md @@ -98,6 +98,7 @@ Checkout [using the configuration file](https://github.com/neoclide/coc.nvim/wik - `typescript.implementationsCodeLens.enable`:Enable codeLens for implementations, default: `true` - `typescript.referencesCodeLens.enable`:Enable codeLens for references, default: `true` - `typescript.preferences.importModuleSpecifier` default: `"auto"` +- `typescript.preferences.importModuleSpecifierEnding` default: `true` - `typescript.preferences.quoteStyle` default: `"single"` - `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` - `typescript.validate.enable`:Enable/disable TypeScript validation., default: `true` @@ -129,6 +130,7 @@ Checkout [using the configuration file](https://github.com/neoclide/coc.nvim/wik - `javascript.implementationsCodeLens.enable` default: `true` - `javascript.referencesCodeLens.enable` default: `true` - `javascript.preferences.importModuleSpecifier` default: `"auto"` +- `javascript.preferences.importModuleSpecifierEnding` default: `true` - `javascript.preferences.quoteStyle` default: `"single"` - `javascript.validate.enable`: Enable/disable JavaScript validation., default: `true` - `javascript.suggestionActions.enabled`: Enable/disable suggestion diagnostics for JavaScript 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 e61fe79..1e729fd 100644 --- a/package.json +++ b/package.json @@ -236,6 +236,18 @@ "auto" ] }, + "typescript.preferences.importModuleSpecifierEnding": { + "type": "string", + "enum": [ + "auto", + "minimal", + "index", + "js" + ], + "default": "auto", + "description": "Preferred path ending for auto imports.", + "scope": "resource" + }, "typescript.preferences.quoteStyle": { "type": "string", "default": "auto", @@ -383,6 +395,18 @@ "relative" ] }, + "javascript.preferences.importModuleSpecifierEnding": { + "type": "string", + "enum": [ + "auto", + "minimal", + "index", + "js" + ], + "default": "auto", + "description": "Preferred path ending for auto imports.", + "scope": "resource" + }, "javascript.preferences.quoteStyle": { "type": "string", "default": "auto", diff --git a/src/server/features/fileConfigurationManager.ts b/src/server/features/fileConfigurationManager.ts index 3e49277..f09d123 100644 --- a/src/server/features/fileConfigurationManager.ts +++ b/src/server/features/fileConfigurationManager.ts @@ -148,15 +148,17 @@ export default class FileConfigurationManager { if (this.client.apiVersion.lt(API.v290)) { return {} } - const config = workspace.getConfiguration(language, uri) - return { - disableSuggestions: !config.get('suggest.enabled', true), - importModuleSpecifierPreference: getImportModuleSpecifier(config) as any, + const config = workspace.getConfiguration(`${language}.preferences`, uri) + // getImportModuleSpecifierEndingPreference available on ts 2.9.0 + const preferences: Proto.UserPreferences & { importModuleSpecifierEnding?: string } = { quotePreference: this.getQuoteStyle(config), + importModuleSpecifierPreference: getImportModuleSpecifier(config) as any, + importModuleSpecifierEnding: getImportModuleSpecifierEndingPreference(config), + allowTextChangesInNewFiles: uri.startsWith('file:'), allowRenameOfImportPath: true, - allowTextChangesInNewFiles: true, providePrefixAndSuffixTextForRename: true, } + return preferences } private getQuoteStyle(config: WorkspaceConfiguration): 'auto' | 'double' | 'single' { @@ -179,3 +181,12 @@ function getImportModuleSpecifier(config): ModuleImportType { return 'auto' } } + +function getImportModuleSpecifierEndingPreference(config: WorkspaceConfiguration): string { + switch (config.get('importModuleSpecifierEnding')) { + case 'minimal': return 'minimal' + case 'index': return 'index' + case 'js': return 'js' + default: return 'auto' + } +}