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-14455] Variable defined in switch case-clause not suggested in string interpolation #56811

Closed
ahoppen opened this issue Apr 7, 2021 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. code completion Area → source tooling: code completion found by stress tester Flag: An issue found by the SourceKit stress tester source tooling Area: IDE support, SourceKit, and other source tooling

Comments

@ahoppen
Copy link
Contributor

ahoppen commented Apr 7, 2021

Previous ID SR-14455
Radar rdar://problem/76330416
Original Reporter @ahoppen
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s CodeCompletion
Labels Bug, FoundByStressTester
Assignee @ahoppen
Priority Medium

md5: c608c0b519d41f87b16bae75a62ad642

Issue Description:

public enum Endpoint {
  case movieDetail


  func path() -> String {
    switch self {
    case .movieDetail:
      let myInt: Int = 2
      return "\(#^COMPLETE^#)"
    }
  }
}

Should suggest myInt when running

swift-ide-test --code-completion -source-filename test.swift --code-completion-token=COMPLETE 

But it does not.

@ahoppen
Copy link
Contributor Author

ahoppen commented Apr 7, 2021

@swift-ci Create

@ahoppen
Copy link
Contributor Author

ahoppen commented Apr 12, 2021

The issue appears to be the following:

The case-statement’s range ends with its last token, which is the string literal token. By convention of SourceRange this token is still included in the range. But the string literal isn’t really just one token but a token containing the string interpolation pieces. Thus the completion token’s position is after the string literal token, thus after the end of the case-statement and we are never visiting the case statement, hence not discovering the myInt variable declared within.

    case .movieDetail:
      let myInt: Int = 2
      return "\(#^COMPLETE^#)"
             ^  |
Case ends here  |
                Code completion token here 

@ahoppen
Copy link
Contributor Author

ahoppen commented Apr 13, 2021

Fixed in #36867

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the source tooling Area: IDE support, SourceKit, and other source tooling label Feb 6, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. code completion Area → source tooling: code completion found by stress tester Flag: An issue found by the SourceKit stress tester source tooling Area: IDE support, SourceKit, and other source tooling
Projects
None yet
Development

No branches or pull requests

2 participants