mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-12 02:58:31 -05:00
Merge from vscode a5cf1da01d5db3d2557132be8d30f89c38019f6c (#8525)
* Merge from vscode a5cf1da01d5db3d2557132be8d30f89c38019f6c * remove files we don't want * fix hygiene * update distro * update distro * fix hygiene * fix strict nulls * distro * distro * fix tests * fix tests * add another edit * fix viewlet icon * fix azure dialog * fix some padding * fix more padding issues
This commit is contained in:
@@ -13,12 +13,19 @@ import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { CodeAction, CodeActionContext, CodeActionProviderRegistry, CodeActionTrigger as CodeActionTriggerKind } from 'vs/editor/common/modes';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
import { CodeActionFilter, CodeActionKind, CodeActionTrigger, filtersAction, mayIncludeActionsOfKind } from './codeActionTrigger';
|
||||
import { CodeActionFilter, CodeActionKind, CodeActionTrigger, filtersAction, mayIncludeActionsOfKind } from './types';
|
||||
import { TextModelCancellationTokenSource } from 'vs/editor/browser/core/editorState';
|
||||
import { DisposableStore, IDisposable, Disposable } from 'vs/base/common/lifecycle';
|
||||
|
||||
export const codeActionCommandId = 'editor.action.codeAction';
|
||||
export const refactorCommandId = 'editor.action.refactor';
|
||||
export const sourceActionCommandId = 'editor.action.sourceAction';
|
||||
export const organizeImportsCommandId = 'editor.action.organizeImports';
|
||||
export const fixAllCommandId = 'editor.action.fixAll';
|
||||
|
||||
export interface CodeActionSet extends IDisposable {
|
||||
readonly actions: readonly CodeAction[];
|
||||
readonly validActions: readonly CodeAction[];
|
||||
readonly allActions: readonly CodeAction[];
|
||||
readonly hasAutoFix: boolean;
|
||||
}
|
||||
|
||||
@@ -38,16 +45,18 @@ class ManagedCodeActionSet extends Disposable implements CodeActionSet {
|
||||
}
|
||||
}
|
||||
|
||||
public readonly actions: readonly CodeAction[];
|
||||
public readonly validActions: readonly CodeAction[];
|
||||
public readonly allActions: readonly CodeAction[];
|
||||
|
||||
public constructor(actions: readonly CodeAction[], disposables: DisposableStore) {
|
||||
super();
|
||||
this._register(disposables);
|
||||
this.actions = mergeSort([...actions], ManagedCodeActionSet.codeActionsComparator);
|
||||
this.allActions = mergeSort([...actions], ManagedCodeActionSet.codeActionsComparator);
|
||||
this.validActions = this.allActions.filter(action => !action.disabled);
|
||||
}
|
||||
|
||||
public get hasAutoFix() {
|
||||
return this.actions.some(fix => !!fix.kind && CodeActionKind.QuickFix.contains(new CodeActionKind(fix.kind)) && !!fix.isPreferred);
|
||||
return this.validActions.some(fix => !!fix.kind && CodeActionKind.QuickFix.contains(new CodeActionKind(fix.kind)) && !!fix.isPreferred);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +69,7 @@ export function getCodeActions(
|
||||
const filter = trigger.filter || {};
|
||||
|
||||
const codeActionContext: CodeActionContext = {
|
||||
only: filter.kind ? filter.kind.value : undefined,
|
||||
only: filter.include?.value,
|
||||
trigger: trigger.type === 'manual' ? CodeActionTriggerKind.Manual : CodeActionTriggerKind.Automatic
|
||||
};
|
||||
|
||||
@@ -68,21 +77,21 @@ export function getCodeActions(
|
||||
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 => {
|
||||
const promises = providers.map(async provider => {
|
||||
try {
|
||||
const providedCodeActions = await provider.provideCodeActions(model, rangeOrSelection, codeActionContext, cts.token);
|
||||
if (cts.token.isCancellationRequested || !providedCodeActions) {
|
||||
return [];
|
||||
}
|
||||
disposables.add(providedCodeActions);
|
||||
return providedCodeActions.actions.filter(action => action && filtersAction(filter, action));
|
||||
}, (err): CodeAction[] => {
|
||||
} catch (err) {
|
||||
if (isPromiseCanceledError(err)) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
onUnexpectedExternalError(err);
|
||||
return [];
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const listener = CodeActionProviderRegistry.onDidChange(() => {
|
||||
@@ -140,9 +149,9 @@ registerLanguageCommand('_executeCodeActionProvider', async function (accessor,
|
||||
const codeActionSet = await getCodeActions(
|
||||
model,
|
||||
validatedRangeOrSelection,
|
||||
{ type: 'manual', filter: { includeSourceActions: true, kind: kind && kind.value ? new CodeActionKind(kind.value) : undefined } },
|
||||
{ type: 'manual', filter: { includeSourceActions: true, include: kind && kind.value ? new CodeActionKind(kind.value) : undefined } },
|
||||
CancellationToken.None);
|
||||
|
||||
setTimeout(() => codeActionSet.dispose(), 100);
|
||||
return codeActionSet.actions;
|
||||
return codeActionSet.validActions;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user