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

First selection was not a text range #20

Open
laurence79 opened this issue Dec 26, 2018 · 4 comments
Open

First selection was not a text range #20

laurence79 opened this issue Dec 26, 2018 · 4 comments

Comments

@laurence79
Copy link

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)

@seanhenry
Copy link
Owner

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>
}

@laurence79
Copy link
Author

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.

@seanhenry
Copy link
Owner

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.

@laurence79
Copy link
Author

laurence79 commented Jan 17, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants