diff --git a/Readme.md b/Readme.md index 0427f86..aa11702 100644 --- a/Readme.md +++ b/Readme.md @@ -87,6 +87,7 @@ this extension. - `typescript.suggest.paths`:Enable/disable suggest paths in import statement and require calls, default: `true` - `typescript.suggest.autoImports`:Enable/disable auto import suggests., default: `true` - `typescript.suggest.completeFunctionCalls`:Enable snippet for method suggestion, default: `true` +- `typescript.format.enabled`:Enable/disable format of typescript files. - `typescript.format.insertSpaceAfterCommaDelimiter` default: `true` - `typescript.format.insertSpaceAfterConstructor` default: `false` - `typescript.format.insertSpaceAfterSemicolonInForStatements` default: `true` @@ -102,18 +103,19 @@ this extension. - `typescript.format.insertSpaceAfterTypeAssertion` default: `false` - `typescript.format.placeOpenBraceOnNewLineForFunctions` default: `false` - `typescript.format.placeOpenBraceOnNewLineForControlBlocks` default: `false` +- `javascript.format.enabled`: Enable/disable format for javascript files. - `javascript.showUnused`: show unused variable hint. - `javascript.updateImportsOnFileMove.enable` default: `true` - `javascript.implementationsCodeLens.enable` default: `true` - `javascript.referencesCodeLens.enable` default: `true` - `javascript.preferences.importModuleSpecifier` default: `"non-relative"` - `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` -- `javascript.suggest.names` default: `true` -- `javascript.suggest.enabled` default: `true` -- `javascript.suggest.paths`:Enable/disable suggest paths in import statement and require calls, default: `true` -- `javascript.suggest.autoImports`:Enable/disable auto import suggests., default: `true` +- `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` +- `javascript.suggest.names`: default `true` +- `javascript.suggest.enabled`: default `true` +- `javascript.suggest.paths`: Enable/disable suggest paths in import statement and require calls, default: `true` +- `javascript.suggest.autoImports`: Enable/disable auto import suggests., default: `true` - `javascript.suggest.completeFunctionCalls`:Enable snippet for method suggestion, default: `true` - `javascript.format.insertSpaceAfterCommaDelimiter` default: `true` - `javascript.format.insertSpaceAfterConstructor` default: `false` diff --git a/package.json b/package.json index 1adb1ca..9c80de9 100644 --- a/package.json +++ b/package.json @@ -268,6 +268,11 @@ "default": true, "description": "Enable snippet for method suggestion" }, + "typescript.format.enabled": { + "type": "boolean", + "default": true, + "description": "Enable format for typescript." + }, "typescript.format.insertSpaceAfterCommaDelimiter": { "type": "boolean", "default": true @@ -395,6 +400,11 @@ "default": true, "description": "Enable snippet for method suggestion" }, + "javascript.format.enabled": { + "type": "boolean", + "default": true, + "description": "Enable format for javascript." + }, "javascript.format.insertSpaceAfterCommaDelimiter": { "type": "boolean", "default": true diff --git a/src/server/features/formatting.ts b/src/server/features/formatting.ts index 61a9981..1c7c71f 100644 --- a/src/server/features/formatting.ts +++ b/src/server/features/formatting.ts @@ -20,12 +20,17 @@ export default class TypeScriptFormattingProvider ) { } + private enabled(document: TextDocument): boolean { + return this.formattingOptionsManager.formatEnabled(document) + } + private async doFormat( document: TextDocument, options: FormattingOptions, args: Proto.FormatRequestArgs, token?: CancellationToken ): Promise { + if (!this.enabled(document)) return [] await this.formattingOptionsManager.ensureConfigurationOptions( document, options.insertSpaces, @@ -49,6 +54,7 @@ export default class TypeScriptFormattingProvider options: FormattingOptions, token: CancellationToken ): Promise { + if (!this.enabled(document)) return [] const filepath = this.client.toPath(document.uri) if (!filepath) return [] const args: Proto.FormatRequestArgs = { @@ -66,6 +72,7 @@ export default class TypeScriptFormattingProvider options: FormattingOptions, token?: CancellationToken ): Promise { + if (!this.enabled(document)) return [] const filepath = this.client.toPath(document.uri) if (!filepath) return [] const args: Proto.FormatRequestArgs = { @@ -85,13 +92,10 @@ export default class TypeScriptFormattingProvider options: FormattingOptions, token: CancellationToken ): Promise { - if (!this.client.configuration.formatOnType) { - return - } + if (!this.enabled(document)) return [] + if (!this.client.configuration.formatOnType) return [] const file = this.client.toPath(document.uri) - if (!file) { - return [] - } + if (!file) return [] await this.formattingOptionsManager.ensureConfigurationOptions( document,