Skip to content

Commit 751eb44

Browse files
authored
Add more detailed log for bad codefix request (microsoft#36420)
1 parent 77d790b commit 751eb44

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/services/codefixes/fixUnreachableCode.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,26 @@ namespace ts.codefix {
55
registerCodeFix({
66
errorCodes,
77
getCodeActions(context) {
8-
const changes = textChanges.ChangeTracker.with(context, t => doChange(t, context.sourceFile, context.span.start, context.span.length));
8+
const changes = textChanges.ChangeTracker.with(context, t => doChange(t, context.sourceFile, context.span.start, context.span.length, context.errorCode));
99
return [createCodeFixAction(fixId, changes, Diagnostics.Remove_unreachable_code, fixId, Diagnostics.Remove_all_unreachable_code)];
1010
},
1111
fixIds: [fixId],
12-
getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => doChange(changes, diag.file, diag.start, diag.length)),
12+
getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => doChange(changes, diag.file, diag.start, diag.length, diag.code)),
1313
});
1414

15-
function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, start: number, length: number): void {
15+
function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, start: number, length: number, errorCode: number): void {
1616
const token = getTokenAtPosition(sourceFile, start);
1717
const statement = findAncestor(token, isStatement)!;
18-
Debug.assert(statement.getStart(sourceFile) === token.getStart(sourceFile), "token and statement should start at the same point");
18+
if (statement.getStart(sourceFile) !== token.getStart(sourceFile)) {
19+
const logData = JSON.stringify({
20+
statementKind: Debug.formatSyntaxKind(statement.kind),
21+
tokenKind: Debug.formatSyntaxKind(token.kind),
22+
errorCode,
23+
start,
24+
length
25+
});
26+
Debug.fail("Token and statement should start at the same point. " + logData);
27+
}
1928

2029
const container = (isBlock(statement.parent) ? statement.parent : statement).parent;
2130
if (!isBlock(statement.parent) || statement === first(statement.parent.statements)) {

0 commit comments

Comments
 (0)