SourceKit limits on Swift refactoring


(Zhao Xin) #1

There is a new Swift refactoring plugin
<https://github.com/johnno1962/Refactorator> for Xcode. It is developed
by johnno1962.

Tonight I have a conversation with him on an issue of the refactoring
plugin. The issue <https://github.com/johnno1962/Refactorator/issues/3> is
closed because johnno1962 says the issue is the limit of SourceKit, which
he can do nothing further.

So I bring it here and see if anyone can help.

The example is simple. Supposing we have code like this:

struct Person {
    var name:String

    init(aName:String) {
        self.name = aName
    }
}
func testOnly() {
    let john = Person(aName: "John")

    print(john)
}

​When we do a refactor on aName, in ​let john = Person(aName: "John").
SourceKit only find this line of code and the code line init(aName:String).

It should also find the code line: self.name = aName, which it didn't.

According to johnno1962, SourceKit treats the aName inside the
init(aName:String) as a variable different from the aName in
init(aName:String).

···

--

​zhaoxin​


(Xi Ge) #2

Hi Xin,
I tried the case you gave here and got a SourceKit crash in the line of "self.name = aName” when querying cursor info. I will get into this by Monday.
Thanks for letting us know!
Xi

···

On Jan 9, 2016, at 1:15 PM, 肇鑫 via swift-dev <swift-dev@swift.org> wrote:

SourceKit


(Zhao Xin) #3

Thanks. Refactor really makes working much easier. Looking forward to the
progress.

zhaoxin

···

On Sun, Jan 10, 2016 at 5:37 AM, Xi Ge <xi_ge@apple.com> wrote:

Hi Xin,
I tried the case you gave here and got a SourceKit crash in the line of "
self.name = aName” when querying cursor info. I will get into this by
Monday.
Thanks for letting us know!
Xi

On Jan 9, 2016, at 1:15 PM, 肇鑫 via swift-dev <swift-dev@swift.org> wrote:

SourceKit

--

Owen Zhao


(Xi Ge) #4

HI Xin,
I have fixed this crash in open source Swift. Please let me know if the progress unlocks your refactoring support.
cheers
Xi

···

On Jan 9, 2016, at 6:45 PM, 肇鑫 <owenzx@gmail.com> wrote:

Thanks. Refactor really makes working much easier. Looking forward to the progress.

zhaoxin

On Sun, Jan 10, 2016 at 5:37 AM, Xi Ge <xi_ge@apple.com <mailto:xi_ge@apple.com>> wrote:
Hi Xin,
I tried the case you gave here and got a SourceKit crash in the line of "self.name <http://self.name/> = aName” when querying cursor info. I will get into this by Monday.
Thanks for letting us know!
Xi

On Jan 9, 2016, at 1:15 PM, 肇鑫 via swift-dev <swift-dev@swift.org <mailto:swift-dev@swift.org>> wrote:

SourceKit

--

Owen Zhao


(Zhao Xin) #5

Hi Xi Ge,

As the latest snapshot in swift.org/download is built on Jan 6, 2016. I try
to build swift from the source myself.

However, I don't know how to build xctoolchain from the source. I have
tried `utils/build-script --darwin-xcrun-toolchain
huhu-swift-2.2.xctoolchain -R`

But I didn't get the xctoolchain file.

Is there anything I can do to make my Xcode 7.2 to use the latest swift 2.2
with your latest patches?

zhaoxin

···

On Tue, Jan 12, 2016 at 3:35 AM, Xi Ge <xi_ge@apple.com> wrote:

HI Xin,
I have fixed this crash in open source Swift. Please let me know if the
progress unlocks your refactoring support.
cheers
Xi

On Jan 9, 2016, at 6:45 PM, 肇鑫 <owenzx@gmail.com> wrote:

Thanks. Refactor really makes working much easier. Looking forward to the
progress.

zhaoxin

On Sun, Jan 10, 2016 at 5:37 AM, Xi Ge <xi_ge@apple.com> wrote:

Hi Xin,
I tried the case you gave here and got a SourceKit crash in the line of "
self.name = aName” when querying cursor info. I will get into this by
Monday.
Thanks for letting us know!
Xi

On Jan 9, 2016, at 1:15 PM, 肇鑫 via swift-dev <swift-dev@swift.org> wrote:

SourceKit

--

Owen Zhao

--

Owen Zhao


(Zhao Xin) #6

Hi Xi Ge,

I just tried the swift-2.2-SNAPSHOT-2016-01-11-a-osx.pkg with Xcode
7.2 (7C68). The results is still the same, should I wait for another
snapshot as this one is not included your patch?

My steps:

1 download swift-2.2-SNAPSHOT-2016-01-11-a-osx.pkg, install it
2 command line, run `xcrun launch-with-toolchain
/Library/Developer/Toolchains/swift-latest.xctoolchain`
3 rebuild the plugin, quit xcode
4 open xcode with the command line
5 open the project which contains the test code

struct Person {
    var name:String

    init(aName:String) {
        self.name = aName
    }
}

func testOnly() {
    let john = Person(aName: "John")

    print(john)
}

6 clean and rebuild the project

zhaoxin

···

On Tue, Jan 12, 2016 at 3:35 AM, Xi Ge <xi_ge@apple.com> wrote:

HI Xin,
I have fixed this crash in open source Swift. Please let me know if the
progress unlocks your refactoring support.
cheers
Xi

