Fix "Add missing record fields" code action on v11+#1088
Fix "Add missing record fields" code action on v11+#1088zth merged 6 commits intorescript-lang:masterfrom
Conversation
This reverts commit 2265806.
| diagnostic, | ||
| file, | ||
| range, | ||
| todoValue: `%todo` |
There was a problem hiding this comment.
Since %todo was introduced in v11.1.0, I wanted to add a version check in addUndefinedRecordFieldsV11, but passing in project.rescriptVersion from triggerIncrementalCompilationOfFile all the way through to addUndefinedRecordFieldsV11 seemed like it wasn't worth the tradeoff in additional complexity
| let theLine = line; | ||
| if (theLine.endsWith(".")) { | ||
| theLine = theLine.slice(0, theLine.length - 2); | ||
| theLine = theLine.slice(0, theLine.length - 1); |
There was a problem hiding this comment.
Bug fix 1: The last character of the last field was cut off
| // For an empty record (`range.end.character - range.start.character == 2`), | ||
| // we don't want to add an initial trailing comma as that would be invalid syntax. | ||
| // | ||
| // We assume that records that already contain some characters between | ||
| // their braces have at least one field and therefore we need to insert | ||
| // an initial trailing comma. | ||
| if (range.end.character - range.start.character > 2) { | ||
| newText += ", "; | ||
| } |
There was a problem hiding this comment.
Bug fix 2: initial comma was inserted when using this code action on empty records, resulting in invalid syntax
|
Fantastic work @mediremi, thank you for this and the great work you've been doing recently! How can I get in touch with you? We'd like to invite you to our contributor Discord, if you're interested in joining. |
|
I'd definitely be interested in joining the Discord! My email is mediremi@gmail.com and my discord username is mediremi :) |
This PR fixes two bugs in the "Add missing record fields" code action:
.slice(0, length - 2)that should have beenlength - 1I've also changed the v11 version of this code action to use
%todoinstead offailwith("TODO").