Merge VS Code 1.31.1 (#4283)

This commit is contained in:
Matt Irvine
2019-03-15 13:09:45 -07:00
committed by GitHub
parent 7d31575149
commit 86bac90001
1716 changed files with 53308 additions and 48375 deletions

View File

@@ -21,7 +21,7 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IMarkerService } from 'vs/platform/markers/common/markers';
import { IProgressService } from 'vs/platform/progress/common/progress';
import { CodeActionModel, CodeActionsComputeEvent, SUPPORTED_CODE_ACTIONS } from './codeActionModel';
import { CodeActionModel, SUPPORTED_CODE_ACTIONS, CodeActionsState } from './codeActionModel';
import { CodeActionAutoApply, CodeActionFilter, CodeActionKind } from './codeActionTrigger';
import { CodeActionContextMenu } from './codeActionWidget';
import { LightBulbWidget } from './lightBulbWidget';
@@ -69,7 +69,7 @@ export class QuickFixController implements IEditorContribution {
this._disposables.push(
this._codeActionContextMenu.onDidExecuteCodeAction(_ => this._model.trigger({ type: 'auto', filter: {} })),
this._lightBulbWidget.onClick(this._handleLightBulbSelect, this),
this._model.onDidChangeFixes(e => this._onCodeActionsEvent(e)),
this._model.onDidChangeState(e => this._onDidChangeCodeActionsState(e)),
this._keybindingService.onDidUpdateKeybindings(this._updateLightBulbTitle, this)
);
}
@@ -79,39 +79,39 @@ export class QuickFixController implements IEditorContribution {
dispose(this._disposables);
}
private _onCodeActionsEvent(e: CodeActionsComputeEvent): void {
private _onDidChangeCodeActionsState(newState: CodeActionsState.State): void {
if (this._activeRequest) {
this._activeRequest.cancel();
this._activeRequest = undefined;
}
if (e && e.actions) {
this._activeRequest = e.actions;
}
if (newState.type === CodeActionsState.Type.Triggered) {
this._activeRequest = newState.actions;
if (e && e.actions && e.trigger.filter && e.trigger.filter.kind) {
// Triggered for specific scope
// Apply if we only have one action or requested autoApply, otherwise show menu
e.actions.then(fixes => {
if (fixes.length > 0 && e.trigger.autoApply === CodeActionAutoApply.First || (e.trigger.autoApply === CodeActionAutoApply.IfSingle && fixes.length === 1)) {
this._onApplyCodeAction(fixes[0]);
} else {
this._codeActionContextMenu.show(e.actions, e.position);
}
}).catch(onUnexpectedError);
return;
}
if (newState.trigger.filter && newState.trigger.filter.kind) {
// Triggered for specific scope
newState.actions.then(fixes => {
if (fixes.length > 0) {
// Apply if we only have one action or requested autoApply
if (newState.trigger.autoApply === CodeActionAutoApply.First || (newState.trigger.autoApply === CodeActionAutoApply.IfSingle && fixes.length === 1)) {
this._onApplyCodeAction(fixes[0]);
return;
}
}
this._codeActionContextMenu.show(newState.actions, newState.position);
if (e && e.trigger.type === 'manual') {
this._codeActionContextMenu.show(e.actions, e.position);
} else if (e && e.actions) {
// auto magically triggered
// * update an existing list of code actions
// * manage light bulb
if (this._codeActionContextMenu.isVisible) {
this._codeActionContextMenu.show(e.actions, e.position);
}).catch(onUnexpectedError);
} else if (newState.trigger.type === 'manual') {
this._codeActionContextMenu.show(newState.actions, newState.position);
} else {
this._lightBulbWidget.model = e;
// auto magically triggered
// * update an existing list of code actions
// * manage light bulb
if (this._codeActionContextMenu.isVisible) {
this._codeActionContextMenu.show(newState.actions, newState.position);
} else {
this._lightBulbWidget.tryShow(newState);
}
}
} else {
this._lightBulbWidget.hide();
@@ -122,13 +122,11 @@ export class QuickFixController implements IEditorContribution {
return QuickFixController.ID;
}
private _handleLightBulbSelect(coords: { x: number, y: number }): void {
if (this._lightBulbWidget.model && this._lightBulbWidget.model.actions) {
this._codeActionContextMenu.show(this._lightBulbWidget.model.actions, coords);
}
private _handleLightBulbSelect(e: { x: number, y: number, state: CodeActionsState.Triggered }): void {
this._codeActionContextMenu.show(e.state.actions, e);
}
public triggerFromEditorSelection(filter?: CodeActionFilter, autoApply?: CodeActionAutoApply): Thenable<CodeAction[] | undefined> {
public triggerFromEditorSelection(filter?: CodeActionFilter, autoApply?: CodeActionAutoApply): Promise<CodeAction[] | undefined> {
return this._model.trigger({ type: 'manual', filter, autoApply });
}
@@ -158,7 +156,7 @@ export async function applyCodeAction(
await bulkEditService.apply(action.edit, { editor });
}
if (action.command) {
await commandService.executeCommand(action.command.id, ...action.command.arguments);
await commandService.executeCommand(action.command.id, ...(action.command.arguments || []));
}
}
@@ -168,6 +166,10 @@ function showCodeActionsForEditorSelection(
filter?: CodeActionFilter,
autoApply?: CodeActionAutoApply
) {
if (!editor.hasModel()) {
return;
}
const controller = QuickFixController.get(editor);
if (!controller) {
return;
@@ -206,38 +208,41 @@ export class QuickFixAction extends EditorAction {
class CodeActionCommandArgs {
public static fromUser(arg: any): CodeActionCommandArgs {
public static fromUser(arg: any, defaults: { kind: CodeActionKind, apply: CodeActionAutoApply }): CodeActionCommandArgs {
if (!arg || typeof arg !== 'object') {
return new CodeActionCommandArgs(CodeActionKind.Empty, CodeActionAutoApply.IfSingle);
return new CodeActionCommandArgs(defaults.kind, defaults.apply, false);
}
return new CodeActionCommandArgs(
CodeActionCommandArgs.getKindFromUser(arg),
CodeActionCommandArgs.getApplyFromUser(arg));
CodeActionCommandArgs.getKindFromUser(arg, defaults.kind),
CodeActionCommandArgs.getApplyFromUser(arg, defaults.apply),
CodeActionCommandArgs.getPreferredUser(arg));
}
private static getApplyFromUser(arg: any) {
private static getApplyFromUser(arg: any, defaultAutoApply: CodeActionAutoApply) {
switch (typeof arg.apply === 'string' ? arg.apply.toLowerCase() : '') {
case 'first':
return CodeActionAutoApply.First;
case 'never':
return CodeActionAutoApply.Never;
case 'ifsingle':
default:
return CodeActionAutoApply.IfSingle;
case 'first': return CodeActionAutoApply.First;
case 'never': return CodeActionAutoApply.Never;
case 'ifsingle': return CodeActionAutoApply.IfSingle;
default: return defaultAutoApply;
}
}
private static getKindFromUser(arg: any) {
private static getKindFromUser(arg: any, defaultKind: CodeActionKind) {
return typeof arg.kind === 'string'
? new CodeActionKind(arg.kind)
: CodeActionKind.Empty;
: defaultKind;
}
private static getPreferredUser(arg: any): boolean {
return typeof arg.preferred === 'boolean'
? arg.preferred
: false;
}
private constructor(
public readonly kind: CodeActionKind,
public readonly apply: CodeActionAutoApply
public readonly apply: CodeActionAutoApply,
public readonly preferred: boolean,
) { }
}
@@ -253,8 +258,17 @@ export class CodeActionCommand extends EditorCommand {
}
public runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor, userArg: any) {
const args = CodeActionCommandArgs.fromUser(userArg);
return showCodeActionsForEditorSelection(editor, nls.localize('editor.action.quickFix.noneMessage', "No code actions available"), { kind: args.kind, includeSourceActions: true }, args.apply);
const args = CodeActionCommandArgs.fromUser(userArg, {
kind: CodeActionKind.Empty,
apply: CodeActionAutoApply.IfSingle,
});
return showCodeActionsForEditorSelection(editor, nls.localize('editor.action.quickFix.noneMessage', "No code actions available"),
{
kind: args.kind,
includeSourceActions: true,
onlyIncludePreferredActions: args.preferred,
},
args.apply);
}
}
@@ -287,11 +301,18 @@ export class RefactorAction extends EditorAction {
});
}
public run(_accessor: ServicesAccessor, editor: ICodeEditor): void {
public run(_accessor: ServicesAccessor, editor: ICodeEditor, userArg: any): void {
const args = CodeActionCommandArgs.fromUser(userArg, {
kind: CodeActionKind.Refactor,
apply: CodeActionAutoApply.Never
});
return showCodeActionsForEditorSelection(editor,
nls.localize('editor.action.refactor.noneMessage', "No refactorings available"),
{ kind: CodeActionKind.Refactor },
CodeActionAutoApply.Never);
{
kind: CodeActionKind.Refactor.contains(args.kind) ? args.kind : CodeActionKind.Empty,
onlyIncludePreferredActions: args.preferred,
},
args.apply);
}
}
@@ -316,11 +337,19 @@ export class SourceAction extends EditorAction {
});
}
public run(_accessor: ServicesAccessor, editor: ICodeEditor): void {
public run(_accessor: ServicesAccessor, editor: ICodeEditor, userArg: any): void {
const args = CodeActionCommandArgs.fromUser(userArg, {
kind: CodeActionKind.Source,
apply: CodeActionAutoApply.Never
});
return showCodeActionsForEditorSelection(editor,
nls.localize('editor.action.source.noneMessage', "No source actions available"),
{ kind: CodeActionKind.Source, includeSourceActions: true },
CodeActionAutoApply.Never);
{
kind: CodeActionKind.Source.contains(args.kind) ? args.kind : CodeActionKind.Empty,
includeSourceActions: true,
onlyIncludePreferredActions: args.preferred,
},
args.apply);
}
}
@@ -350,4 +379,38 @@ export class OrganizeImportsAction extends EditorAction {
{ kind: CodeActionKind.SourceOrganizeImports, includeSourceActions: true },
CodeActionAutoApply.IfSingle);
}
}
}
export class AutoFixAction extends EditorAction {
static readonly Id = 'editor.action.autoFix';
constructor() {
super({
id: AutoFixAction.Id,
label: nls.localize('autoFix.label', "Auto Fix..."),
alias: 'Auto Fix',
precondition: ContextKeyExpr.and(
EditorContextKeys.writable,
contextKeyForSupportedActions(CodeActionKind.QuickFix)),
kbOpts: {
kbExpr: EditorContextKeys.editorTextFocus,
primary: KeyMod.Alt | KeyMod.Shift | KeyCode.US_DOT,
mac: {
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.US_DOT
},
weight: KeybindingWeight.EditorContrib
}
});
}
public run(_accessor: ServicesAccessor, editor: ICodeEditor): void {
return showCodeActionsForEditorSelection(editor,
nls.localize('editor.action.autoFix.noneMessage', "No auto fixes available"),
{
kind: CodeActionKind.QuickFix,
onlyIncludePreferredActions: true
},
CodeActionAutoApply.IfSingle);
}
}