Add code fix for double literal without dot#3352
Conversation
It's very easy to write `2` when you mean `2.`. Offer a code fix.
|
I don't really care whether we merge this. I make this mistake pretty regularly in Q#, but I mostly implemented it to practice writing rust without copilot. With all the time in the world, I'd probably experiment with having type inference infer either |
| operation Foo(qs: Qubit[]) : Unit is Adj { | ||
| use q = Qubit(); | ||
| Foo(q); | ||
| Foo(◉◉q◉◉); |
There was a problem hiding this comment.
When we switched from one edit to two, the updated test became less meaningful as confirmation that the action was behaving correctly, so now we check the locations of the edits too.
There was a problem hiding this comment.
Pull request overview
Adds a new Q# language service code action that offers a quick fix when an integer literal is used where a Double is expected, by inserting a trailing . (e.g., 2 → 2.). This fits into the existing source/language_service/src/code_action/ quick-fix providers alongside existing fixes like “wrap in array”.
Changes:
- Add
int_to_doublecode action provider and wire it intoget_code_actions. - Add a new test suite for the int-to-double quick fix (including unary +/-, parens cases).
- Strengthen existing “wrap in array” tests by asserting edit ranges against marker-derived expected locations.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| source/language_service/src/code_action/wrap_in_array/tests.rs | Updates tests to use marker-derived Locations and assert edit ranges precisely. |
| source/language_service/src/code_action/int_to_double/tests.rs | New tests validating the “Convert to double literal” code action behavior across several expression shapes. |
| source/language_service/src/code_action/int_to_double.rs | New quick-fix implementation that inserts a trailing . for Int literal mismatches against expected Double. |
| source/language_service/src/code_action.rs | Registers the new int_to_double provider in the code actions pipeline. |
It's very easy to write
2when you mean2.. Offer a code fix.