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

x/tools/gopls: support conversion between raw and interpreted string literals #51200

pgaskin opened this issue Nov 28, 2021 · 3 comments
FeatureRequest gopls help wanted


Copy link

@pgaskin pgaskin commented Nov 28, 2021

Is your feature request related to a problem? Please describe.
I've often needed to convert between raw (`…`) and interpreted ("…") strings, especially when pasting literals between files in different languages. This would also make it easier to edit complex string literals.

Describe the solution you'd like
Code actions or refactoring options for converting between the two forms:

  • Interpreted to raw (one option for if strconv.CanBackquote, another one which is similar but allows newlines).
    • If the string contains backticks, this action could either be hidden or made to transform it to ` + "`" + `. If it transforms it, another action to merge consecutive concatenated literals into a single one would be useful.
  • Raw to interpreted (i.e. %q).
  • Raw to interpreted ASCII (i.e. %+q) (for completeness; I wouldn't really use this one much).

Describe alternatives you've considered
I currently manually convert between forms, using regular expressions for large strings. I've considered making this as a separate VSCode extension, but I think this fits better in gopls since it's Go-specific.

Additional context

@hyangah hyangah added FeatureRequest gopls labels Nov 29, 2021
Copy link

@suzmue suzmue commented Dec 3, 2021

How would you envision this feature working? / How would it appear in the UI?

@suzmue suzmue added the WaitingForInfo label Dec 3, 2021
Copy link

@pgaskin pgaskin commented Dec 3, 2021

I think the best place would be in the refactor menu when right-clicking on an eligible string.

Copy link

@hyangah hyangah commented Feb 15, 2022

I think this can be a candidate of refactor.rewrite code actions when the range is string.
Transferring to gopls issue tracker for discussion.

@hyangah hyangah removed the WaitingForInfo label Feb 15, 2022
@hyangah hyangah changed the title Support automatic conversion between raw and interpreted string literals x/tools/gopls: support conversion between raw and interpreted string literals Feb 15, 2022
@hyangah hyangah transferred this issue from golang/vscode-go Feb 15, 2022
@gopherbot gopherbot added this to the Unreleased milestone Feb 15, 2022
@hyangah hyangah removed this from the Unreleased milestone Feb 15, 2022
@hyangah hyangah added this to the gopls/unplanned milestone Feb 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
FeatureRequest gopls help wanted
None yet

No branches or pull requests

4 participants