Skip to content

Enhanced f-string completion #13203

Closed
Closed

Description

Pycharm just released a new version with a feature that would be great to have in vscode. It will turn a string into an f-string if you add a pair of curly braces inside of it.

https://www.jetbrains.com/pycharm/whatsnew/

Forgot to add ‘f’ to your f-string? PyCharm now auto-enables f-strings when the user adds curly braces within a string statement

Activity

  1. karthiknadig commented on Jul 30, 2020

    @karthiknadig
    Member

    Thank you for the suggestion! We have marked this issue as "needs decision" to make sure we have a conversation about your idea. We plan to leave this feature request open for at least a month to see how many 👍 votes the opening comment gets to help us make our decision.

  2. added
    area-intellisenseLSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc.
    and removed
    triage-neededNeeds assignment to the proper sub-team
    on Jul 30, 2020
  3. luabud commented on Sep 9, 2020

    @luabud
    Member

    Jake Bailey (@jakebailey) is this something that could be addressed by Pylance?

  4. jakebailey commented on Sep 14, 2020

    @jakebailey
    Member

    I'm not sure that this sort of thing is possible in LSP (or even VS Code). We can only edit the document by responding with a text change, e.g. we give a text change in a completion response, or give a text change for a quick fix, etc. The LSP is designed such that the client accepts changes the server suggests.

    We could technically detect that these characters were typed (it's gross to try), but then to get the changes back, you'd have to hack something together to force the changes in the client; I'm not familiar enough with the VS Code API to know if that's possible or a good UX. I can't say I've ever seen text edits provided by anything but completions, quickfixes, formatting, etc.

    I have other UX issues with this feature, in any case; I'd think this would be annoying to anyone typing regular format strings where they just want {}. It's the same characters.

  5. luabud commented on Sep 8, 2023

    @luabud
    Member

    This is now possible when using Pylance: https://devblogs.microsoft.com/python/python-in-visual-studio-code-may-2023-release/#automatic-conversion-of-f-strings-with-pylance

    You just need to enable "python.analysis.autoFormatStrings": true, in your settings :)

  6. removed their assignment
    on Sep 8, 2023
  7. locked as resolved and limited conversation to collaborators on Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-intellisenseLSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc.feature-requestRequest for new features or functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions