From 9d26b4eb4178cc59ae27f1e1f3d68e9cbd799b34 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Mon, 3 Aug 2015 15:09:49 -0700 Subject: [PATCH] Fixed newline handling --- src/harness/fourslash.ts | 20 ++++++++++--------- src/services/services.ts | 4 ++-- ...ocCommentTemplateFunctionWithParameters.ts | 6 +++--- .../docCommentTemplateIndentation.ts | 8 ++++---- tests/cases/fourslash/fourslash.ts | 3 +-- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index e8048ab82d7..a65a6b21e38 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1941,7 +1941,7 @@ module FourSlash { } } - public verifyDocCommentTemplate(expected: ts.TextInsertion) { + public verifyDocCommentTemplate(expected?: ts.TextInsertion) { const name = "verifyDocCommentTemplate"; let actual = this.languageService.getDocCommentTemplateAtPosition(this.activeFile.fileName, this.currentCaretPosition); @@ -1953,16 +1953,18 @@ module FourSlash { this.raiseError(name + ' failed - expected no template but got {newText: \"' + actual.newText + '\" offsetInNewText: ' + actual.offsetInNewText + '}'); } } - if (expected !== undefined && actual === undefined) { - this.raiseError(name + ' failed - expected the template {newText: \"' + actual.newText + '\" offsetInNewText: ' + actual.offsetInNewText + '} but got nothing instead'); - } + else { + if (actual === undefined) { + this.raiseError(name + ' failed - expected the template {newText: \"' + actual.newText + '\" offsetInNewText: ' + actual.offsetInNewText + '} but got nothing instead'); + } - if (actual.newText !== expected.newText) { - this.raiseError(name + ' failed - expected insertion:\n' + expected.newText + '\nactual insertion:\n' + actual.newText); - } + if (actual.newText !== expected.newText) { + this.raiseError(name + ' failed - expected insertion:\n' + expected.newText + '\nactual insertion:\n' + actual.newText); + } - if (actual.offsetInNewText !== expected.offsetInNewText) { - this.raiseError(name + ' failed - expected offsetInNewText: ' + expected.offsetInNewText + ',\nactual offsetInNewText:' + actual.offsetInNewText); + if (actual.offsetInNewText !== expected.offsetInNewText) { + this.raiseError(name + ' failed - expected offsetInNewText: ' + expected.offsetInNewText + ',\nactual offsetInNewText:' + actual.offsetInNewText); + } } } diff --git a/src/services/services.ts b/src/services/services.ts index a9992cbe231..260f18e4630 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -6838,7 +6838,7 @@ namespace ts { let indentationStr = sourceFile.text.substr(lineStart, posLineAndChar.character).match(/\s*/).toString(); - const newLine = host.getNewLine(); + const newLine = host.getNewLine ? host.getNewLine() : "\r\n"; let docParams = parameters.map((p, index) => indentationStr + " * @param " + (p.name.kind === SyntaxKind.Identifier ? (p.name).text : "param" + index.toString()) + newLine); @@ -6850,7 +6850,7 @@ namespace ts { /* closing comment */ indentationStr + " */" + /* newline if at decl start */ (tokenStart === position ? newLine + indentationStr : ""); - let cursorOffset = /* "/**" */ 3 + /* newLine */ + newLine.length + indentationStr.length + /* " * " */ 3; + let cursorOffset = /* "/**" */ 3 + /* newLine */ newLine.length + indentationStr.length + /* " * " */ 3; return {newText: result, offsetInNewText: cursorOffset }; } diff --git a/tests/cases/fourslash/docCommentTemplateFunctionWithParameters.ts b/tests/cases/fourslash/docCommentTemplateFunctionWithParameters.ts index 00a98cfe72c..f4410d5d454 100644 --- a/tests/cases/fourslash/docCommentTemplateFunctionWithParameters.ts +++ b/tests/cases/fourslash/docCommentTemplateFunctionWithParameters.ts @@ -5,9 +5,9 @@ //// /*1*/ //// function foo(x: number, y: string): boolean {} -const noIndentScaffolding = "/**\n * \n * @param x\n * @param y\n */"; -const oneIndentScaffolding = "/**\n * \n * @param x\n * @param y\n */"; -const noIndentOffset = 7; +const noIndentScaffolding = "/**\r\n * \r\n * @param x\r\n * @param y\r\n */"; +const oneIndentScaffolding = "/**\r\n * \r\n * @param x\r\n * @param y\r\n */"; +const noIndentOffset = 8; const oneIndentOffset = noIndentOffset + 4; goTo.marker("0"); diff --git a/tests/cases/fourslash/docCommentTemplateIndentation.ts b/tests/cases/fourslash/docCommentTemplateIndentation.ts index f35e3b42cd3..db7e48dab2e 100644 --- a/tests/cases/fourslash/docCommentTemplateIndentation.ts +++ b/tests/cases/fourslash/docCommentTemplateIndentation.ts @@ -5,10 +5,10 @@ //// /*1*/ //// /*2*/function foo() { } -const noIndentEmptyScaffolding = "/**\n * \n */"; -const oneIndentEmptyScaffolding = "/**\n * \n */"; -const twoIndentEmptyScaffolding = "/**\n * \n */\n "; -const noIndentOffset = 7; +const noIndentEmptyScaffolding = "/**\r\n * \r\n */"; +const oneIndentEmptyScaffolding = "/**\r\n * \r\n */"; +const twoIndentEmptyScaffolding = "/**\r\n * \r\n */\r\n "; +const noIndentOffset = 8; const oneIndentOffset = noIndentOffset + 4; const twoIndentOffset = oneIndentOffset + 4; diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 10c49777a6d..b778fb3fc24 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -378,9 +378,8 @@ module FourSlashInterface { FourSlash.currentTestState.verifyNoMatchingBracePosition(bracePosition); } - // Will fix in fourslash-referencing public DocCommentTemplate(expectedText: string, expectedOffset: number, empty?: boolean) { - FourSlash.currentTestState.verifyDocCommentTemplate(empty ? undefined : { newText: expectedText, cursorOffset: expectedOffset }); + FourSlash.currentTestState.verifyDocCommentTemplate(empty ? undefined : { newText: expectedText, offsetInNewText: expectedOffset }); } public noDocCommentTemplate() {