add preferences.importModuleSpecifierEnding configuration

Closes #136
This commit is contained in:
Qiming Zhao 2020-04-10 19:52:24 +08:00
parent 1d4e80edf8
commit 64fd389b71
3 changed files with 42 additions and 5 deletions

View file

@ -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`

View file

@ -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",

View file

@ -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<boolean>('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<string>('importModuleSpecifierEnding')) {
case 'minimal': return 'minimal'
case 'index': return 'index'
case 'js': return 'js'
default: return 'auto'
}
}