diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index 1ddfa2e64485f..37d760ac8f55b 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -360,7 +360,8 @@ namespace ts.textChanges { // Otherwise, add an extra new line immediately before the error span. const insertAtLineStart = isValidLocationToAddComment(sourceFile, startPosition); const token = getTouchingToken(sourceFile, insertAtLineStart ? startPosition : position, /*includeJsDocComment*/ false); - const text = `${insertAtLineStart ? "" : this.newLineCharacter}${sourceFile.text.slice(lineStartPosition, startPosition)}//${commentText}${this.newLineCharacter}`; + const indent = sourceFile.text.slice(lineStartPosition, startPosition); + const text = `${insertAtLineStart ? "" : this.newLineCharacter}//${commentText}${this.newLineCharacter}${indent}`; this.insertText(sourceFile, token.getStart(sourceFile), text); } diff --git a/tests/cases/fourslash/codeFixDisableJsDiagnosticsInFile_tsIgnore_indent.ts b/tests/cases/fourslash/codeFixDisableJsDiagnosticsInFile_tsIgnore_indent.ts new file mode 100644 index 0000000000000..7368ce1f3367b --- /dev/null +++ b/tests/cases/fourslash/codeFixDisableJsDiagnosticsInFile_tsIgnore_indent.ts @@ -0,0 +1,19 @@ +/// + +// @allowjs: true +// @checkJs: true + +// @Filename: /a.js +////{ +//// a; +////} + +verify.codeFix({ + description: "Ignore this error message", + index: 0, + newFileContent: +`{ + // @ts-ignore + a; +}`, +});