MCPcopy Index your code
hub / github.com/nodejs/node / getRefactorActionsToExtractSymbol

Function getRefactorActionsToExtractSymbol

test/fixtures/snapshot/typescript.js:159974–160102  ·  view source on GitHub ↗

* Compute the associated code actions * Exported for tests.

(context)

Source from the content-addressed store, hash-verified

159972 * Exported for tests.
159973 */
159974 function getRefactorActionsToExtractSymbol(context) {
159975 var requestedRefactor = context.kind;
159976 var rangeToExtract = getRangeToExtract(context.file, ts.getRefactorContextSpan(context), context.triggerReason === "invoked");
159977 var targetRange = rangeToExtract.targetRange;
159978 if (targetRange === undefined) {
159979 if (!rangeToExtract.errors || rangeToExtract.errors.length === 0 || !context.preferences.provideRefactorNotApplicableReason) {
159980 return ts.emptyArray;
159981 }
159982 var errors = [];
159983 if (refactor.refactorKindBeginsWith(extractFunctionAction.kind, requestedRefactor)) {
159984 errors.push({
159985 name: refactorName,
159986 description: extractFunctionAction.description,
159987 actions: [__assign(__assign({}, extractFunctionAction), { notApplicableReason: getStringError(rangeToExtract.errors) })]
159988 });
159989 }
159990 if (refactor.refactorKindBeginsWith(extractConstantAction.kind, requestedRefactor)) {
159991 errors.push({
159992 name: refactorName,
159993 description: extractConstantAction.description,
159994 actions: [__assign(__assign({}, extractConstantAction), { notApplicableReason: getStringError(rangeToExtract.errors) })]
159995 });
159996 }
159997 return errors;
159998 }
159999 var extractions = getPossibleExtractions(targetRange, context);
160000 if (extractions === undefined) {
160001 // No extractions possible
160002 return ts.emptyArray;
160003 }
160004 var functionActions = [];
160005 var usedFunctionNames = new ts.Map();
160006 var innermostErrorFunctionAction;
160007 var constantActions = [];
160008 var usedConstantNames = new ts.Map();
160009 var innermostErrorConstantAction;
160010 var i = 0;
160011 for (var _i = 0, extractions_1 = extractions; _i < extractions_1.length; _i++) {
160012 var _a = extractions_1[_i], functionExtraction = _a.functionExtraction, constantExtraction = _a.constantExtraction;
160013 var description = functionExtraction.description;
160014 if (refactor.refactorKindBeginsWith(extractFunctionAction.kind, requestedRefactor)) {
160015 if (functionExtraction.errors.length === 0) {
160016 // Don't issue refactorings with duplicated names.
160017 // Scopes come back in "innermost first" order, so extractions will
160018 // preferentially go into nearer scopes
160019 if (!usedFunctionNames.has(description)) {
160020 usedFunctionNames.set(description, true);
160021 functionActions.push({
160022 description: description,
160023 name: "function_scope_".concat(i),
160024 kind: extractFunctionAction.kind
160025 });
160026 }
160027 }
160028 else if (!innermostErrorFunctionAction) {
160029 innermostErrorFunctionAction = {
160030 description: description,
160031 name: "function_scope_".concat(i),

Callers

nothing calls this directly

Calls 7

getRangeToExtractFunction · 0.85
getStringErrorFunction · 0.85
getPossibleExtractionsFunction · 0.85
concatMethod · 0.80
hasMethod · 0.65
pushMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected