intitni / CopilotForXcode

The first GitHub Copilot, Codeium and ChatGPT Xcode Source Editor Extension
https://copilotforxcode.intii.com
MIT License
7.85k stars 387 forks source link

[Bug]: Copilot option is not available in Xcode Editor #585

Closed Nivru closed 1 week ago

Nivru commented 2 months ago

Before Reporting

What happened?

I have installed Copilot for Xcode (Version: 0.34.1) and my MacOS version is 15.0 and Xcode 16.0 When I type for code suggestion and click on "Accept" then not getting any output. Have restarted Xcode and system.

Please refer attached screenshots for more details

Screenshot 2024-09-30 at 2 03 10 PM Screenshot 2024-09-30 at 2 16 14 PM

How to reproduce the bug.

It just happened!

Relevant log output

No response

macOS version

15.0

Xcode version

16.0

Copilot for Xcode version

0.34.1

intitni commented 2 months ago

That means you have not enabled the Xcode Source Editor Extension.

From the Apple menu located in the top-left corner of your screen click System Settings. Navigate to General then Login Items & Extensions. Click Xcode Source Editor and tick Copilot for Xcode.

For more information about it, please check the faq

Nivru commented 2 months ago

Thanks for quick reply.

Now I have enabled it and can see Copilot option however still not getting code suggestion. Please refer attached snap for exact error/warning message.

Screenshot 2024-09-30 at 2 16 14 PM
intitni commented 2 months ago

What is inside the Copilot menu?

Nivru commented 2 months ago
Screenshot 2024-09-30 at 2 50 16 PM
Nivru commented 2 months ago

If I click on Accept and nothing in coming over

Screenshot 2024-09-30 at 2 51 31 PM
intitni commented 2 months ago

That's weird. I would suggest you restart the Mac. If the restart doesn't help, answer the following questions:

  1. Where is Copilot for Xcode installed.
  2. Where is Xcode installed.
  3. Does running Xcode automatically runs the CopilotForXcodeServiceExtension.app
  4. Did you change any settings in the Advanced tab in Copilot for Xcode.app
  5. Are there multiple copies of Copilot for Xcode.app exist on your Mac.
Nivru commented 2 months ago

Restart doesn't helped.

  1. In Application Folder
  2. In Application Folder
  3. Have to open manually. Automatically it does not open
Screenshot 2024-09-30 at 3 18 00 PM
  1. No

    Screenshot 2024-09-30 at 3 19 43 PM
  2. No but one confusion. In Mac finder/search if I type Copilot two different suggestions are coming. Are they both same?

Screenshot 2024-09-30 at 3 18 00 PM
intitni commented 2 months ago

If either Xcode or Copilot for Xcode can't bring the service app up, it basically means the launch agent is not correctly setup. Please try clicking the "Setup Launch Agent" button and try again.

Screenshot 2024-09-30 at 17 56 08

If it doesn't work, you may have to do it manually.

Copilot for Xcode is the host app, extension service is the service app that does the real jobs.

The service app is not meant to be launched manually.

intitni commented 2 months ago

You should also check if the login item is disabled in the system settings.

Screenshot 2024-09-30 at 18 04 30
Nivru commented 2 months ago

Copilot for Xcode is enabled in Login items.

Screenshot 2024-09-30 at 3 39 45 PM
intitni commented 2 months ago

Please do the following:

  1. Quit Copilot for Xcode and the CopilotForXcodeExtensionService.
  2. Quit Xcode.
  3. Open Console.app, In the menu -> Action, turn on "Include Info Messages" and "Include Debug Messages".
  4. Click start streaming, and set the filter to category:CommunicationBridge.
  5. Open Xcode, and trigger the Accept Suggestion or any other menu item (do not open Copilot for Xcode), let me know what logs you can see.
Screenshot 2024-09-30 at 18 25 47

If you don't see any log, please check if CommunicationBridge is running from the Activity Monitor.app.

Also let me know if you can see any warnings on the top of the Xcode editor after triggering the menu items.

intitni commented 2 months ago

Another thing that I want to confirm is, can Copilot for Xcode.app start the CopilotForXcodeExtensionService automatically?

Nivru commented 2 months ago

After triggering the menu items does not see any warning in Xcode editor.

Don't see any logs in Console app.

Screenshot 2024-09-30 at 4 46 48 PM

CommunicationBridge is running:

Screenshot 2024-09-30 at 4 46 10 PM
Nivru commented 2 months ago

Can Copilot for Xcode.app start the CopilotForXcodeExtensionService automatically? -> No

intitni commented 2 months ago

Everything is so weird in your case. Who is launching the CommunicationBrdige after all? Please try removing the launch agent and try to set it up manually.

Any chance the binary is not released by me?

Nivru commented 2 months ago

Any chance the binary is not released by me? -> Yeah, Could be possibility of this.

Are we missing anything related to API key?

I am opening below window from Editor -> Copilot -> Write of Modify code and there I am getting below error. Where I need to add API key?

You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username).

Screenshot 2024-09-30 at 5 13 43 PM
intitni commented 2 months ago

That would be another story that you have to set up the chat model before you can chat.

I am almost sure that the issue is that the launch agent is not correctly set up, which is required to launch the CommunicationBridge to enable communication between the source editor extension and the service app.

It seems like in your case the CommunicationBridge is launched but no one is talking to it, therefore the service app is not launched automatically and the source editor extension can't get information from the service app.

I honestly don't know why. All I can suggest now is to try reinstalling the app, resetting the launch agent, or setup the launch agent manually following the FAQ.

If the binary is released by someone else, they may have messed up with the identifiers but who knows.

intitni commented 2 months ago

Wait. It looks like the menu is already working for you. I think I miss read you messages.

Nivru commented 2 months ago

No Problem. Please suggest next steps

intitni commented 2 months ago

Please go to Console.app again, this time set the filter to category:Service any:CopilotForXcodeExtensionService. Accept Suggestion from the suggestion panel again, let me kown if there is any error that looks like Trigger menu item XXX Failed.

Nivru commented 2 months ago

Below are the Console logs

Screenshot 2024-09-30 at 6 09 12 PM Screenshot 2024-09-30 at 6 10 26 PM
intitni commented 2 months ago

Not these error, anything starts with "Trigger menu item"? also the filter is incorrect. It looks like copy pasting all at once will break the format, please paste one by one.

category:Service 
any:CopilotForXcodeExtensionService
Nivru commented 2 months ago

Now Applied correct filter and don't see anything related to "Trigger Menu items"

All logs are : The operation couldn’t be completed. (Swift.CancellationError error 1.)

Screenshot 2024-09-30 at 6 26 01 PM
intitni commented 2 months ago

These errors are not actually errors.

You can give this version a try and turn off "Trigger command with Accessibility API" to use a fallback solution to trigger menu items.

https://github.com/intitni/CopilotForXcode/releases/download/0.34.1/Copilot.for.Xcode.trigger.command.fallback.solution.fix.zip

But the experience is definitly not as good as the default behavior. You can add a keybinding to the Accept Suggestion menu item in Xcode and use that instead.

It's hard to tell what is going on if we can't see the logs. If you want to help by building the app, you can add a break point to XcodeInspector+TriggerCommand.swift between line 51 to 95 and run the ExtensionService target. The code will try to click the menu item in Xcode menu when you tab to accept a suggestion or accept a suggestion from the UI. If the above workround works for you, the issue should be in this few lines of code.

I would suggest overriding the path argument to ["Editor", "Copilot", "Write or Modify Code"] so you will know it's triggered when you see the modification window appears.

Nivru commented 1 month ago

Not sure what's wrong.

Tried with above version by turning Off "Trigger command with Accessibility API" but still same issue.

intitni commented 1 month ago

It's simply running the apple script:

tell application "System Events"
    set theprocs to every process whose unix id is     74496 // replace it with the pid of Xcode
    repeat with proc in theprocs
        tell proc
            repeat with theMenu in menus of menu bar 1
                set theValue to value of attribute "AXVisibleChildren" of theMenu
                if theValue is not {} then
                    return
                end if
            end repeat
            click menu item "Write or Modify Code" of menu 1 of menu item "Copilot" of menu 1 of menu bar item "Editor" of menu bar 1
        end tell
    end repeat
end tell

Other than calling click, you can return the value of the menu item to see if it exists.

When the toggle is on, it will do the similar thing in a more efficient way. You can try running in from the Script Editor.app to see if it works. If it doesn't, it's probably some mystery macOS bugs that only happens for some users.

It's still highly recommended to build the app and see if func triggerMenuItem(path: [String], activateApp: Bool) async throws fails for other reasons.

intitni commented 1 month ago

Oh sorry you have to activate the Xcode too, here is the updated script:

tell application "System Events"
    set theprocs to every process whose unix id is 20622 // update the id
    repeat with proc in theprocs
        tell proc
            set frontmost of proc to 1
            repeat with theMenu in menus of menu bar 1
                set theValue to value of attribute "AXVisibleChildren" of theMenu
                if theValue is not {} then
                    return
                end if
            end repeat
            click menu item "Write or Modify Code" of menu 1 of menu item "Copilot" of menu 1 of menu bar item "Editor" of menu bar 1
        end tell
    end repeat
end tell

I noticed that it won't work without Xcode been activated. It could also be that the activation of Xcode failed in triggerMenuItem().

intitni commented 1 month ago

This version will use another method to activate Xcode:

https://github.com/intitni/CopilotForXcode/releases/download/0.34.1/Copilot.for.Xcode.activate.app.with.accessibility.api.zip

github-actions[bot] commented 4 weeks ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 1 week ago

This issue was closed because it has been inactive for 14 days since being marked as stale.