提交 6253b44e 编写于 作者: J Johannes Rieken

IFormattingSupport can be either doc or range formatting support, fixes #1163

上级 974ed10c
......@@ -22,7 +22,9 @@ export const FormatOnTypeRegistry = new LanguageFeatureRegistry<IFormattingSuppo
export {IFormattingSupport};
export function formatRange(model: IModel, range: IRange, options: IFormattingOptions): TPromise<ISingleEditOperation[]> {
const [support] = FormatRegistry.ordered(model);
const [support] = FormatRegistry.ordered(model)
.filter(s => typeof s.formatRange === 'function');
if (!support) {
return TPromise.as(undefined);
}
......
......@@ -958,6 +958,27 @@ suite('ExtHostLanguageFeatures', function() {
});
})
test('Format Range, + format_doc', function(done) {
disposables.push(extHost.registerDocumentRangeFormattingEditProvider(defaultSelector, <vscode.DocumentRangeFormattingEditProvider>{
provideDocumentRangeFormattingEdits(): any {
return [new types.TextEdit(new types.Range(0, 0, 1, 1), 'range')];
}
}));
disposables.push(extHost.registerDocumentFormattingEditProvider(defaultSelector, <vscode.DocumentFormattingEditProvider>{
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, <vscode.DocumentRangeFormattingEditProvider>{
provideDocumentRangeFormattingEdits(): any {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册