提交 38f0dea2 编写于 作者: J Johannes Rieken

fix #29469, remove unsued code

上级 2ae81ab6
...@@ -258,13 +258,6 @@ export interface ISuggestSupport { ...@@ -258,13 +258,6 @@ export interface ISuggestSupport {
resolveCompletionItem?(model: editorCommon.IModel, position: Position, item: ISuggestion, token: CancellationToken): ISuggestion | Thenable<ISuggestion>; resolveCompletionItem?(model: editorCommon.IModel, position: Position, item: ISuggestion, token: CancellationToken): ISuggestion | Thenable<ISuggestion>;
} }
/**
* Interface used to quick fix typing errors while accesing member fields.
*/
export interface CodeAction {
command: Command;
score: number;
}
/** /**
* The code action interface defines the contract between extensions and * The code action interface defines the contract between extensions and
* the [light bulb](https://code.visualstudio.com/docs/editor/editingevolved#_code-action) feature. * the [light bulb](https://code.visualstudio.com/docs/editor/editingevolved#_code-action) feature.
...@@ -274,7 +267,7 @@ export interface CodeActionProvider { ...@@ -274,7 +267,7 @@ export interface CodeActionProvider {
/** /**
* Provide commands for the given document and range. * 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): Command[] | Thenable<Command[]>;
} }
/** /**
......
...@@ -7,20 +7,24 @@ ...@@ -7,20 +7,24 @@
import URI from 'vs/base/common/uri'; import URI from 'vs/base/common/uri';
import { IReadOnlyModel } from 'vs/editor/common/editorCommon'; import { IReadOnlyModel } from 'vs/editor/common/editorCommon';
import { Range } from 'vs/editor/common/core/range'; import { Range } from 'vs/editor/common/core/range';
import { CodeAction, CodeActionProviderRegistry } from 'vs/editor/common/modes'; import { Command, CodeActionProviderRegistry } from 'vs/editor/common/modes';
import { asWinJsPromise } from 'vs/base/common/async'; import { asWinJsPromise } from 'vs/base/common/async';
import { TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
import { onUnexpectedExternalError, illegalArgument } from 'vs/base/common/errors'; import { onUnexpectedExternalError, illegalArgument } from 'vs/base/common/errors';
import { IModelService } from 'vs/editor/common/services/modelService'; import { IModelService } from 'vs/editor/common/services/modelService';
import { CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions'; import { CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';
export function getCodeActions(model: IReadOnlyModel, range: Range): TPromise<CodeAction[]> { export function getCodeActions(model: IReadOnlyModel, range: Range): TPromise<Command[]> {
const allResults: CodeAction[] = []; const allResults: Command[] = [];
const promises = CodeActionProviderRegistry.all(model).map(support => { const promises = CodeActionProviderRegistry.all(model).map(support => {
return asWinJsPromise(token => support.provideCodeActions(model, range, token)).then(result => { return asWinJsPromise(token => support.provideCodeActions(model, range, token)).then(result => {
if (Array.isArray(result)) { if (Array.isArray(result)) {
allResults.push(...result); for (const quickFix of result) {
if (quickFix) {
allResults.push(quickFix);
}
}
} }
}, err => { }, err => {
onUnexpectedExternalError(err); onUnexpectedExternalError(err);
......
...@@ -12,16 +12,11 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView ...@@ -12,16 +12,11 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IMarkerService } from 'vs/platform/markers/common/markers'; import { IMarkerService } from 'vs/platform/markers/common/markers';
import { ICommonCodeEditor, IEditorContribution, IReadOnlyModel } from 'vs/editor/common/editorCommon'; import { ICommonCodeEditor, IEditorContribution } from 'vs/editor/common/editorCommon';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { Range } from 'vs/editor/common/core/range';
import { editorAction, ServicesAccessor, EditorAction } from 'vs/editor/common/editorCommonExtensions'; import { editorAction, ServicesAccessor, EditorAction } from 'vs/editor/common/editorCommonExtensions';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { editorContribution } from 'vs/editor/browser/editorBrowserExtensions'; import { editorContribution } from 'vs/editor/browser/editorBrowserExtensions';
import { CodeAction, CodeActionProviderRegistry } from 'vs/editor/common/modes';
import { asWinJsPromise } from 'vs/base/common/async';
import { TPromise } from 'vs/base/common/winjs.base';
import { onUnexpectedExternalError } from 'vs/base/common/errors';
import { QuickFixContextMenu } from './quickFixWidget'; import { QuickFixContextMenu } from './quickFixWidget';
import { LightBulbWidget } from './lightBulbWidget'; import { LightBulbWidget } from './lightBulbWidget';
import { QuickFixModel, QuickFixComputeEvent } from './quickFixModel'; import { QuickFixModel, QuickFixComputeEvent } from './quickFixModel';
...@@ -135,21 +130,3 @@ export class QuickFixAction extends EditorAction { ...@@ -135,21 +130,3 @@ export class QuickFixAction extends EditorAction {
} }
} }
} }
export function getCodeActions(model: IReadOnlyModel, range: Range): TPromise<CodeAction[]> {
const allResults: CodeAction[] = [];
const promises = CodeActionProviderRegistry.all(model).map(support => {
return asWinJsPromise(token => support.provideCodeActions(model, range, token)).then(result => {
if (Array.isArray(result)) {
allResults.push(...result);
}
}, err => {
onUnexpectedExternalError(err);
});
});
return TPromise.join(promises).then(() => allResults);
}
...@@ -12,7 +12,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; ...@@ -12,7 +12,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { IMarker, IMarkerService } from 'vs/platform/markers/common/markers'; import { IMarker, IMarkerService } from 'vs/platform/markers/common/markers';
import { Range } from 'vs/editor/common/core/range'; import { Range } from 'vs/editor/common/core/range';
import { ICommonCodeEditor } from 'vs/editor/common/editorCommon'; import { ICommonCodeEditor } from 'vs/editor/common/editorCommon';
import { CodeActionProviderRegistry, CodeAction } from 'vs/editor/common/modes'; import { CodeActionProviderRegistry, Command } from 'vs/editor/common/modes';
import { getCodeActions } from './quickFix'; import { getCodeActions } from './quickFix';
import { Position } from 'vs/editor/common/core/position'; import { Position } from 'vs/editor/common/core/position';
...@@ -126,7 +126,7 @@ export interface QuickFixComputeEvent { ...@@ -126,7 +126,7 @@ export interface QuickFixComputeEvent {
type: 'auto' | 'manual'; type: 'auto' | 'manual';
range: Range; range: Range;
position: Position; position: Position;
fixes: TPromise<CodeAction[]>; fixes: TPromise<Command[]>;
} }
export class QuickFixModel { export class QuickFixModel {
......
...@@ -10,7 +10,7 @@ import { always } from 'vs/base/common/async'; ...@@ -10,7 +10,7 @@ import { always } from 'vs/base/common/async';
import { getDomNodePagePosition } from 'vs/base/browser/dom'; import { getDomNodePagePosition } from 'vs/base/browser/dom';
import { Position } from 'vs/editor/common/core/position'; import { Position } from 'vs/editor/common/core/position';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { CodeAction } from 'vs/editor/common/modes'; import { Command } from 'vs/editor/common/modes';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { ICommandService } from 'vs/platform/commands/common/commands'; import { ICommandService } from 'vs/platform/commands/common/commands';
import { Action } from 'vs/base/common/actions'; import { Action } from 'vs/base/common/actions';
...@@ -32,10 +32,10 @@ export class QuickFixContextMenu { ...@@ -32,10 +32,10 @@ export class QuickFixContextMenu {
this._commandService = commandService; this._commandService = commandService;
} }
show(fixes: TPromise<CodeAction[]>, at: { x: number; y: number } | Position) { show(fixes: TPromise<Command[]>, at: { x: number; y: number } | Position) {
const actions = fixes.then(value => { const actions = fixes.then(value => {
return value.map(({ command }) => { return value.map(command => {
return new Action(command.id, command.title, undefined, true, () => { return new Action(command.id, command.title, undefined, true, () => {
return always( return always(
this._commandService.executeCommand(command.id, ...command.arguments), this._commandService.executeCommand(command.id, ...command.arguments),
......
...@@ -38,7 +38,7 @@ suite('QuickFix', () => { ...@@ -38,7 +38,7 @@ suite('QuickFix', () => {
setup(() => { setup(() => {
reg = CodeActionProviderRegistry.register(languageIdentifier.language, { reg = CodeActionProviderRegistry.register(languageIdentifier.language, {
provideCodeActions() { provideCodeActions() {
return [{ command: { id: 'test-command', title: 'test', arguments: [] }, score: 1 }]; return [{ id: 'test-command', title: 'test', arguments: [] }];
} }
}); });
markerService = new MarkerService(); markerService = new MarkerService();
......
...@@ -329,7 +329,7 @@ export function registerCodeLensProvider(languageId: string, provider: modes.Cod ...@@ -329,7 +329,7 @@ export function registerCodeLensProvider(languageId: string, provider: modes.Cod
*/ */
export function registerCodeActionProvider(languageId: string, provider: CodeActionProvider): IDisposable { export function registerCodeActionProvider(languageId: string, provider: CodeActionProvider): IDisposable {
return modes.CodeActionProviderRegistry.register(languageId, { return modes.CodeActionProviderRegistry.register(languageId, {
provideCodeActions: (model: editorCommon.IReadOnlyModel, range: Range, token: CancellationToken): modes.CodeAction[] | Thenable<modes.CodeAction[]> => { provideCodeActions: (model: editorCommon.IReadOnlyModel, range: Range, token: CancellationToken): modes.Command[] | Thenable<modes.Command[]> => {
let markers = StaticServices.markerService.get().read({ resource: model.uri }).filter(m => { let markers = StaticServices.markerService.get().read({ resource: model.uri }).filter(m => {
return Range.areIntersectingOrTouching(m, range); return Range.areIntersectingOrTouching(m, range);
}); });
...@@ -404,7 +404,7 @@ export interface CodeActionProvider { ...@@ -404,7 +404,7 @@ export interface CodeActionProvider {
/** /**
* Provide commands for the given document and range. * Provide commands for the given document and range.
*/ */
provideCodeActions(model: editorCommon.IReadOnlyModel, range: Range, context: CodeActionContext, token: CancellationToken): modes.CodeAction[] | Thenable<modes.CodeAction[]>; provideCodeActions(model: editorCommon.IReadOnlyModel, range: Range, context: CodeActionContext, token: CancellationToken): modes.Command[] | Thenable<modes.Command[]>;
} }
/** /**
......
...@@ -4050,7 +4050,7 @@ declare module monaco.languages { ...@@ -4050,7 +4050,7 @@ declare module monaco.languages {
/** /**
* Provide commands for the given document and range. * Provide commands for the given document and range.
*/ */
provideCodeActions(model: editor.IReadOnlyModel, range: Range, context: CodeActionContext, token: CancellationToken): CodeAction[] | Thenable<CodeAction[]>; provideCodeActions(model: editor.IReadOnlyModel, range: Range, context: CodeActionContext, token: CancellationToken): Command[] | Thenable<Command[]>;
} }
/** /**
...@@ -4425,14 +4425,6 @@ declare module monaco.languages { ...@@ -4425,14 +4425,6 @@ declare module monaco.languages {
provideHover(model: editor.IReadOnlyModel, position: Position, token: CancellationToken): Hover | Thenable<Hover>; provideHover(model: editor.IReadOnlyModel, position: Position, token: CancellationToken): Hover | Thenable<Hover>;
} }
/**
* Interface used to quick fix typing errors while accesing member fields.
*/
export interface CodeAction {
command: Command;
score: number;
}
/** /**
* Represents a parameter of a callable-signature. A parameter can * Represents a parameter of a callable-signature. A parameter can
* have a label and a doc-comment. * have a label and a doc-comment.
......
...@@ -157,7 +157,7 @@ export class MainThreadLanguageFeatures extends MainThreadLanguageFeaturesShape ...@@ -157,7 +157,7 @@ export class MainThreadLanguageFeatures extends MainThreadLanguageFeaturesShape
$registerQuickFixSupport(handle: number, selector: vscode.DocumentSelector): TPromise<any> { $registerQuickFixSupport(handle: number, selector: vscode.DocumentSelector): TPromise<any> {
this._registrations[handle] = modes.CodeActionProviderRegistry.register(selector, <modes.CodeActionProvider>{ this._registrations[handle] = modes.CodeActionProviderRegistry.register(selector, <modes.CodeActionProvider>{
provideCodeActions: (model: IReadOnlyModel, range: EditorRange, token: CancellationToken): Thenable<modes.CodeAction[]> => { provideCodeActions: (model: IReadOnlyModel, range: EditorRange, token: CancellationToken): Thenable<modes.Command[]> => {
return this._heapService.trackRecursive(wireCancellationToken(token, this._proxy.$provideCodeActions(handle, model.uri, range))); return this._heapService.trackRecursive(wireCancellationToken(token, this._proxy.$provideCodeActions(handle, model.uri, range)));
} }
}); });
......
...@@ -464,7 +464,7 @@ export abstract class ExtHostLanguageFeaturesShape { ...@@ -464,7 +464,7 @@ export abstract class ExtHostLanguageFeaturesShape {
$provideHover(handle: number, resource: URI, position: IPosition): TPromise<modes.Hover> { throw ni(); } $provideHover(handle: number, resource: URI, position: IPosition): TPromise<modes.Hover> { throw ni(); }
$provideDocumentHighlights(handle: number, resource: URI, position: IPosition): TPromise<modes.DocumentHighlight[]> { throw ni(); } $provideDocumentHighlights(handle: number, resource: URI, position: IPosition): TPromise<modes.DocumentHighlight[]> { throw ni(); }
$provideReferences(handle: number, resource: URI, position: IPosition, context: modes.ReferenceContext): TPromise<modes.Location[]> { throw ni(); } $provideReferences(handle: number, resource: URI, position: IPosition, context: modes.ReferenceContext): TPromise<modes.Location[]> { throw ni(); }
$provideCodeActions(handle: number, resource: URI, range: IRange): TPromise<modes.CodeAction[]> { throw ni(); } $provideCodeActions(handle: number, resource: URI, range: IRange): TPromise<modes.Command[]> { throw ni(); }
$provideDocumentFormattingEdits(handle: number, resource: URI, options: modes.FormattingOptions): TPromise<editorCommon.ISingleEditOperation[]> { throw ni(); } $provideDocumentFormattingEdits(handle: number, resource: URI, options: modes.FormattingOptions): TPromise<editorCommon.ISingleEditOperation[]> { throw ni(); }
$provideDocumentRangeFormattingEdits(handle: number, resource: URI, range: IRange, options: modes.FormattingOptions): TPromise<editorCommon.ISingleEditOperation[]> { throw ni(); } $provideDocumentRangeFormattingEdits(handle: number, resource: URI, range: IRange, options: modes.FormattingOptions): TPromise<editorCommon.ISingleEditOperation[]> { throw ni(); }
$provideOnTypeFormattingEdits(handle: number, resource: URI, position: IPosition, ch: string, options: modes.FormattingOptions): TPromise<editorCommon.ISingleEditOperation[]> { throw ni(); } $provideOnTypeFormattingEdits(handle: number, resource: URI, position: IPosition, ch: string, options: modes.FormattingOptions): TPromise<editorCommon.ISingleEditOperation[]> { throw ni(); }
......
...@@ -399,11 +399,11 @@ export class ExtHostApiCommands { ...@@ -399,11 +399,11 @@ export class ExtHostApiCommands {
resource, resource,
range: typeConverters.fromRange(range) range: typeConverters.fromRange(range)
}; };
return this._commands.executeCommand<modes.CodeAction[]>('_executeCodeActionProvider', args).then(value => { return this._commands.executeCommand<modes.Command[]>('_executeCodeActionProvider', args).then(value => {
if (!Array.isArray(value)) { if (!Array.isArray(value)) {
return undefined; return undefined;
} }
return value.map(quickFix => this._commands.converter.fromInternal(quickFix.command)); return value.map(quickFix => this._commands.converter.fromInternal(quickFix));
}); });
} }
......
...@@ -271,7 +271,7 @@ class QuickFixAdapter { ...@@ -271,7 +271,7 @@ class QuickFixAdapter {
this._provider = provider; this._provider = provider;
} }
provideCodeActions(resource: URI, range: IRange): TPromise<modes.CodeAction[]> { provideCodeActions(resource: URI, range: IRange): TPromise<modes.Command[]> {
const doc = this._documents.getDocumentData(resource).document; const doc = this._documents.getDocumentData(resource).document;
const ran = TypeConverters.toRange(range); const ran = TypeConverters.toRange(range);
...@@ -291,12 +291,7 @@ class QuickFixAdapter { ...@@ -291,12 +291,7 @@ class QuickFixAdapter {
if (!Array.isArray(commands)) { if (!Array.isArray(commands)) {
return undefined; return undefined;
} }
return commands.map((command, i) => { return commands.map(command => this._commands.toInternal(command));
return <modes.CodeAction>{
command: this._commands.toInternal(command),
score: i
};
});
}); });
} }
} }
...@@ -843,7 +838,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape { ...@@ -843,7 +838,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
return this._createDisposable(handle); return this._createDisposable(handle);
} }
$provideCodeActions(handle: number, resource: URI, range: IRange): TPromise<modes.CodeAction[]> { $provideCodeActions(handle: number, resource: URI, range: IRange): TPromise<modes.Command[]> {
return this._withAdapter(handle, QuickFixAdapter, adapter => adapter.provideCodeActions(resource, range)); return this._withAdapter(handle, QuickFixAdapter, adapter => adapter.provideCodeActions(resource, range));
} }
......
...@@ -650,10 +650,29 @@ suite('ExtHostLanguageFeatures', function () { ...@@ -650,10 +650,29 @@ suite('ExtHostLanguageFeatures', function () {
assert.equal(value.length, 2); assert.equal(value.length, 2);
let [first, second] = value; let [first, second] = value;
assert.equal(first.command.title, 'Testing1'); assert.equal(first.title, 'Testing1');
assert.equal(first.command.id, 'test1'); assert.equal(first.id, 'test1');
assert.equal(second.command.title, 'Testing2'); assert.equal(second.title, 'Testing2');
assert.equal(second.command.id, 'test2'); assert.equal(second.id, 'test2');
});
});
});
test('Cannot read property \'id\' of undefined, #29469', function () {
disposables.push(extHost.registerCodeActionProvider(defaultSelector, <vscode.CodeActionProvider>{
provideCodeActions(): any {
return [
undefined,
null,
<vscode.Command>{ command: 'test', title: 'Testing' }
];
}
}));
return threadService.sync().then(() => {
return getCodeActions(model, model.getFullModelRange()).then(value => {
assert.equal(value.length, 1);
}); });
}); });
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册