Skip to content

Commit 9d26b4e

Browse files
author
Arthur Ozga
committed
Fixed newline handling
1 parent 8d07c69 commit 9d26b4e

5 files changed

Lines changed: 21 additions & 20 deletions

File tree

src/harness/fourslash.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,7 @@ module FourSlash {
19411941
}
19421942
}
19431943

1944-
public verifyDocCommentTemplate(expected: ts.TextInsertion) {
1944+
public verifyDocCommentTemplate(expected?: ts.TextInsertion) {
19451945
const name = "verifyDocCommentTemplate";
19461946
let actual = this.languageService.getDocCommentTemplateAtPosition(this.activeFile.fileName, this.currentCaretPosition);
19471947

@@ -1953,16 +1953,18 @@ module FourSlash {
19531953
this.raiseError(name + ' failed - expected no template but got {newText: \"' + actual.newText + '\" offsetInNewText: ' + actual.offsetInNewText + '}');
19541954
}
19551955
}
1956-
if (expected !== undefined && actual === undefined) {
1957-
this.raiseError(name + ' failed - expected the template {newText: \"' + actual.newText + '\" offsetInNewText: ' + actual.offsetInNewText + '} but got nothing instead');
1958-
}
1956+
else {
1957+
if (actual === undefined) {
1958+
this.raiseError(name + ' failed - expected the template {newText: \"' + actual.newText + '\" offsetInNewText: ' + actual.offsetInNewText + '} but got nothing instead');
1959+
}
19591960

1960-
if (actual.newText !== expected.newText) {
1961-
this.raiseError(name + ' failed - expected insertion:\n' + expected.newText + '\nactual insertion:\n' + actual.newText);
1962-
}
1961+
if (actual.newText !== expected.newText) {
1962+
this.raiseError(name + ' failed - expected insertion:\n' + expected.newText + '\nactual insertion:\n' + actual.newText);
1963+
}
19631964

1964-
if (actual.offsetInNewText !== expected.offsetInNewText) {
1965-
this.raiseError(name + ' failed - expected offsetInNewText: ' + expected.offsetInNewText + ',\nactual offsetInNewText:' + actual.offsetInNewText);
1965+
if (actual.offsetInNewText !== expected.offsetInNewText) {
1966+
this.raiseError(name + ' failed - expected offsetInNewText: ' + expected.offsetInNewText + ',\nactual offsetInNewText:' + actual.offsetInNewText);
1967+
}
19661968
}
19671969
}
19681970

src/services/services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6838,7 +6838,7 @@ namespace ts {
68386838

68396839
let indentationStr = sourceFile.text.substr(lineStart, posLineAndChar.character).match(/\s*/).toString();
68406840

6841-
const newLine = host.getNewLine();
6841+
const newLine = host.getNewLine ? host.getNewLine() : "\r\n";
68426842

68436843
let docParams = parameters.map((p, index) =>
68446844
indentationStr + " * @param " + (p.name.kind === SyntaxKind.Identifier ? (<Identifier>p.name).text : "param" + index.toString()) + newLine);
@@ -6850,7 +6850,7 @@ namespace ts {
68506850
/* closing comment */ indentationStr + " */" +
68516851
/* newline if at decl start */ (tokenStart === position ? newLine + indentationStr : "");
68526852

6853-
let cursorOffset = /* "/**" */ 3 + /* newLine */ + newLine.length + indentationStr.length + /* " * " */ 3;
6853+
let cursorOffset = /* "/**" */ 3 + /* newLine */ newLine.length + indentationStr.length + /* " * " */ 3;
68546854

68556855
return {newText: result, offsetInNewText: cursorOffset };
68566856
}

tests/cases/fourslash/docCommentTemplateFunctionWithParameters.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
//// /*1*/
66
//// function foo(x: number, y: string): boolean {}
77

8-
const noIndentScaffolding = "/**\n * \n * @param x\n * @param y\n */";
9-
const oneIndentScaffolding = "/**\n * \n * @param x\n * @param y\n */";
10-
const noIndentOffset = 7;
8+
const noIndentScaffolding = "/**\r\n * \r\n * @param x\r\n * @param y\r\n */";
9+
const oneIndentScaffolding = "/**\r\n * \r\n * @param x\r\n * @param y\r\n */";
10+
const noIndentOffset = 8;
1111
const oneIndentOffset = noIndentOffset + 4;
1212

1313
goTo.marker("0");

tests/cases/fourslash/docCommentTemplateIndentation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
//// /*1*/
66
//// /*2*/function foo() { }
77

8-
const noIndentEmptyScaffolding = "/**\n * \n */";
9-
const oneIndentEmptyScaffolding = "/**\n * \n */";
10-
const twoIndentEmptyScaffolding = "/**\n * \n */\n ";
11-
const noIndentOffset = 7;
8+
const noIndentEmptyScaffolding = "/**\r\n * \r\n */";
9+
const oneIndentEmptyScaffolding = "/**\r\n * \r\n */";
10+
const twoIndentEmptyScaffolding = "/**\r\n * \r\n */\r\n ";
11+
const noIndentOffset = 8;
1212
const oneIndentOffset = noIndentOffset + 4;
1313
const twoIndentOffset = oneIndentOffset + 4;
1414

tests/cases/fourslash/fourslash.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,8 @@ module FourSlashInterface {
378378
FourSlash.currentTestState.verifyNoMatchingBracePosition(bracePosition);
379379
}
380380

381-
// Will fix in fourslash-referencing
382381
public DocCommentTemplate(expectedText: string, expectedOffset: number, empty?: boolean) {
383-
FourSlash.currentTestState.verifyDocCommentTemplate(empty ? undefined : { newText: expectedText, cursorOffset: expectedOffset });
382+
FourSlash.currentTestState.verifyDocCommentTemplate(empty ? undefined : { newText: expectedText, offsetInNewText: expectedOffset });
384383
}
385384

386385
public noDocCommentTemplate() {

0 commit comments

Comments
 (0)