Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 (#6381)

* Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973

* disable strict null check
This commit is contained in:
Anthony Dresser
2019-07-15 22:35:46 -07:00
committed by GitHub
parent f720ec642f
commit 0b7e7ddbf9
2406 changed files with 59140 additions and 35464 deletions

View File

@@ -15,8 +15,14 @@ import { CodeAction, CodeActionContext, CodeActionProviderRegistry, CodeActionTr
import { IModelService } from 'vs/editor/common/services/modelService';
import { CodeActionFilter, CodeActionKind, CodeActionTrigger, filtersAction, mayIncludeActionsOfKind } from './codeActionTrigger';
import { TextModelCancellationTokenSource } from 'vs/editor/browser/core/editorState';
import { Disposable, DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
export class CodeActionSet {
export interface CodeActionSet extends IDisposable {
readonly actions: readonly CodeAction[];
readonly hasAutoFix: boolean;
}
class ManagedCodeActionSet extends Disposable implements CodeActionSet {
private static codeActionsComparator(a: CodeAction, b: CodeAction): number {
if (isNonEmptyArray(a.diagnostics)) {
@@ -34,8 +40,10 @@ export class CodeActionSet {
public readonly actions: readonly CodeAction[];
public constructor(actions: readonly CodeAction[]) {
this.actions = mergeSort([...actions], CodeActionSet.codeActionsComparator);
public constructor(actions: readonly CodeAction[], disposables: DisposableStore) {
super();
this._register(disposables);
this.actions = mergeSort([...actions], ManagedCodeActionSet.codeActionsComparator);
}
public get hasAutoFix() {
@@ -59,12 +67,14 @@ export function getCodeActions(
const cts = new TextModelCancellationTokenSource(model, token);
const providers = getCodeActionProviders(model, filter);
const disposables = new DisposableStore();
const promises = providers.map(provider => {
return Promise.resolve(provider.provideCodeActions(model, rangeOrSelection, codeActionContext, cts.token)).then(providedCodeActions => {
if (cts.token.isCancellationRequested || !Array.isArray(providedCodeActions)) {
if (cts.token.isCancellationRequested || !providedCodeActions) {
return [];
}
return providedCodeActions.filter(action => action && filtersAction(filter, action));
disposables.add(providedCodeActions);
return providedCodeActions.actions.filter(action => action && filtersAction(filter, action));
}, (err): CodeAction[] => {
if (isPromiseCanceledError(err)) {
throw err;
@@ -84,7 +94,7 @@ export function getCodeActions(
return Promise.all(promises)
.then(flatten)
.then(actions => new CodeActionSet(actions))
.then(actions => new ManagedCodeActionSet(actions, disposables))
.finally(() => {
listener.dispose();
cts.dispose();
@@ -106,7 +116,7 @@ function getCodeActionProviders(
});
}
registerLanguageCommand('_executeCodeActionProvider', function (accessor, args): Promise<ReadonlyArray<CodeAction>> {
registerLanguageCommand('_executeCodeActionProvider', async function (accessor, args): Promise<ReadonlyArray<CodeAction>> {
const { resource, range, kind } = args;
if (!(resource instanceof URI) || !Range.isIRange(range)) {
throw illegalArgument();
@@ -117,9 +127,12 @@ registerLanguageCommand('_executeCodeActionProvider', function (accessor, args):
throw illegalArgument();
}
return getCodeActions(
const codeActionSet = await getCodeActions(
model,
model.validateRange(range),
{ type: 'manual', filter: { includeSourceActions: true, kind: kind && kind.value ? new CodeActionKind(kind.value) : undefined } },
CancellationToken.None).then(actions => actions.actions);
CancellationToken.None);
setTimeout(() => codeActionSet.dispose(), 0);
return codeActionSet.actions;
});