You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
Activity
karthiknadig commentedon Jul 30, 2020
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.
luabud commentedon Sep 9, 2020
Jake Bailey (@jakebailey) is this something that could be addressed by Pylance?
jakebailey commentedon Sep 14, 2020
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 commentedon 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 :)