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

Closed
pgaskin opened this issue Nov 28, 2021 · 5 comments
Closed
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. help wanted Refactoring Issues related to refactoring tools
Milestone

Comments

@pgaskin
Copy link

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
N/A

@hyangah hyangah added FeatureRequest gopls Issues related to the Go language server, gopls. labels Nov 29, 2021
@suzmue
Copy link
Contributor

suzmue commented Dec 3, 2021

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

@suzmue suzmue added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 3, 2021
@pgaskin
Copy link
Author

pgaskin commented Dec 3, 2021

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

@hyangah
Copy link
Contributor

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 Issue is not actionable because of missing required information, which needs to be provided. 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 modified the milestones: Unreleased, gopls/unplanned Feb 15, 2022
@adonovan adonovan added the Refactoring Issues related to refactoring tools label Apr 24, 2023
@gopherbot
Copy link

Change https://go.dev/cl/542235 mentions this issue: gopls/internal/lsp: add code action for conversion between raw and interpreted string

@findleyr
Copy link
Contributor

Thanks for the contribution! Moved to the gopls@v0.15.0 milestone so we remember to mention this in the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. help wanted Refactoring Issues related to refactoring tools
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants