fix: quote marks during autocomplete now take care of the existing quotes
Summary
Fix code completion to avoid inserting extra quotes when cursor is already inside a string literal.
When typing foo(' and triggering completion for a Literal["apple", "pear"] parameter, the completion previously inserted 'apple' (with quotes), resulting in invalid syntax foo(''apple''). Now it correctly inserts just apple, producing valid code foo('apple').
Fixes completion behavior for typing.Literal string values when the user has already typed an opening quote.
Fixes #1086
Test Plan
Automated Testing
- Added new test case [completion_literal_quote_test] in [pyrefly/lib/test/lsp/completion_quotes.rs]
- Test verifies that completions insert unquoted text when cursor is inside a string
- Run with:
cargo test -p pyrefly --lib test::lsp::completion_quotes::completion_literal_quote_test
Manual Testing
- Create a Python file with:
from typing import Literal def foo(fruit: Literal["apple", "pear"]) -> None: ... foo('
Hi @Karman-singh15!
Thank you for your pull request and welcome to our community.
Action Required
In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.
Process
In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.
Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.
If you have received this in error or have any questions, please contact us at [email protected]. Thanks!
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!
@kinto0 has imported this pull request. If you are a Meta employee, you can view this in D87793904.
@kinto0 , i will work on your suggestions but can you please tell what are the merge conflicts and how do i go about fixing that. it would be great help if you could guide me through that
- pyrefly/lib/state/lsp.rs
not sure exactly what the conflicts are but it says there are conflicts in pyrefly/lib/state/lsp.rs. if you pull + merge, it should tell you. let me know if you need more help!
hi i think i made some mistake while trying to resolve the conflict, but it seems fine to me now. sorry for the mess of commits i made, still new to this. can you please check once sorry for the inconvenience
looks great now! thank you for working on this
only changing the test is left you can tell me if you want the previous test, i will add that tonight rest changes i have made you can take a look
hi, sorry for the delay i have reverted the test to the previous test. you can look and tell me if there is any issues
@kinto0 is there any update?
@kinto0 is there any update
@kinto0 is there any update
sorry about the delay. we've been taking some time off with the holidays and I haven't got a chance to get through my backlog. if you fix the merge conflicts, shoot me a message on discord and i'll make sure to review it again in time
@kinto0 i am sorry i accidentally closed this pr, i am still figuring out git github. i request you to reopen this sorry for the inconvenience
We can't reopen the PR for you, I think only you can
@kinto0 i have redid the issue and test file please check and sorry for the problems before still new to this. thanks for your cooperation.