Skip to content

Commit c354e51

Browse files
committed
Stop requiring that the full range of a declaration fall within the
selection Fixes microsoft#18546 (cherry picked from commit af49c60)
1 parent 30ac684 commit c354e51

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/harness/unittests/extractMethods.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,11 @@ function parsePrimaryExpression(): any {
700700
}
701701
}|]
702702
}
703+
}`);
704+
// Selection excludes leading trivia of declaration
705+
testExtractMethod("extractMethod33",
706+
`function F() {
707+
[#|function G() { }|]
703708
}`);
704709
});
705710

src/services/refactors/extractMethod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ namespace ts.refactor.extractMethod {
10701070
if (!declInFile) {
10711071
return undefined;
10721072
}
1073-
if (rangeContainsRange(enclosingTextRange, declInFile)) {
1073+
if (rangeContainsStartEnd(enclosingTextRange, declInFile.getStart(), declInFile.end)) {
10741074
// declaration is located in range to be extracted - do nothing
10751075
return undefined;
10761076
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// ==ORIGINAL==
2+
function F() {
3+
function G() { }
4+
}
5+
// ==SCOPE::function 'F'==
6+
function F() {
7+
/*RENAME*/newFunction();
8+
9+
function newFunction() {
10+
function G() { }
11+
}
12+
}
13+
// ==SCOPE::global scope==
14+
function F() {
15+
/*RENAME*/newFunction();
16+
}
17+
function newFunction() {
18+
function G() { }
19+
}

0 commit comments

Comments
 (0)