diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 9ac2aac764..6724015107 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2871,14 +2871,14 @@ Actual: ${stringify(fullActual)}`); public applyRefactor({ refactorName, actionName, actionDescription, newContent: newContentWithRenameMarker }: FourSlashInterface.ApplyRefactorOptions) { const range = this.getSelection(); const refactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, range); - const refactor = refactors.find(r => r.name === refactorName); - if (!refactor) { + const refactorsWithName = refactors.filter(r => r.name === refactorName); + if (refactorsWithName.length === 0) { this.raiseError(`The expected refactor: ${refactorName} is not available at the marker location.\nAvailable refactors: ${refactors.map(r => r.name)}`); } - const action = refactor.actions.find(a => a.name === actionName); + const action = ts.firstDefined(refactorsWithName, refactor => refactor.actions.find(a => a.name === actionName)); if (!action) { - this.raiseError(`The expected action: ${action} is not included in: ${refactor.actions.map(a => a.name)}`); + this.raiseError(`The expected action: ${actionName} is not included in: ${ts.flatMap(refactorsWithName, r => r.actions.map(a => a.name))}`); } if (action.description !== actionDescription) { this.raiseError(`Expected action description to be ${JSON.stringify(actionDescription)}, got: ${JSON.stringify(action.description)}`); diff --git a/tests/cases/fourslash/extract-const1.ts b/tests/cases/fourslash/extract-const1.ts new file mode 100644 index 0000000000..3ed9373f2b --- /dev/null +++ b/tests/cases/fourslash/extract-const1.ts @@ -0,0 +1,14 @@ +/// + +////const x = /*a*/0/*b*/; + +goTo.select("a", "b"); +edit.applyRefactor({ + refactorName: "Extract Symbol", + actionName: "constant_scope_0", + actionDescription: "Extract to constant in enclosing scope", + newContent: +`const newLocal = 0; + +const x = /*RENAME*/newLocal;` +});