SwiftMockGeneratorForXcode icon indicating copy to clipboard operation
SwiftMockGeneratorForXcode copied to clipboard

First selection was not a text range

Open laurence79 opened this issue 5 years ago • 4 comments

When attempting to generate anything using the plugin for the first time I am receiving this First selection was not a text range error.

Looking through the code I can see that this is being thrown because XCSourceEditorCommandInvocation.buffer.selections[0] isn't of type XCSourceTextRange, but I don't really know where to go from here.

macOS Mojave 10.14.1 XCode 10.0 (10A255)

laurence79 avatar Dec 26 '18 10:12 laurence79

Hi @laurence79

Thanks for raising this issue. I haven't been able to reproduce your issue so far. If you help me clarify a few things I might be able to help solve your problem.

  1. Have you ever been able to generate a test double using the plugin?
  2. Do you have the latest version of the plugin installed?
  3. Did you have a Swift file open in Xcode and place the cursor in a class declaration? Example:
class MySpy: MyProtocol {
<cursor here>
}

seanhenry avatar Dec 26 '18 14:12 seanhenry

Hi, thanks for looking into it.

  1. No I haven't been able to generate anything yet, everything I try yields the same error.
  2. I do, v0.18.
  3. Yes I've tried that, also selecting a few characters, selecting the entire class etc.

laurence79 avatar Dec 26 '18 14:12 laurence79

Thanks for the info. I've looked into the error and, you're right, it seems like selections.object(at: 0) as? XCSourceTextRange is failing. I'm confident that the selection isn't nil which means that the cast to XCSourceTextRange is failing. Which is strange because, according to the documentation, XCSourceTextRange is the only possible type in the selections array.

Assuming Xcode is only passing selections containing XCSourceTextRange objects then the only reason for that failure that I can think of is that, for some reason, your bundle is loading two XcodeKit frameworks or is loading a different XcodeKit framework to Xcode and the type check is failing.*

According to my analytics, you are the only user who has seen this error so far. So I wonder if the problem is due to your environment. Could you try uninstalling the plugin, restarting your machine, reinstalling, and making sure only one Xcode is open and that xcode-select -p points to the open version of Xcode.

It's not exactly inspiring advice for fixing a problem but I can't think of any other reasons why you would see this error.

* I've checked the rpaths of the binary and they point to directories in the bundle. There is also not a copy of XcodeKit.framework in the bundle. I also searched Xcode.app directories for the XcodeKit.framework and there seems to be only one bundled with Xcode.

seanhenry avatar Dec 28 '18 15:12 seanhenry

Could you try uninstalling the plugin, restarting your machine, reinstalling, and making sure only one Xcode is open and that xcode-select -p points to the open version of Xcode.

I've done this, also uninstalled Xcode completely, emptied trash, restart, reinstall, but the problem persists. I've done an install on a separate machine and the plugin works fine, so it clearly is a problem with my environment but I'm stumped on how to figure out what exactly that problem is.

laurence79 avatar Jan 17 '19 16:01 laurence79