Skip to content

Commit

Permalink
Revert change to only use CodeAction instead of `CodeAction | Comma…
Browse files Browse the repository at this point in the history
…nd` in modes since this will break `vscode.executeCodeActionProvider`
  • Loading branch information
mjbvz committed Nov 8, 2017
1 parent f1e6cdd commit 19cae05
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/vs/editor/common/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export interface CodeActionProvider {
/**
* Provide commands for the given document and range.
*/
provideCodeActions(model: editorCommon.IReadOnlyModel, range: Range, token: CancellationToken): CodeAction[] | Thenable<CodeAction[]>;
provideCodeActions(model: editorCommon.IReadOnlyModel, range: Range, token: CancellationToken): (CodeAction | Command)[] | Thenable<(Command | CodeAction)[]>;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/vs/editor/contrib/quickFix/quickFix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
import URI from 'vs/base/common/uri';
import { IReadOnlyModel } from 'vs/editor/common/editorCommon';
import { Range } from 'vs/editor/common/core/range';
import { CodeActionProviderRegistry, CodeAction } from 'vs/editor/common/modes';
import { CodeActionProviderRegistry, CodeAction, Command } from 'vs/editor/common/modes';
import { asWinJsPromise } from 'vs/base/common/async';
import { TPromise } from 'vs/base/common/winjs.base';
import { onUnexpectedExternalError, illegalArgument } from 'vs/base/common/errors';
import { IModelService } from 'vs/editor/common/services/modelService';
import { CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';

export function getCodeActions(model: IReadOnlyModel, range: Range): TPromise<CodeAction[]> {
export function getCodeActions(model: IReadOnlyModel, range: Range): TPromise<(CodeAction | Command)[]> {

const allResults: CodeAction[] = [];
const allResults: (CodeAction | Command)[] = [];
const promises = CodeActionProviderRegistry.all(model).map(support => {
return asWinJsPromise(token => support.provideCodeActions(model, range, token)).then(result => {
if (Array.isArray(result)) {
Expand Down
12 changes: 10 additions & 2 deletions src/vs/editor/contrib/quickFix/quickFixModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { IMarkerService } from 'vs/platform/markers/common/markers';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import { ICommonCodeEditor } from 'vs/editor/common/editorCommon';
import { CodeActionProviderRegistry, CodeAction } from 'vs/editor/common/modes';
import { CodeActionProviderRegistry, CodeAction, Command } from 'vs/editor/common/modes';
import { getCodeActions } from './quickFix';
import { Position } from 'vs/editor/common/core/position';

Expand Down Expand Up @@ -113,7 +113,15 @@ export class QuickFixOracle {
const range = model.validateRange(rangeOrSelection);
const position = rangeOrSelection instanceof Selection ? rangeOrSelection.getPosition() : rangeOrSelection.getStartPosition();

const fixes = getCodeActions(model, range);
const fixes = getCodeActions(model, range).then(actions =>
actions.map(action => {
if ('id' in action) {
// must be a command
const command = action as Command;
return { title: command.title, command: command } as CodeAction;
}
return action;
}));

this._signalChange({
type,
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/node/extHostLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class QuickFixAdapter {
this._provider = provider;
}

provideCodeActions(resource: URI, range: IRange): TPromise<modes.CodeAction[]> {
provideCodeActions(resource: URI, range: IRange): TPromise<(modes.CodeAction | modes.Command)[]> {

const doc = this._documents.getDocumentData(resource).document;
const ran = <vscode.Range>TypeConverters.toRange(range);
Expand All @@ -293,7 +293,7 @@ class QuickFixAdapter {
if (!Array.isArray(commands)) {
return undefined;
}
return commands.map(action => {
return commands.map((action): modes.CodeAction => {
if (!action) {
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ suite('ExtHostLanguageFeatureCommands', function () {
// --- quickfix

test('QuickFix, back and forth', function () {
disposables.push(extHost.registerCodeActionProvider(defaultSelector, <vscode.CodeActionProvider>{
provideCodeActions(): any {
disposables.push(extHost.registerCodeActionProvider(defaultSelector, {
provideCodeActions(): vscode.Command[] {
return [{ command: 'testing', title: 'Title', arguments: [1, 2, true] }];
}
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { IHeapService } from 'vs/workbench/api/electron-browser/mainThreadHeapSe
import { ExtHostDocuments } from 'vs/workbench/api/node/extHostDocuments';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/node/extHostDocumentsAndEditors';
import { getDocumentSymbols } from 'vs/editor/contrib/quickOpen/quickOpen';
import { DocumentSymbolProviderRegistry, DocumentHighlightKind, Hover } from 'vs/editor/common/modes';
import { DocumentSymbolProviderRegistry, DocumentHighlightKind, Hover, Command } from 'vs/editor/common/modes';
import { getCodeLensData } from 'vs/editor/contrib/codelens/codelens';
import { getDefinitionsAtPosition, getImplementationsAtPosition, getTypeDefinitionsAtPosition } from 'vs/editor/contrib/goToDeclaration/goToDeclaration';
import { getHover } from 'vs/editor/contrib/hover/getHover';
Expand Down Expand Up @@ -642,11 +642,11 @@ suite('ExtHostLanguageFeatures', function () {

test('Quick Fix, data conversion', function () {

disposables.push(extHost.registerCodeActionProvider(defaultSelector, <vscode.CodeActionProvider>{
provideCodeActions(): any {
disposables.push(extHost.registerCodeActionProvider(defaultSelector, {
provideCodeActions(): vscode.Command[] {
return [
<vscode.Command>{ command: 'test1', title: 'Testing1' },
<vscode.Command>{ command: 'test2', title: 'Testing2' }
{ command: 'test1', title: 'Testing1' },
{ command: 'test2', title: 'Testing2' }
];
}
}));
Expand All @@ -655,11 +655,11 @@ suite('ExtHostLanguageFeatures', function () {
return getCodeActions(model, model.getFullModelRange()).then(value => {
assert.equal(value.length, 2);

let [first, second] = value;
const [first, second]: Command[] = value as any;
assert.equal(first.title, 'Testing1');
assert.equal(first.command.id, 'test1');
assert.equal(first.id, 'test1');
assert.equal(second.title, 'Testing2');
assert.equal(second.command.id, 'test2');
assert.equal(second.id, 'test2');
});
});
});
Expand Down

0 comments on commit 19cae05

Please sign in to comment.