pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

fix: quote marks during autocomplete now take care of the existing quotes

Open Karman-singh15 opened this issue 1 month ago • 10 comments

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

  1. Create a Python file with:
    from typing import Literal
    def foo(fruit: Literal["apple", "pear"]) -> None: ...
    foo('
    

Karman-singh15 avatar Nov 22 '25 18:11 Karman-singh15

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!

meta-cla[bot] avatar Nov 22 '25 18:11 meta-cla[bot]

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

meta-cla[bot] avatar Nov 22 '25 18:11 meta-cla[bot]

@kinto0 has imported this pull request. If you are a Meta employee, you can view this in D87793904.

meta-codesync[bot] avatar Nov 24 '25 17:11 meta-codesync[bot]

@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

Karman-singh15 avatar Nov 24 '25 19:11 Karman-singh15

  • 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!

kinto0 avatar Nov 24 '25 19:11 kinto0

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

Karman-singh15 avatar Nov 24 '25 20:11 Karman-singh15

looks great now! thank you for working on this

kinto0 avatar Nov 24 '25 22:11 kinto0

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

Karman-singh15 avatar Nov 25 '25 07:11 Karman-singh15

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

Karman-singh15 avatar Nov 27 '25 10:11 Karman-singh15

@kinto0 is there any update?

Karman-singh15 avatar Nov 28 '25 12:11 Karman-singh15

@kinto0 is there any update

Karman-singh15 avatar Dec 03 '25 11:12 Karman-singh15

@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 avatar Dec 04 '25 00:12 kinto0

@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

Karman-singh15 avatar Dec 05 '25 08:12 Karman-singh15

We can't reopen the PR for you, I think only you can

yangdanny97 avatar Dec 06 '25 01:12 yangdanny97

@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.

Karman-singh15 avatar Dec 11 '25 08:12 Karman-singh15