提交 a8839f85 编写于 作者: J Johannes Rieken

add an arg to resolve code lenses, #44846

上级 f952b5d7
......@@ -14,6 +14,7 @@ import { registerLanguageCommand } from 'vs/editor/browser/editorExtensions';
import { CodeLensProviderRegistry, CodeLensProvider, ICodeLensSymbol } from 'vs/editor/common/modes';
import { IModelService } from 'vs/editor/common/services/modelService';
import { asWinJsPromise } from 'vs/base/common/async';
import { CancellationToken } from 'vs/base/common/cancellation';
export interface ICodeLensData {
symbol: ICodeLensSymbol;
......@@ -58,7 +59,7 @@ export function getCodeLensData(model: ITextModel): TPromise<ICodeLensData[]> {
registerLanguageCommand('_executeCodeLensProvider', function (accessor, args) {
const { resource } = args;
let { resource, itemResolveCount } = args;
if (!(resource instanceof URI)) {
throw illegalArgument();
}
......@@ -68,5 +69,22 @@ registerLanguageCommand('_executeCodeLensProvider', function (accessor, args) {
throw illegalArgument();
}
return getCodeLensData(model).then(value => value.map(item => item.symbol));
const result: ICodeLensSymbol[] = [];
return getCodeLensData(model).then(value => {
let resolve: Thenable<any>[] = [];
for (const item of value) {
if (typeof itemResolveCount === 'undefined') {
result.push(item.symbol);
} else if (itemResolveCount-- > 0) {
resolve.push(Promise.resolve(item.provider.resolveCodeLens(model, item.symbol, CancellationToken.None)).then(symbol => result.push(symbol)));
}
}
return Promise.all(resolve);
}).then(() => {
return result;
});
});
......@@ -137,7 +137,8 @@ export class ExtHostApiCommands {
this._register('vscode.executeCodeLensProvider', this._executeCodeLensProvider, {
description: 'Execute CodeLens provider.',
args: [
{ name: 'uri', description: 'Uri of a text document', constraint: URI }
{ name: 'uri', description: 'Uri of a text document', constraint: URI },
{ name: 'itemResolveCount', description: '(optional) Number of lenses that should be resolved and returned. Will only retrun resolved lenses, will impact performance)', constraint: value => value === void 0 || typeof value === 'number' }
],
returns: 'A promise that resolves to an array of CodeLens-instances.'
});
......@@ -472,8 +473,8 @@ export class ExtHostApiCommands {
}));
}
private _executeCodeLensProvider(resource: URI): Thenable<vscode.CodeLens[]> {
const args = { resource };
private _executeCodeLensProvider(resource: URI, itemResolveCount: number): Thenable<vscode.CodeLens[]> {
const args = { resource, itemResolveCount };
return this._commands.executeCommand<modes.ICodeLensSymbol[]>('_executeCodeLensProvider', args)
.then(tryMapWith(item => {
return new types.CodeLens(
......
......@@ -534,6 +534,40 @@ suite('ExtHostLanguageFeatureCommands', function () {
});
});
test('CodeLens, resolve', async function () {
let resolveCount = 0;
disposables.push(extHost.registerCodeLensProvider(defaultSelector, <vscode.CodeLensProvider>{
provideCodeLenses(): any {
return [
new types.CodeLens(new types.Range(0, 0, 1, 1)),
new types.CodeLens(new types.Range(0, 0, 1, 1)),
new types.CodeLens(new types.Range(0, 0, 1, 1)),
new types.CodeLens(new types.Range(0, 0, 1, 1))
];
},
resolveCodeLens(codeLens: types.CodeLens) {
codeLens.command = { title: resolveCount.toString(), command: 'resolved' };
resolveCount += 1;
return codeLens;
}
}));
await rpcProtocol.sync();
let value = await commands.executeCommand<vscode.CodeLens[]>('vscode.executeCodeLensProvider', model.uri, 2);
assert.equal(value.length, 2); // the resolve argument defines the number of results being returned
assert.equal(resolveCount, 2);
resolveCount = 0;
value = await commands.executeCommand<vscode.CodeLens[]>('vscode.executeCodeLensProvider', model.uri);
assert.equal(value.length, 4);
assert.equal(resolveCount, 0);
});
test('Links, back and forth', function () {
disposables.push(extHost.registerDocumentLinkProvider(defaultSelector, <vscode.DocumentLinkProvider>{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册