Skip to content

Commit 6253b44

Browse files
committed
IFormattingSupport can be either doc or range formatting support, fixes microsoft#1163
1 parent 974ed10 commit 6253b44

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/vs/editor/contrib/format/common/format.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export const FormatOnTypeRegistry = new LanguageFeatureRegistry<IFormattingSuppo
2222
export {IFormattingSupport};
2323

2424
export function formatRange(model: IModel, range: IRange, options: IFormattingOptions): TPromise<ISingleEditOperation[]> {
25-
const [support] = FormatRegistry.ordered(model);
25+
const [support] = FormatRegistry.ordered(model)
26+
.filter(s => typeof s.formatRange === 'function');
27+
2628
if (!support) {
2729
return TPromise.as(undefined);
2830
}

src/vs/workbench/test/common/api/extHostLanguageFeatures.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,27 @@ suite('ExtHostLanguageFeatures', function() {
958958
});
959959
})
960960

961+
test('Format Range, + format_doc', function(done) {
962+
disposables.push(extHost.registerDocumentRangeFormattingEditProvider(defaultSelector, <vscode.DocumentRangeFormattingEditProvider>{
963+
provideDocumentRangeFormattingEdits(): any {
964+
return [new types.TextEdit(new types.Range(0, 0, 1, 1), 'range')];
965+
}
966+
}));
967+
disposables.push(extHost.registerDocumentFormattingEditProvider(defaultSelector, <vscode.DocumentFormattingEditProvider>{
968+
provideDocumentFormattingEdits(): any {
969+
return [new types.TextEdit(new types.Range(0, 0, 1, 1), 'doc')];
970+
}
971+
}));
972+
threadService.sync().then(() => {
973+
formatRange(model, { startLineNumber: 1, startColumn: 1, endLineNumber: 1, endColumn: 1 }, { insertSpaces: true, tabSize: 4 }).then(value => {
974+
assert.equal(value.length, 1);
975+
let [first] = value;
976+
assert.equal(first.text, 'range');
977+
done();
978+
});
979+
});
980+
});
981+
961982
test('Format Range, evil provider', function(done) {
962983
disposables.push(extHost.registerDocumentRangeFormattingEditProvider(defaultSelector, <vscode.DocumentRangeFormattingEditProvider>{
963984
provideDocumentRangeFormattingEdits(): any {

0 commit comments

Comments
 (0)