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-5743] Refactoring action to convert try statement to do-catch and vice-versa #48313

Closed
akyrtzi opened this issue Aug 23, 2017 · 5 comments
Closed
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-5743
Radar rdar://32751464
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: 33863f80f650dc33d1c7e7e3c1a33d1f

Issue Description:

Implement action to change code from:

  try! doit()

to

  do {
    try doit()
  } catch {
    <#code#>
  }

also vice-versa

@swift-ci
Copy link
Collaborator

Comment by KacperHarasim (JIRA)

Hi @akyrtzi, @nkcsgexi

I would like to try implement this. Probably will split action and it's reverse into two separate PRs if that's okay. Right now I'm thinking only about conversion from `try!` to `try catch`
Do you think it makes sense as a range refactoring? I mean that user has to select one or more of try expressions and they're all converted into one `do catch` block. Or maybe cursor based refactoring and limiting to only one conversion is better?

Thanks in advance for the answer,

@swift-ci
Copy link
Collaborator

Comment by KacperHarasim (JIRA)

Also @nkcsgexi: What is the preferred way of getting parents in AST tree? I would like to get a statement which contains force try expression picked by the user. I would appreciate any hints. Should I maybe gather this information in `CursorInfoResolver` and provide API for querying in `ResolvedCursorInfo`? Or maybe is there a mechanism already built to do just that?

@swift-ci
Copy link
Collaborator

Comment by KacperHarasim (JIRA)

Refactor from `try!` to `do try catch` is now implemented and merged: #12063 The opposite is WIP.

@swift-ci
Copy link
Collaborator

Comment by KacperHarasim (JIRA)

PR for the opposite action is now opened: #12128

@swift-ci
Copy link
Collaborator

Comment by KacperHarasim (JIRA)

After thinking more with feedback from @nkcsgexi we've decided to abandon refactor for the opposite action since it encourages bad language practices. Marking the issue as resolved, since action from `try!` to `do try catch` is already in master.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added good first issue Good for newcomers feature A feature request or implementation compiler The Swift compiler in itself 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

3 participants