Skip to content
Permalink
Browse files
fix(37030): Expand Selection in function and arrow function skips bod…
…y block (#50711)

* fix(37030): include curly braces from function body in the selection

* add missed sourceFile argument
  • Loading branch information
a-tarasyuk committed Sep 21, 2022
1 parent e2dd508 commit 4d91204c9d9f27756785f62fade44d93824d47f4
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 12 deletions.
@@ -24,6 +24,11 @@ namespace ts.SmartSelectionRange {
}

if (positionShouldSnapToNode(sourceFile, pos, node)) {
if (isFunctionBody(node)
&& isFunctionLikeDeclaration(parentNode) && !positionsAreOnSameLine(node.getStart(sourceFile), node.getEnd(), sourceFile)) {
pushSelectionRange(node.getStart(sourceFile), node.getEnd());
}

// 1. Blocks are effectively redundant with SyntaxLists.
// 2. TemplateSpans, along with the SyntaxLists containing them, are a somewhat unintuitive grouping
// of things that should be considered independently.
@@ -44,23 +44,28 @@ class Foo {
parent: {
textSpan: { // SyntaxList + whitespace (body of method)
start: { line: 3, offset: 16 },
end: { line: 8, offset: 5 } },
end: { line: 8, offset: 5 }
},
parent: {
textSpan: { // MethodDeclaration
start: { line: 3, offset: 5 },
textSpan: { // {}
start: { line: 3, offset: 15 },
end: { line: 8, offset: 6 } },
parent: {
textSpan: { // SyntaxList + whitespace (body of class)
start: { line: 2, offset: 12 },
end: { line: 9, offset: 1 } },
textSpan: { // MethodDeclaration
start: { line: 3, offset: 5 },
end: { line: 8, offset: 6 } },
parent: {
textSpan: { // ClassDeclaration
start: { line: 2, offset: 1 },
end: { line: 9, offset: 2 } },
textSpan: { // SyntaxList + whitespace (body of class)
start: { line: 2, offset: 12 },
end: { line: 9, offset: 1 } },
parent: {
textSpan: { // SourceFile (all text)
start: { line: 1, offset: 1 },
end: { line: 9, offset: 2 }, } } } } } } } } }]);
textSpan: { // ClassDeclaration
start: { line: 2, offset: 1 },
end: { line: 9, offset: 2 } },
parent: {
textSpan: { // SourceFile (all text)
start: { line: 1, offset: 1 },
end: { line: 9, offset: 2 } } } } } } } } } } }]);
});
});
}
@@ -62,6 +62,13 @@ class HomePage {
••


{
if (this.props.username) {
return '';
}
}


componentDidMount() {
if (this.props.username) {
return '';
@@ -119,6 +126,13 @@ class HomePage {
••


{
if (this.props.username) {
return '';
}
}


componentDidMount() {
if (this.props.username) {
return '';
@@ -0,0 +1,16 @@
const f1 = () => {
/**/
};


{

}

() => {

}

const f1 = () => {

};
@@ -0,0 +1,12 @@
function f2() {
/**/
}


{

}

function f2() {

}
@@ -0,0 +1,16 @@
const f3 = function () {
/**/
}


{

}

function () {

}

const f3 = function () {

}
@@ -27,6 +27,14 @@ class Foo {
••


{
if (a === b) {
return true;
}
return false;
}


bar(a, b) {
if (a === b) {
return true;
@@ -89,6 +97,14 @@ class Foo {
••


{
if (a === b) {
return true;
}
return false;
}


bar(a, b) {
if (a === b) {
return true;
@@ -0,0 +1,7 @@
/// <reference path="fourslash.ts" />

////const f1 = () => {
//// /**/
////};

verify.baselineSmartSelection();
@@ -0,0 +1,7 @@
/// <reference path="fourslash.ts" />

////function f2() {
//// /**/
////}

verify.baselineSmartSelection();
@@ -0,0 +1,7 @@
/// <reference path="fourslash.ts" />

////const f3 = function () {
//// /**/
////}

verify.baselineSmartSelection();

0 comments on commit 4d91204

Please sign in to comment.