mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-20 08:38:56 +01:00
proposed API for CodeActionProvider#resolveCodeAction and all the wiring
This commit is contained in:
@@ -413,7 +413,8 @@ class CodeActionAdapter {
|
||||
this._disposables.set(cacheId, disposables);
|
||||
|
||||
const actions: CustomCodeAction[] = [];
|
||||
for (const candidate of commandsOrActions) {
|
||||
for (let i = 0; i < commandsOrActions.length; i++) {
|
||||
const candidate = commandsOrActions[i];
|
||||
if (!candidate) {
|
||||
continue;
|
||||
}
|
||||
@@ -439,6 +440,7 @@ class CodeActionAdapter {
|
||||
|
||||
// new school: convert code action
|
||||
actions.push({
|
||||
cacheId: [cacheId, i],
|
||||
title: candidate.title,
|
||||
command: candidate.command && this._commands.toInternal(candidate.command, disposables),
|
||||
diagnostics: candidate.diagnostics && candidate.diagnostics.map(typeConvert.Diagnostic.from),
|
||||
@@ -454,6 +456,21 @@ class CodeActionAdapter {
|
||||
});
|
||||
}
|
||||
|
||||
public async resolveCodeAction(id: extHostProtocol.ChainedCacheId, token: CancellationToken): Promise<extHostProtocol.IWorkspaceEditDto | undefined> {
|
||||
const [sessionId, itemId] = id;
|
||||
const item = this._cache.get(sessionId, itemId);
|
||||
if (!item || CodeActionAdapter._isCommand(item)) {
|
||||
return undefined; // code actions only!
|
||||
}
|
||||
if (!this._provider.resolveCodeAction) {
|
||||
return; // this should not happen...
|
||||
}
|
||||
const resolvedItem = await this._provider.resolveCodeAction(item, token);
|
||||
return resolvedItem?.edit
|
||||
? typeConvert.WorkspaceEdit.from(resolvedItem.edit)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
public releaseCodeActions(cachedId: number): void {
|
||||
this._disposables.get(cachedId)?.dispose();
|
||||
this._disposables.delete(cachedId);
|
||||
@@ -1595,7 +1612,7 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
|
||||
kind: x.kind.value,
|
||||
command: this._commands.converter.toInternal(x.command, store),
|
||||
}))
|
||||
}, ExtHostLanguageFeatures._extLabel(extension));
|
||||
}, ExtHostLanguageFeatures._extLabel(extension), Boolean(extension.enableProposedApi && provider.resolveCodeAction));
|
||||
store.add(this._createDisposable(handle));
|
||||
return store;
|
||||
}
|
||||
@@ -1605,6 +1622,10 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
|
||||
return this._withAdapter(handle, CodeActionAdapter, adapter => adapter.provideCodeActions(URI.revive(resource), rangeOrSelection, context, token), undefined);
|
||||
}
|
||||
|
||||
$resolveCodeAction(handle: number, id: extHostProtocol.ChainedCacheId, token: CancellationToken): Promise<extHostProtocol.IWorkspaceEditDto | undefined> {
|
||||
return this._withAdapter(handle, CodeActionAdapter, adapter => adapter.resolveCodeAction(id, token), undefined);
|
||||
}
|
||||
|
||||
$releaseCodeActions(handle: number, cacheId: number): void {
|
||||
this._withAdapter(handle, CodeActionAdapter, adapter => Promise.resolve(adapter.releaseCodeActions(cacheId)), undefined);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user