From 6253b44ec7680dc525fe62b75166e11e12ea0968 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 10 Dec 2015 12:46:08 +0100 Subject: [PATCH] IFormattingSupport can be either doc or range formatting support, fixes #1163 --- src/vs/editor/contrib/format/common/format.ts | 4 +++- .../api/extHostLanguageFeatures.test.ts | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/vs/editor/contrib/format/common/format.ts b/src/vs/editor/contrib/format/common/format.ts index 681a9d7d0eb..44820b30b1f 100644 --- a/src/vs/editor/contrib/format/common/format.ts +++ b/src/vs/editor/contrib/format/common/format.ts @@ -22,7 +22,9 @@ export const FormatOnTypeRegistry = new LanguageFeatureRegistry { - const [support] = FormatRegistry.ordered(model); + const [support] = FormatRegistry.ordered(model) + .filter(s => typeof s.formatRange === 'function'); + if (!support) { return TPromise.as(undefined); } diff --git a/src/vs/workbench/test/common/api/extHostLanguageFeatures.test.ts b/src/vs/workbench/test/common/api/extHostLanguageFeatures.test.ts index 7d5664e138f..9334a3a4fe5 100644 --- a/src/vs/workbench/test/common/api/extHostLanguageFeatures.test.ts +++ b/src/vs/workbench/test/common/api/extHostLanguageFeatures.test.ts @@ -958,6 +958,27 @@ suite('ExtHostLanguageFeatures', function() { }); }) + test('Format Range, + format_doc', function(done) { + disposables.push(extHost.registerDocumentRangeFormattingEditProvider(defaultSelector, { + provideDocumentRangeFormattingEdits(): any { + return [new types.TextEdit(new types.Range(0, 0, 1, 1), 'range')]; + } + })); + disposables.push(extHost.registerDocumentFormattingEditProvider(defaultSelector, { + provideDocumentFormattingEdits(): any { + return [new types.TextEdit(new types.Range(0, 0, 1, 1), 'doc')]; + } + })); + threadService.sync().then(() => { + formatRange(model, { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 }, { insertSpaces: true, tabSize: 4 }).then(value => { + assert.equal(value.length, 1); + let [first] = value; + assert.equal(first.text, 'range'); + done(); + }); + }); + }); + test('Format Range, evil provider', function(done) { disposables.push(extHost.registerDocumentRangeFormattingEditProvider(defaultSelector, { provideDocumentRangeFormattingEdits(): any { -- GitLab