提交 d2da7e96 编写于 作者: J Johannes Rieken
上级 1d177e24
......@@ -13,6 +13,7 @@ import { IModelService } from 'vs/editor/common/services/modelService';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { isDisposable, Disposable } from 'vs/base/common/lifecycle';
import { coalesce } from 'vs/base/common/arrays';
import { assertType } from 'vs/base/common/types';
export class Link implements ILink {
......@@ -152,10 +153,13 @@ export function getLinks(model: ITextModel, token: CancellationToken): Promise<L
CommandsRegistry.registerCommand('_executeLinkProvider', async (accessor, ...args): Promise<ILink[]> => {
const [uri] = args;
if (!(uri instanceof URI)) {
return [];
let [uri, resolveCount] = args;
assertType(uri instanceof URI);
if (typeof resolveCount !== 'number') {
resolveCount = 0;
}
const model = accessor.get(IModelService).getModel(uri);
if (!model) {
return [];
......@@ -164,6 +168,12 @@ CommandsRegistry.registerCommand('_executeLinkProvider', async (accessor, ...arg
if (!list) {
return [];
}
// resolve links
for (let i = 0; i < Math.min(resolveCount, list.links.length); i++) {
await list.links[i].resolve(CancellationToken.None);
}
const result = list.links.slice(0);
list.dispose();
return result;
......
......@@ -228,10 +228,15 @@ const newCommands: ApiCommand[] = [
}
return typeConverters.WorkspaceEdit.to(value);
})
),
// --- links
new ApiCommand(
'vscode.executeLinkProvider', '_executeLinkProvider', 'Execute document link provider.',
[ApiCommandArgument.Uri, new ApiCommandArgument('linkResolveCount', '(optional) Number of links that should be resolved, only when links are unresolved.', v => typeof v === 'number' || typeof v === 'undefined', v => v)],
new ApiCommandResult<modes.ILink[], vscode.DocumentLink[]>('A promise that resolves to an array of DocumentLink-instances.', value => value.map(typeConverters.DocumentLink.to))
)
];
//#endregion
......@@ -289,13 +294,6 @@ export class ExtHostApiCommands {
returns: 'A promise that resolves to an array of CodeLens-instances.'
});
this._register('vscode.executeLinkProvider', this._executeDocumentLinkProvider, {
description: 'Execute document link provider.',
args: [
{ name: 'uri', description: 'Uri of a text document', constraint: URI }
],
returns: 'A promise that resolves to an array of DocumentLink-instances.'
});
this._register('vscode.executeDocumentColorProvider', this._executeDocumentColorProvider, {
description: 'Execute document color provider.',
args: [
......@@ -478,12 +476,6 @@ export class ExtHostApiCommands {
typeConverters.Range.to(item.range),
item.command ? this._commands.converter.fromInternal(item.command) : undefined);
}));
}
private _executeDocumentLinkProvider(resource: URI): Promise<vscode.DocumentLink[] | undefined> {
return this._commands.executeCommand<modes.ILink[]>('_executeLinkProvider', resource)
.then(tryMapWith(typeConverters.DocumentLink.to));
}
}
......
......@@ -1011,6 +1011,29 @@ suite('ExtHostLanguageFeatureCommands', function () {
});
});
test('What\'s the condition for DocumentLink target to be undefined? #106308', async function () {
disposables.push(extHost.registerDocumentLinkProvider(nullExtensionDescription, defaultSelector, <vscode.DocumentLinkProvider>{
provideDocumentLinks(): any {
return [new types.DocumentLink(new types.Range(0, 0, 0, 20), undefined)];
},
resolveDocumentLink(link) {
link.target = URI.parse('foo:bar');
return link;
}
}));
await rpcProtocol.sync();
const links1 = await commands.executeCommand<vscode.DocumentLink[]>('vscode.executeLinkProvider', model.uri);
assert.equal(links1.length, 1);
assert.equal(links1[0].target, undefined);
const links2 = await commands.executeCommand<vscode.DocumentLink[]>('vscode.executeLinkProvider', model.uri, 1000);
assert.equal(links2.length, 1);
assert.equal(links2[0].target!.toString(), URI.parse('foo:bar').toString());
});
test('Color provider', function () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册