Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced f-string completion #13203

Closed
mattstrayer opened this issue Jul 30, 2020 · 4 comments
Closed

Enhanced f-string completion #13203

mattstrayer opened this issue Jul 30, 2020 · 4 comments
Labels
area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. feature-request Request for new features or functionality

Comments

@mattstrayer
Copy link

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

@mattstrayer mattstrayer added triage-needed Needs assignment to the proper sub-team feature-request Request for new features or functionality labels Jul 30, 2020
@karthiknadig
Copy link
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.

@karthiknadig karthiknadig added needs decision area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. and removed triage-needed Needs assignment to the proper sub-team labels Jul 30, 2020
@luabud luabud added needs proposal Need to make some design decisions and removed needs decision labels Sep 9, 2020
@luabud luabud self-assigned this Sep 9, 2020
@luabud
Copy link
Member

luabud commented Sep 9, 2020

@jakebailey is this something that could be addressed by Pylance?

@jakebailey
Copy link
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.

@luabud
Copy link
Member

luabud commented Sep 8, 2023

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 :)

@luabud luabud closed this as completed Sep 8, 2023
@luabud luabud removed their assignment Sep 8, 2023
@github-actions github-actions bot removed the needs proposal Need to make some design decisions label Sep 8, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

4 participants