mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Merge pull request #28340 from saschanaz/listindent-revive
List position based formatting
This commit is contained in:
@@ -1,52 +1,160 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////Promise
|
||||
//// .resolve()
|
||||
//// .then(() => {/*1*/""/*2*/
|
||||
////}).then(() => {/*3*//*4*/
|
||||
////})/*semi1*//*semi2*/
|
||||
|
||||
////function foo() {
|
||||
//// return Promise.resolve()
|
||||
//// .then(function () {
|
||||
//// ""/*a*/
|
||||
//// })/*b*/
|
||||
////}
|
||||
|
||||
////Promise
|
||||
//// .then(
|
||||
//// /*n1*/
|
||||
//// )
|
||||
//// /*n2*/
|
||||
//// .then();
|
||||
|
||||
|
||||
goTo.marker('1');
|
||||
edit.insertLine('');
|
||||
goTo.marker('2');
|
||||
verify.currentLineContentIs(' ""');
|
||||
edit.insertLine('');
|
||||
verify.indentationIs(8);
|
||||
goTo.marker('4');
|
||||
edit.insertLine('');
|
||||
goTo.marker('3');
|
||||
verify.currentLineContentIs(' }).then(() => {');
|
||||
|
||||
goTo.marker("semi1");
|
||||
edit.insert(';');
|
||||
verify.currentLineContentIs(' });');
|
||||
goTo.marker("semi2");
|
||||
edit.insert(';');
|
||||
verify.currentLineContentIs(' });;');
|
||||
|
||||
goTo.marker('a');
|
||||
edit.insert(';');
|
||||
verify.currentLineContentIs(' "";');
|
||||
goTo.marker('b');
|
||||
edit.insert(';');
|
||||
verify.currentLineContentIs(' });');
|
||||
|
||||
goTo.marker('n1');
|
||||
verify.indentationIs(8);
|
||||
goTo.marker('n2');
|
||||
verify.indentationIs(4);
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////Promise
|
||||
//// .resolve()
|
||||
//// .then(() => {/*1*/""/*2*/
|
||||
////}).then(() => {/*3*//*4*/
|
||||
////})/*semi1*//*semi2*/
|
||||
|
||||
////function foo() {
|
||||
//// return Promise.resolve()
|
||||
//// .then(function () {
|
||||
//// ""/*a*/
|
||||
//// })/*b*/
|
||||
////}
|
||||
|
||||
////Promise
|
||||
//// .then(
|
||||
//// /*n1*/
|
||||
//// )
|
||||
//// /*n2*/
|
||||
//// .then();
|
||||
|
||||
// @Filename: listSmart.ts
|
||||
////Promise
|
||||
//// .resolve().then(
|
||||
//// /*listSmart1*/
|
||||
//// 3,
|
||||
//// /*listSmart2*/
|
||||
//// [
|
||||
//// 3
|
||||
//// /*listSmart3*/
|
||||
//// ]
|
||||
//// /*listSmart4*/
|
||||
//// );
|
||||
|
||||
// @Filename: listZeroIndent.ts
|
||||
////Promise.resolve([
|
||||
////]).then(
|
||||
//// /*listZeroIndent1*/
|
||||
//// [
|
||||
//// /*listZeroIndent2*/
|
||||
//// 3
|
||||
//// ]
|
||||
//// );
|
||||
|
||||
// @Filename: listTypeParameter1.ts
|
||||
////foo.then
|
||||
//// <
|
||||
//// /*listTypeParameter1*/
|
||||
//// void
|
||||
//// /*listTypeParameter2*/
|
||||
//// >(
|
||||
//// function (): void {
|
||||
//// },
|
||||
//// function (): void {
|
||||
//// }
|
||||
//// );
|
||||
|
||||
// @Filename: listComment.ts
|
||||
////Promise
|
||||
//// .then(
|
||||
//// // euphonium
|
||||
//// "k"
|
||||
//// // oboe
|
||||
//// );
|
||||
|
||||
|
||||
goTo.marker('1');
|
||||
edit.insertLine('');
|
||||
goTo.marker('2');
|
||||
verify.currentLineContentIs(' ""');
|
||||
edit.insertLine('');
|
||||
verify.indentationIs(8);
|
||||
goTo.marker('4');
|
||||
edit.insertLine('');
|
||||
goTo.marker('3');
|
||||
verify.currentLineContentIs(' }).then(() => {');
|
||||
|
||||
goTo.marker("semi1");
|
||||
edit.insert(';');
|
||||
verify.currentLineContentIs(' });');
|
||||
goTo.marker("semi2");
|
||||
edit.insert(';');
|
||||
verify.currentLineContentIs(' });;');
|
||||
|
||||
goTo.marker('a');
|
||||
edit.insert(';');
|
||||
verify.currentLineContentIs(' "";');
|
||||
goTo.marker('b');
|
||||
edit.insert(';');
|
||||
verify.currentLineContentIs(' });');
|
||||
|
||||
goTo.marker('n1');
|
||||
verify.indentationIs(8);
|
||||
goTo.marker('n2');
|
||||
verify.indentationIs(4);
|
||||
|
||||
goTo.file("listSmart.ts");
|
||||
format.document();
|
||||
verify.currentFileContentIs(`Promise
|
||||
.resolve().then(
|
||||
|
||||
3,
|
||||
|
||||
[
|
||||
3
|
||||
|
||||
]
|
||||
|
||||
);`);
|
||||
goTo.marker("listSmart1");
|
||||
verify.indentationIs(8);
|
||||
goTo.marker("listSmart2");
|
||||
verify.indentationIs(8);
|
||||
goTo.marker("listSmart3");
|
||||
verify.indentationIs(12);
|
||||
goTo.marker("listSmart4");
|
||||
verify.indentationIs(8);
|
||||
|
||||
goTo.file("listZeroIndent.ts");
|
||||
format.document();
|
||||
verify.currentFileContentIs(`Promise.resolve([
|
||||
]).then(
|
||||
|
||||
[
|
||||
|
||||
3
|
||||
]
|
||||
);`);
|
||||
goTo.marker("listZeroIndent1");
|
||||
verify.indentationIs(4);
|
||||
goTo.marker("listZeroIndent2");
|
||||
verify.indentationIs(8);
|
||||
|
||||
goTo.file("listTypeParameter1.ts");
|
||||
format.document();
|
||||
verify.currentFileContentIs(`foo.then
|
||||
<
|
||||
|
||||
void
|
||||
|
||||
>(
|
||||
function(): void {
|
||||
},
|
||||
function(): void {
|
||||
}
|
||||
);`);
|
||||
goTo.marker("listTypeParameter1");
|
||||
verify.indentationIs(8);
|
||||
goTo.marker("listTypeParameter2");
|
||||
verify.indentationIs(8);
|
||||
|
||||
goTo.file("listComment.ts");
|
||||
format.document();
|
||||
verify.currentFileContentIs(`Promise
|
||||
.then(
|
||||
// euphonium
|
||||
"k"
|
||||
// oboe
|
||||
);`)
|
||||
|
||||
37
tests/cases/fourslash/formattingOnTypeLiteral.ts
Normal file
37
tests/cases/fourslash/formattingOnTypeLiteral.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////function _uniteVertices<p extends string, a>(
|
||||
//// minority: Pinned<p, Vertex<a>>,
|
||||
//// majorityCounter: number,
|
||||
//// majority: Pinned<p, Vertex<a>>
|
||||
////): {
|
||||
//// /*start*/
|
||||
//// majorityCounter: number;
|
||||
//// vertecis: Pinned<p, {
|
||||
//// oldVertexId: VertexId;
|
||||
//// vertex: Vertex<a>;
|
||||
//// }>;
|
||||
//// /*end*/
|
||||
//// } {
|
||||
////}
|
||||
|
||||
format.document();
|
||||
verify.currentFileContentIs(`function _uniteVertices<p extends string, a>(
|
||||
minority: Pinned<p, Vertex<a>>,
|
||||
majorityCounter: number,
|
||||
majority: Pinned<p, Vertex<a>>
|
||||
): {
|
||||
|
||||
majorityCounter: number;
|
||||
vertecis: Pinned<p, {
|
||||
oldVertexId: VertexId;
|
||||
vertex: Vertex<a>;
|
||||
}>;
|
||||
|
||||
} {
|
||||
}`);
|
||||
|
||||
goTo.marker("start");
|
||||
verify.indentationIs(4);
|
||||
goTo.marker("end");
|
||||
verify.indentationIs(4);
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
//// function foo(a?,b?) { b(a); }
|
||||
////
|
||||
//// (foo)(1, function() {/*4_0*/
|
||||
//// (foo)(1, function() {/*4_1*/
|
||||
//// });
|
||||
////
|
||||
//// // No line-breaks in the expression part of the call expression
|
||||
@@ -20,7 +20,7 @@
|
||||
//// // Contains line-breaks in the expression part of the call expression.
|
||||
////
|
||||
//// (
|
||||
//// foo)(1, function () {/*4_1*/
|
||||
//// foo)(1, function () {/*8_4*/
|
||||
//// });
|
||||
//// (foo
|
||||
//// )(1, function () {/*4_3*/
|
||||
@@ -38,14 +38,14 @@
|
||||
//// {/*4_4*/
|
||||
//// });
|
||||
|
||||
for (let i = 0; i < 5; ++i) {
|
||||
for (let i = 1; i < 5; ++i) {
|
||||
goTo.marker(`4_${i}`);
|
||||
edit.insertLine("");
|
||||
verify.indentationIs(4);
|
||||
}
|
||||
|
||||
for (let i = 1; i < 4; ++i) {
|
||||
for (let i = 1; i < 5; ++i) {
|
||||
goTo.marker(`8_${i}`);
|
||||
edit.insertLine("");
|
||||
verify.indentationIs(8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,8 @@ function verifyIndentationAfterNewLine(marker: string, indentation: number): voi
|
||||
verify.indentationIs(indentation);
|
||||
}
|
||||
|
||||
// TODO (arozga): fix this.
|
||||
// verifyIndentationAfterNewLine("1", 4);
|
||||
verifyIndentationAfterNewLine("1", 0);
|
||||
verifyIndentationAfterNewLine("1", 4);
|
||||
verifyIndentationAfterNewLine("2", 8);
|
||||
verifyIndentationAfterNewLine("3", 8);
|
||||
verifyIndentationAfterNewLine("4", 8);
|
||||
verifyIndentationAfterNewLine("5", 8);
|
||||
verifyIndentationAfterNewLine("5", 8);
|
||||
|
||||
@@ -8,11 +8,9 @@ function verifyIndentationAfterNewLine(marker: string, indentation: number): voi
|
||||
verify.indentationIs(indentation);
|
||||
}
|
||||
|
||||
// TODO(arozga): fix this
|
||||
// verifyIndentationAfterNewLine("1", 4);
|
||||
verifyIndentationAfterNewLine("1", 0);
|
||||
verifyIndentationAfterNewLine("1", 4);
|
||||
verifyIndentationAfterNewLine("2", 8);
|
||||
verifyIndentationAfterNewLine("3", 8);
|
||||
verifyIndentationAfterNewLine("4", 8);
|
||||
verifyIndentationAfterNewLine("5", 8);
|
||||
verifyIndentationAfterNewLine("6", 0);
|
||||
verifyIndentationAfterNewLine("6", 0);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
//// var a =
|
||||
//// {/*1*/}
|
||||
//// var a =/*1*/
|
||||
//// {/*2*/}
|
||||
////
|
||||
//// var b = {
|
||||
//// outer:
|
||||
//// {/*2*/}
|
||||
//// outer:/*3*/
|
||||
//// {/*4*/}
|
||||
//// }
|
||||
|
||||
function verifyIndentationAfterNewLine(marker: string, indentation: number): void {
|
||||
@@ -15,4 +15,6 @@ function verifyIndentationAfterNewLine(marker: string, indentation: number): voi
|
||||
}
|
||||
|
||||
verifyIndentationAfterNewLine("1", 0);
|
||||
verifyIndentationAfterNewLine("2", 4);
|
||||
verifyIndentationAfterNewLine("2", 4);
|
||||
verifyIndentationAfterNewLine("3", 4);
|
||||
verifyIndentationAfterNewLine("4", 8);
|
||||
|
||||
12
tests/cases/fourslash/smartIndentOnListEnd.ts
Normal file
12
tests/cases/fourslash/smartIndentOnListEnd.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////var a = []
|
||||
/////*1*/
|
||||
////| {}
|
||||
/////*2*/
|
||||
////| "";
|
||||
|
||||
goTo.marker("1");
|
||||
verify.indentationIs(4)
|
||||
goTo.marker("2");
|
||||
verify.indentationIs(4)
|
||||
@@ -3,15 +3,18 @@
|
||||
////function f<A,B,C>/*1*/(/*2*/a: A, /*3*/b:/*4*/B, c/*5*/, d: C/*6*/
|
||||
|
||||
|
||||
function verifyIndentationAfterNewLine(marker: string, indentation: number): void {
|
||||
function verifyIndentationAfterNewLine(marker: string, indentation: number, positionWorkaround: number, expectedText: string): void {
|
||||
goTo.marker(marker);
|
||||
edit.insert("\n");
|
||||
// The next two lines are to workaround #13433
|
||||
goTo.position(positionWorkaround);
|
||||
verify.textAtCaretIs(expectedText);
|
||||
verify.indentationIs(indentation);
|
||||
}
|
||||
|
||||
verifyIndentationAfterNewLine("1", 4);
|
||||
verifyIndentationAfterNewLine("2", 4);
|
||||
verifyIndentationAfterNewLine("3", 4);
|
||||
verifyIndentationAfterNewLine("4", 8);
|
||||
verifyIndentationAfterNewLine("5", 4);
|
||||
verifyIndentationAfterNewLine("6", 4);
|
||||
verifyIndentationAfterNewLine("1", 4, 24, '(');
|
||||
verifyIndentationAfterNewLine("2", 8, 34, 'a');
|
||||
verifyIndentationAfterNewLine("3", 8, 48, 'b');
|
||||
verifyIndentationAfterNewLine("4", 12, 63, 'B');
|
||||
verifyIndentationAfterNewLine("5", 8, 76, ',');
|
||||
verifyIndentationAfterNewLine("6", 8, 83, '');
|
||||
|
||||
Reference in New Issue
Block a user