本文整理汇总了TypeScript中vs/editor/common/modes.CodeActionProviderRegistry.all方法的典型用法代码示例。如果您正苦于以下问题:TypeScript CodeActionProviderRegistry.all方法的具体用法?TypeScript CodeActionProviderRegistry.all怎么用?TypeScript CodeActionProviderRegistry.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vs/editor/common/modes.CodeActionProviderRegistry
的用法示例。
在下文中一共展示了CodeActionProviderRegistry.all方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getCodeActions
export function getCodeActions(model: IReadOnlyModel, range: Range): TPromise<IQuickFix2[]> {
const quickFixes: IQuickFix2[] = [];
let ids = new IdGenerator('quickfix');
const promises = CodeActionProviderRegistry.all(model).map(support => {
return asWinJsPromise((token) => {
return support.provideCodeActions(model, range, token);
}).then(result => {
if (!Array.isArray(result)) {
return;
}
for (let fix of result) {
quickFixes.push({
command: fix.command,
score: fix.score,
id: ids.nextId(),
support
});
}
}, err => {
onUnexpectedError(err);
});
});
return TPromise.join(promises).then(() => quickFixes);
}
示例2: getCodeActions
export function getCodeActions(model: ITextModel, range: Range, filter?: CodeActionFilter): TPromise<CodeAction[]> {
const allResults: CodeAction[] = [];
const promises = CodeActionProviderRegistry.all(model).map(support => {
return asWinJsPromise(token => support.provideCodeActions(model, range, { only: filter && filter.kind ? filter.kind.value : undefined }, token)).then(result => {
if (Array.isArray(result)) {
for (const quickFix of result) {
if (!quickFix) {
continue;
}
if (!filter || !filter.kind || (quickFix.kind && filter.kind.contains(quickFix.kind))) {
if (quickFix.kind && CodeActionKind.Source.contains(quickFix.kind) && (!filter || !filter.includeSourceActions)) {
continue;
}
allResults.push(quickFix);
}
}
}
}, err => {
onUnexpectedExternalError(err);
});
});
return TPromise.join(promises).then(
() => mergeSort(allResults, codeActionsComparator)
);
}
示例3: getCodeActions
export function getCodeActions(model: ITextModel, rangeOrSelection: Range | Selection, trigger?: CodeActionTrigger, token: CancellationToken = CancellationToken.None): Promise<CodeAction[]> {
const codeActionContext: CodeActionContext = {
only: trigger && trigger.filter && trigger.filter.kind ? trigger.filter.kind.value : undefined,
trigger: trigger && trigger.type === 'manual' ? CodeActionTriggerKind.Manual : CodeActionTriggerKind.Automatic
};
const promises = CodeActionProviderRegistry.all(model)
.filter(provider => {
// Avoid calling providers that we know will not return code actions of interest
return !provider.providedCodeActionKinds || provider.providedCodeActionKinds.some(providedKind => isValidActionKind(trigger && trigger.filter, providedKind));
})
.map(support => {
return Promise.resolve(support.provideCodeActions(model, rangeOrSelection, codeActionContext, token)).then(providedCodeActions => {
if (!Array.isArray(providedCodeActions)) {
return [];
}
return providedCodeActions.filter(action => isValidAction(trigger && trigger.filter, action));
}, (err): CodeAction[] => {
if (isPromiseCanceledError(err)) {
throw err;
}
onUnexpectedExternalError(err);
return [];
});
});
return Promise.all(promises)
.then(flatten)
.then(allCodeActions => mergeSort(allCodeActions, codeActionsComparator));
}
示例4: getCodeActions
export function getCodeActions(model: ITextModel, rangeOrSelection: Range | Selection, trigger?: CodeActionTrigger): TPromise<CodeAction[]> {
const codeActionContext: CodeActionContext = {
only: trigger && trigger.filter && trigger.filter.kind ? trigger.filter.kind.value : undefined,
trigger: trigger && trigger.type === 'manual' ? CodeActionTriggerKind.Manual : CodeActionTriggerKind.Automatic
};
const promises = CodeActionProviderRegistry.all(model).map(support => {
return asWinJsPromise(token => support.provideCodeActions(model, rangeOrSelection, codeActionContext, token)).then(providedCodeActions => {
if (!Array.isArray(providedCodeActions)) {
return [];
}
return providedCodeActions.filter(action => isValidAction(trigger && trigger.filter, action));
}, (err): CodeAction[] => {
if (isPromiseCanceledError(err)) {
throw err;
}
onUnexpectedExternalError(err);
return [];
});
});
return TPromise.join(promises)
.then(flatten)
.then(allCodeActions => mergeSort(allCodeActions, codeActionsComparator));
}
示例5: getCodeActions
export function getCodeActions(
model: ITextModel,
rangeOrSelection: Range | Selection,
trigger?: CodeActionTrigger,
token: CancellationToken = CancellationToken.None
): Promise<CodeAction[]> {
const codeActionContext: CodeActionContext = {
only: trigger && trigger.filter && trigger.filter.kind ? trigger.filter.kind.value : undefined,
trigger: trigger && trigger.type === 'manual' ? CodeActionTriggerKind.Manual : CodeActionTriggerKind.Automatic
};
const promises = CodeActionProviderRegistry.all(model)
.filter(provider => {
if (!provider.providedCodeActionKinds) {
return true;
}
// Avoid calling providers that we know will not return code actions of interest
return provider.providedCodeActionKinds.some(providedKind => {
// Filter out actions by kind
// The provided kind can be either a subset of a superset of the filtered kind
if (trigger && trigger.filter && trigger.filter.kind && !(trigger.filter.kind.contains(providedKind) || new CodeActionKind(providedKind).contains(trigger.filter.kind.value))) {
return false;
}
// Don't return source actions unless they are explicitly requested
if (trigger && CodeActionKind.Source.contains(providedKind) && (!trigger.filter || !trigger.filter.includeSourceActions)) {
return false;
}
return true;
});
})
.map(support => {
return Promise.resolve(support.provideCodeActions(model, rangeOrSelection, codeActionContext, token)).then(providedCodeActions => {
if (!Array.isArray(providedCodeActions)) {
return [];
}
return providedCodeActions.filter(action => isValidAction(trigger && trigger.filter, action));
}, (err): CodeAction[] => {
if (isPromiseCanceledError(err)) {
throw err;
}
onUnexpectedExternalError(err);
return [];
});
});
return Promise.all(promises)
.then(flatten)
.then(allCodeActions => mergeSort(allCodeActions, codeActionsComparator));
}
示例6: getCodeActionProviders
function getCodeActionProviders(
model: ITextModel,
filter: CodeActionFilter
) {
return CodeActionProviderRegistry.all(model)
// Don't include providers that we know will not return code actions of interest
.filter(provider => {
if (!provider.providedCodeActionKinds) {
// We don't know what type of actions this provider will return.
return true;
}
return provider.providedCodeActionKinds.some(kind => mayIncludeActionsOfKind(filter, new CodeActionKind(kind)));
});
}
示例7: getCodeActions
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);
}
示例8: getCodeActions
export function getCodeActions(model: ITextModel, range: Range, filter?: CodeActionFilter): TPromise<CodeAction[]> {
const codeActionContext = { only: filter && filter.kind ? filter.kind.value : undefined };
const promises = CodeActionProviderRegistry.all(model).map(support => {
return asWinJsPromise(token => support.provideCodeActions(model, range, codeActionContext, token)).then(providedCodeActions => {
if (!Array.isArray(providedCodeActions)) {
return [];
}
return providedCodeActions.filter(action => isValidAction(filter, action));
}, (err): CodeAction[] => {
onUnexpectedExternalError(err);
return [];
});
});
return TPromise.join(promises)
.then(flatten)
.then(allCodeActions => mergeSort(allCodeActions, codeActionsComparator));
}
示例9: getCodeActions
export function getCodeActions(model: ITextModel, 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)) {
for (const quickFix of result) {
if (quickFix) {
allResults.push(quickFix);
}
}
}
}, err => {
onUnexpectedExternalError(err);
});
});
return TPromise.join(promises).then(
() => allResults.sort(codeActionsComparator)
);
}
示例10: getCodeActions
export function getCodeActions(model: ITextModel, range: Range, scope?: CodeActionKind): TPromise<CodeAction[]> {
const allResults: CodeAction[] = [];
const promises = CodeActionProviderRegistry.all(model).map(support => {
return asWinJsPromise(token => support.provideCodeActions(model, range, { only: scope ? scope.value : undefined }, token)).then(result => {
if (Array.isArray(result)) {
for (const quickFix of result) {
if (quickFix) {
if (!scope || (quickFix.kind && scope.contains(quickFix.kind))) {
allResults.push(quickFix);
}
}
}
}
}, err => {
onUnexpectedExternalError(err);
});
});
return TPromise.join(promises).then(
() => mergeSort(allResults, codeActionsComparator)
);
}