On Jan 9, 2016, at 6:45 PM, 肇鑫 <owenzx@gmail.com> wrote:

Thanks. Refactor really makes working much easier. Looking forward to the
progress.

zhaoxin

On Sun, Jan 10, 2016 at 5:37 AM, Xi Ge <xi_ge@apple.com> wrote:

Hi Xin,
I tried the case you gave here and got a SourceKit crash in the line of "
self.name = aName” when querying cursor info. I will get into this by
Monday.
Thanks for letting us know!
Xi

On Jan 9, 2016, at 1:15 PM, 肇鑫 via swift-dev <swift-dev@swift.org> wrote:

SourceKit

--

Owen Zhao

--

Owen Zhao


(Xi Ge) #7

Hi Xin,
It seems that the cursor info crash is not your blocker : ( Could you point me to the refactoring plugin source? I can investigate better if I know which SourceKit request is used by it.
Thanks
Xi

···

On Jan 12, 2016, at 5:58 PM, 肇鑫 <owenzx@gmail.com> wrote:

Hi Xi Ge,

I just tried the swift-2.2-SNAPSHOT-2016-01-11-a-osx.pkg with Xcode 7.2 (7C68). The results is still the same, should I wait for another snapshot as this one is not included your patch?

My steps:

1 download swift-2.2-SNAPSHOT-2016-01-11-a-osx.pkg, install it
2 command line, run `xcrun launch-with-toolchain /Library/Developer/Toolchains/swift-latest.xctoolchain`
3 rebuild the plugin, quit xcode
4 open xcode with the command line
5 open the project which contains the test code

struct Person {
    var name:String
    
    init(aName:String) {
        self.name <http://self.name/> = aName
    }
}

func testOnly() {
    let john = Person(aName: "John")
    
    print(john)
}

6 clean and rebuild the project

zhaoxin

On Tue, Jan 12, 2016 at 3:35 AM, Xi Ge <xi_ge@apple.com <mailto:xi_ge@apple.com>> wrote:
HI Xin,
I have fixed this crash in open source Swift. Please let me know if the progress unlocks your refactoring support.
cheers
Xi

On Jan 9, 2016, at 6:45 PM, 肇鑫 <owenzx@gmail.com <mailto:owenzx@gmail.com>> wrote:

Thanks. Refactor really makes working much easier. Looking forward to the progress.

zhaoxin

On Sun, Jan 10, 2016 at 5:37 AM, Xi Ge <xi_ge@apple.com <mailto:xi_ge@apple.com>> wrote:
Hi Xin,
I tried the case you gave here and got a SourceKit crash in the line of "self.name <http://self.name/> = aName” when querying cursor info. I will get into this by Monday.
Thanks for letting us know!
Xi

On Jan 9, 2016, at 1:15 PM, 肇鑫 via swift-dev <swift-dev@swift.org <mailto:swift-dev@swift.org>> wrote:

SourceKit

--

Owen Zhao

--

Owen Zhao


(Zhao Xin) #8

Here. Github <https://github.com/johnno1962/Refactorator>

You should compile it in Xcode 7.2. I tried Xcode 7.3, the plugin doesn't
load. You can also further communicate with the author by creating a github
issue <https://github.com/johnno1962/Refactorator/issues/3>. He replies
really fast.

zhaoxin

···

On Wed, Jan 13, 2016 at 10:02 AM, Xi Ge <xi_ge@apple.com> wrote:

Hi Xin,
It seems that the cursor info crash is not your blocker : ( Could you
point me to the refactoring plugin source? I can investigate better if I
know which SourceKit request is used by it.
Thanks
Xi

On Jan 12, 2016, at 5:58 PM, 肇鑫 <owenzx@gmail.com> wrote:

Hi Xi Ge,

I just tried the swift-2.2-SNAPSHOT-2016-01-11-a-osx.pkg with Xcode
7.2 (7C68). The results is still the same, should I wait for another
snapshot as this one is not included your patch?

My steps:

1 download swift-2.2-SNAPSHOT-2016-01-11-a-osx.pkg, install it
2 command line, run `xcrun launch-with-toolchain
/Library/Developer/Toolchains/swift-latest.xctoolchain`
3 rebuild the plugin, quit xcode
4 open xcode with the command line
5 open the project which contains the test code

struct Person {
    var name:String

    init(aName:String) {
        self.name = aName
    }
}

func testOnly() {
    let john = Person(aName: "John")

    print(john)
}

6 clean and rebuild the project

zhaoxin

On Tue, Jan 12, 2016 at 3:35 AM, Xi Ge <xi_ge@apple.com> wrote:

HI Xin,
I have fixed this crash in open source Swift. Please let me know if the
progress unlocks your refactoring support.
cheers
Xi

On Jan 9, 2016, at 6:45 PM, 肇鑫 <owenzx@gmail.com> wrote:

Thanks. Refactor really makes working much easier. Looking forward to the
progress.

zhaoxin

On Sun, Jan 10, 2016 at 5:37 AM, Xi Ge <xi_ge@apple.com> wrote:

Hi Xin,
I tried the case you gave here and got a SourceKit crash in the line of "
self.name = aName” when querying cursor info. I will get into this by
Monday.
Thanks for letting us know!
Xi

On Jan 9, 2016, at 1:15 PM, 肇鑫 via swift-dev <swift-dev@swift.org> >>> wrote:

SourceKit

--

Owen Zhao

--

Owen Zhao

--

Owen Zhao