Skip to content

Commit 8817703

Browse files
authored
Merge pull request microsoft#14545 from aozgaa/docCommentPrefix
Make docComment template indent whitespace-only
2 parents 77c2a1d + b7d09ef commit 8817703

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/harness/fourslash.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -2248,22 +2248,23 @@ namespace FourSlash {
22482248

22492249
if (expected === undefined) {
22502250
if (actual) {
2251-
this.raiseError(name + " failed - expected no template but got {newText: \"" + actual.newText + "\" caretOffset: " + actual.caretOffset + "}");
2251+
this.raiseError(`${name} failed - expected no template but got {newText: "${actual.newText}", caretOffset: ${actual.caretOffset}}`);
22522252
}
22532253

22542254
return;
22552255
}
22562256
else {
22572257
if (actual === undefined) {
2258-
this.raiseError(name + " failed - expected the template {newText: \"" + actual.newText + "\" caretOffset: " + actual.caretOffset + "} but got nothing instead");
2258+
this.raiseError(`${name} failed - expected the template {newText: "${expected.newText}", caretOffset: "${expected.caretOffset}"} but got nothing instead`);
2259+
22592260
}
22602261

22612262
if (actual.newText !== expected.newText) {
2262-
this.raiseError(name + " failed - expected insertion:\n" + this.clarifyNewlines(expected.newText) + "\nactual insertion:\n" + this.clarifyNewlines(actual.newText));
2263+
this.raiseError(`${name} failed - expected insertion:\n"${this.clarifyNewlines(expected.newText)}"\nactual insertion:\n"${this.clarifyNewlines(actual.newText)}"`);
22632264
}
22642265

22652266
if (actual.caretOffset !== expected.caretOffset) {
2266-
this.raiseError(name + " failed - expected caretOffset: " + expected.caretOffset + ",\nactual caretOffset:" + actual.caretOffset);
2267+
this.raiseError(`${name} failed - expected caretOffset: ${expected.caretOffset}\nactual caretOffset:${actual.caretOffset}`);
22672268
}
22682269
}
22692270
}

src/services/jsDoc.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ namespace ts.JsDoc {
178178
const posLineAndChar = sourceFile.getLineAndCharacterOfPosition(position);
179179
const lineStart = sourceFile.getLineStarts()[posLineAndChar.line];
180180

181-
const indentationStr = sourceFile.text.substr(lineStart, posLineAndChar.character);
181+
// replace non-whitespace characters in prefix with spaces.
182+
const indentationStr = sourceFile.text.substr(lineStart, posLineAndChar.character).replace(/\S/i, () => " ");
182183
const isJavaScriptFile = hasJavaScriptFileExtension(sourceFile.fileName);
183184

184185
let docParams = "";
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/// <reference path='fourslash.ts' />
22

33
// @Filename: indents.ts
4-
/////*0*/
4+
//// a /*2*/
55
//// /*1*/
6-
//// /*2*/function foo() { }
6+
/////*0*/ function foo() { }
77

88
const noIndentEmptyScaffolding = "/**\r\n * \r\n */";
99
const oneIndentEmptyScaffolding = "/**\r\n * \r\n */";
10-
const twoIndentEmptyScaffolding = "/**\r\n * \r\n */\r\n ";
10+
const twoIndentEmptyScaffolding = "/**\r\n * \r\n */";
1111
const noIndentOffset = 8;
1212
const oneIndentOffset = noIndentOffset + 4;
1313
const twoIndentOffset = oneIndentOffset + 4;
@@ -19,4 +19,4 @@ goTo.marker("1");
1919
verify.DocCommentTemplate(oneIndentEmptyScaffolding, oneIndentOffset);
2020

2121
goTo.marker("2");
22-
verify.DocCommentTemplate(twoIndentEmptyScaffolding, twoIndentOffset);
22+
verify.DocCommentTemplate(twoIndentEmptyScaffolding, twoIndentOffset);

0 commit comments

Comments
 (0)