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

[SR-5745] Refactoring action to convert string concatenation to string interpolation #48315

Closed
akyrtzi opened this issue Aug 23, 2017 · 9 comments
Labels
compiler The Swift compiler in itself feature A feature request or implementation good first issue Good for newcomers refactoring Area → source tooling: refactoring source tooling Area: IDE support, SourceKit, and other source tooling

Comments

@akyrtzi
Copy link
Member

akyrtzi commented Aug 23, 2017

Previous ID SR-5745
Radar rdar://32751594
Original Reporter @akyrtzi
Type New Feature
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Source Tooling
Labels New Feature, Refactoring, StarterProposal
Assignee kacperh (JIRA)
Priority Medium

md5: 9bb65dc496b5da36485ed8f9177d1e8a

Issue Description:

Implement action to convert from:

let text = "hello " + name + "!"

to

let text = "hello \(name)!"
@swift-ci
Copy link
Collaborator

Comment by KacperHarasim (JIRA)

Hi @akyrtzi,
I would like to attempt to implement this.
I see this as a range based refactoring with the following behavior:
User chooses a range of text and every string value that is within the range is converted. This way, if in example provided range begins on "h" and ends on name variable result would be the following:

let text = "hello \(name)" + "!"

Since "!" was not selected it was not converted.
Does it make any sense? What do you think?

Thanks for the feedback,

@akyrtzi
Copy link
Member Author

akyrtzi commented Aug 25, 2017

Yes, I think it makes sense as range refactoring.

Note that if the range includes other expressions (or statements) unrelated to string concatenation then it should not be available.

@swift-ci
Copy link
Collaborator

Comment by KacperHarasim (JIRA)

That seems reasonable. Thanks!

@swift-ci
Copy link
Collaborator

Comment by KacperHarasim (JIRA)

Hi @akyrtzi
I've started to look around the source code in order to implement it and I have question:
Should I rather look at TokensInRange property of ResolvedRangeInfo and check for sequence of binary operators and literals, or maybe use SourceEntityWalker to walk through ResolvedInfo.ContainedNodes property? What's the clearer way to do things in this case?

@nkcsgexi
Copy link
Member

Hi kacperh (JIRA User),

I prefer we use SourceEntityWalker to walk through ContainedNode (in this case, a single expression) to analyze its content instead of scanning tokens. The reason is token contains much less semantic information that AST node does.

@swift-ci
Copy link
Collaborator

Comment by KacperHarasim (JIRA)

Thanks @nkcsgexi!
One last question(I hope :-) ): I’ve tried to go this approach and my logic was: scan expression with SourceEntityWalker and check whether it contains literals, Binary + expressions, interpolations and string objects. If given any other type of Expression I intended to report refactor as unavailable. Problem is that running it on expression like:

a” + „b” + „c

Results in going through DotSyntaxExpr. I’m not really sure why is it here, because I don’t see any expression like that in the example. It’s probably result of my limited knowledge about a compiler. Could you please point me to some information on why is it included?

Thanks in advance!

@nkcsgexi
Copy link
Member

Hi kacperh (JIRA User), great progress! You approach makes sense to me. I think the DotSyntaxExpr you see is implicit node synthesized by compiler to help later code generation; i think you can ignore any `implicit()` expressions.

@swift-ci
Copy link
Collaborator

Comment by KacperHarasim (JIRA)

Opened a PR to implement this: #11944

@swift-ci
Copy link
Collaborator

Comment by KacperHarasim (JIRA)

Committed in: 80698a0

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler in itself good first issue Good for newcomers feature A feature request or implementation source tooling Area: IDE support, SourceKit, and other source tooling and removed new feature StarterProposal labels Nov 11, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself feature A feature request or implementation good first issue Good for newcomers refactoring Area → source tooling: refactoring source tooling Area: IDE support, SourceKit, and other source tooling
Projects
None yet
Development

No branches or pull requests

4 participants