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-5051] No Code Completion within closures passed to functions when in do&class&struct scope #47627

Closed
swift-ci opened this issue May 30, 2017 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. code completion Area → source tooling: code completion source tooling Area: IDE support, SourceKit, and other source tooling

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-5051
Radar radar://32700983
Original Reporter hannesoid (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

macOS Sierra 10.12.5, Xcode Version 8.3.2 (8E2002), Swift 3.1

Additional Detail from JIRA
Votes 3
Component/s CodeCompletion
Labels Bug
Assignee None
Priority Medium

md5: f582ebc3279f35cc6b7e1368ac520fcc

Issue Description:

When calling a function that takes a closure from certain scopes, I don't get code completion within the closure. Here are some examples. I run in to this a lot as I lke using Then-style initialization. In addition to SR-2750, I am trying to provide some more examples here about what is working and what is not.

Copy this code to a playground (or take attached swift file). And try autocompletion of the .property in various context. It will work on top level, and in func and init, but not in do, struct and class scope.

//: Playground - noun: a place where people can play


// EXAMPLE Materials

class MyClass {
    var property: Bool = false

    // example with method on a class
    func then(applying action: (MyClass) -> Void) -> MyClass {
        action(self)
        return self
    }
}

struct MyStruct {
    var property: Bool = false

    // example with method on a struct
    func with(applying action: (inout MyStruct) -> Void) -> MyStruct {
        var copy = self
        action(&copy)
        return copy
    }
}

// example with plain function
func modify(item: MyStruct, applying action: (inout MyStruct) -> Void) -> MyStruct {
    var copy = item
    action(&copy)
    return copy
}

// EXAMPLE for working autocompletions

let y = MyStruct().with { a in
    a.property = true // type a.prop… yes, autocompletion to a.property works
}

let z = modify(item: y) { a in
    a.property = false // type a.prop… yes, autocompletion to a.property works
}

let c =  MyClass().then { c in
    c.property = true // type a.prop… yes, autocompletion to a.property works
}

let d =  MyClass().then(applying: { (d: MyClass) in
    d.property = false // type a.prop… yes, autocompletion to a.property works
})

struct MyOtherStruct {
    init() {
        let y = MyStruct().with { a in
            a.property = true // type a.prop… yes, autocompletion to a.property works
        }
    }
    func function() {
        let y = MyStruct().with { a in
            a.property = true // type a.prop… yes, autocompletion to a.property works
        }
    }
}

// EXAMPLE 1 for no autocompletion for a.property

do {
    let x = MyStruct().with { a in
        a.property = true // type a.prop… no, autocompletion does not work
    }
    let z = modify(item: x) { x in
        x.property = false // type a.prop… no, autocompletion does not work
    }
    let c =  MyClass().then { c in
        c.property = false // type a.prop… no, autocompletion does not work
    }
    let d =  MyClass().then(applying: { (d: MyClass) in
        d.property = false // type a.prop… no, autocompletion does not work
    })
}

// EXAMPLE 2 for no autocompletion for a.property

struct B {
    let x = MyStruct().with { a in
        a.property = true // type a.prop… no, autocompletion does not work
    }
    let c =  MyClass().then { c in
        c.property = false // type a.prop… no, autocompletion does not work
    }
    // … same as EXAMPLE 1
}
@belkadan
Copy link
Contributor

@benlangmuir, look familiar?

@benlangmuir
Copy link
Member

The way we typecheck a closure that's not inside a function for code-completion is broken. This is just one of the symptoms.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jun 5, 2017

Comment by Hannes Oud (JIRA)

Okay. Is there a more general mother-issue for this?
Is it worth a radar or is this already the right place for it?

@swift-ci
Copy link
Collaborator Author

Comment by Hannes Oud (JIRA)

Same issue in Swift 3.2 and Swift 4 with Xcode Version 9.0 beta (9M136h)

@rintaro
Copy link
Mannequin

rintaro mannequin commented Jun 25, 2019

This seems to work in Xcode 11 beta 2
hannesoid (JIRA User) Could you confirm?

@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 source tooling Area: IDE support, SourceKit, and other source tooling
Projects
None yet
Development

No branches or pull requests

4 participants