remvoe commaAfterImport option, use noSemicolons

This commit is contained in:
chemzqm 2018-10-24 20:45:48 +08:00
parent 17a13df39c
commit 311d4c0782
4 changed files with 12 additions and 19 deletions

View file

@ -200,11 +200,6 @@
"default": true,
"description": "Enable/disable suggest paths in import statement and require calls"
},
"typescript.suggest.commaAfterImport": {
"type": "boolean",
"default": true,
"description": "Add comma after import statement."
},
"typescript.suggest.autoImports": {
"type": "boolean",
"default": true,
@ -316,11 +311,6 @@
"default": true,
"description": "Enable/disable suggest paths in import statement and require calls"
},
"javascript.suggest.commaAfterImport": {
"type": "boolean",
"default": true,
"description": "Add comma after import statement."
},
"javascript.suggest.autoImports": {
"type": "boolean",
"default": true,
@ -407,3 +397,4 @@
"which": "^1.3.1"
}
}

View file

@ -51,6 +51,7 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
public static readonly triggerCharacters = ['.', '@', '<']
private completeOption: SuggestOptions
private noSemicolons = false
constructor(
private readonly client: ITypeScriptServiceClient,
@ -61,10 +62,14 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
this.setCompleteOption(languageId)
commands.register(new ApplyCompletionCodeActionCommand(this.client))
workspace.onDidChangeConfiguration(_e => {
this.setCompleteOption(languageId)
})
}
private setCompleteOption(languageId: string): void {
this.completeOption = this.fileConfigurationManager.getCompleteOptions(languageId)
this.noSemicolons = this.fileConfigurationManager.removeSemicolons(languageId)
}
/**
@ -218,7 +223,6 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
if (!detail.codeActions || !detail.codeActions.length) {
return {}
}
let { commaAfterImport } = this.completeOption
// Try to extract out the additionalTextEdits for the current file.
// Also check if we still have to apply other workspace edits
const additionalTextEdits: TextEdit[] = []
@ -257,10 +261,10 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
]
}
}
if (additionalTextEdits.length && !commaAfterImport) {
if (additionalTextEdits.length && this.noSemicolons) {
// remove comma
additionalTextEdits.forEach(o => {
o.newText = o.newText.replace(/;/, '')
o.newText = o.newText.replace(/;/g, '')
})
}
return {

View file

@ -34,7 +34,6 @@ export interface SuggestOptions {
readonly enabled: boolean
readonly names: boolean
readonly paths: boolean
readonly commaAfterImport: boolean
readonly completeFunctionCalls: boolean
readonly autoImports: boolean
}
@ -129,7 +128,6 @@ export default class FileConfigurationManager {
enabled: config.get<boolean>('enabled', true),
names: config.get<boolean>('names', true),
paths: config.get<boolean>('paths', true),
commaAfterImport: config.get<boolean>('commaAfterImport', true),
completeFunctionCalls: config.get<boolean>('completeFunctionCalls', true),
autoImports: config.get<boolean>('autoImports', true)
}

View file

@ -16,7 +16,7 @@ class OrganizeImportsCommand implements Command {
constructor(
private readonly client: ITypeScriptServiceClient,
private commaAfterImport: boolean,
private noSemicolons: boolean,
private modeIds: string[]
) {
workspace.onWillSaveUntil(this.onWillSaveUntil, this, 'tsserver-organizeImports')
@ -55,7 +55,7 @@ class OrganizeImportsCommand implements Command {
this.client,
response.body
)
if (!this.commaAfterImport) {
if (this.noSemicolons) {
let { changes } = edit
if (changes) {
for (let c of Object.keys(changes)) {
@ -87,8 +87,8 @@ export default class OrganizeImports {
) {
let description = standardLanguageDescriptions.find(o => o.id == languageId)
let modeIds = description ? description.modeIds : []
let option = fileConfigurationManager.getCompleteOptions(languageId)
let cmd = new OrganizeImportsCommand(client, option.commaAfterImport, modeIds)
let noSemicolons = fileConfigurationManager.removeSemicolons(languageId)
let cmd = new OrganizeImportsCommand(client, noSemicolons, modeIds)
commandManager.register(cmd)
this.disposables.push(Disposable.create(() => {
commandManager.unregister(cmd.id)