當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript CodeActionProviderRegistry.all方法代碼示例

本文整理匯總了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);
}
開發者ID:CPoirot3,項目名稱:vscode,代碼行數:26,代碼來源:quickFix.ts

示例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)
	);
}
開發者ID:costincaraivan,項目名稱:vscode,代碼行數:28,代碼來源:quickFix.ts

示例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));
}
開發者ID:ramesius,項目名稱:vscode,代碼行數:31,代碼來源:codeAction.ts

示例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));
}
開發者ID:jinlongchen2018,項目名稱:vscode,代碼行數:26,代碼來源:codeAction.ts

示例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));
}
開發者ID:VishalMadhvani,項目名稱:vscode,代碼行數:53,代碼來源:codeAction.ts

示例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)));
		});
}
開發者ID:eamodio,項目名稱:vscode,代碼行數:14,代碼來源:codeAction.ts

示例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);
}
開發者ID:StateFarmIns,項目名稱:vscode,代碼行數:15,代碼來源:quickFix.ts

示例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));
}
開發者ID:AllureFer,項目名稱:vscode,代碼行數:19,代碼來源:codeAction.ts

示例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)
	);
}
開發者ID:servicesgpr,項目名稱:vscode,代碼行數:21,代碼來源:quickFix.ts

示例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)
	);
}
開發者ID:sameer-coder,項目名稱:vscode,代碼行數:23,代碼來源:quickFix.ts


注:本文中的vs/editor/common/modes.CodeActionProviderRegistry.all方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。