CopilotForXcode icon indicating copy to clipboard operation
CopilotForXcode copied to clipboard

Accept button on floating window doesn't work

Open el-hoshino opened this issue 2 years ago • 15 comments

I'm experiencing a weird problem that on the suggestion floating window, the Accept button doesn't work. When I click on it, nothing happens. The suggestion isn't applied to the code, and the floating window doesn't disappear either.

スクリーンショット 2023-03-24 2 31 44

The reject button works as expected that no code changes and the floating window disappears.

I can accept it from Menu bar though

スクリーンショット 2023-03-24 2 32 40

But since it's too inconvenient so I've set a key binding to accept it as a workaround.

Is there anybody having the same problem?

My environment:

  • Chip: M1 Max
  • macOS: 13.2.1(22D68)
  • Xcode: 14.2 (14C18)
  • Copilot for Xcode: 0.8.6 (49)

el-hoshino avatar Mar 23 '23 17:03 el-hoshino

The accept button needs to click the menu bar item via Apple Script, it's not guarantee to always work. That's a limitation of a Xcode extension.

But I noticed that the code is using an old way to find the active Xcode, which may fail sometimes. So please give it a try when 0.9.0 comes out.

intitni avatar Mar 24 '23 01:03 intitni

May have been fixed in 0.9.1. If the bug still exists, it will not likely to be fixed in the future.

intitni avatar Mar 25 '23 17:03 intitni

Looks like the problem still exists. I made a workaround but it's not as good as the Apple Script solution.

I am reopening this issue. Since I can't reproduce this issue, if anyone is facing this issue and would like to give it a fix, please let me know.

When the button is clicked, it will fire PseudoCommandHandler.acceptSuggestion and runs an Apple Script that clicks the Accept Suggestion button from the menu bar.

intitni avatar Mar 29 '23 15:03 intitni

I'm still seeing this issue, closing Xcode and Copilot doesn't fix the issue, I usually have to restart the machine. Weirdly after the last time this happened, the Copilot for Xcode buttons wouldn't respond either and I can't type in Xcode it's not responding to keyboard input, it's almost like something else has the focus, but all other apps are working fine.

cameroncooke avatar Apr 26 '23 16:04 cameroncooke

Screenshot 2023-04-26 at 18 15 11

Just noticed this subtle message, looks like something is hanging in the plugin. Restarted and still having same issue.

cameroncooke avatar Apr 26 '23 17:04 cameroncooke

I had to downgrade to 0.12.0. The 0.13.x versions have been inconsistent and the UI of 0.13.3 stopped working almost entirely for me. The app info, launch agent, and account sections were non-functional and the accept button for suggestions was exhibiting the same behavior as what cameroncooke describes.

chickdan avatar Apr 26 '23 22:04 chickdan

I had to downgrade to 0.12.0. The 0.13.x versions have been inconsistent and the UI of 0.13.3 stopped working almost entirely for me. The app info, launch agent, and account sections were non-functional and the accept button for suggestions was exhibiting the same behavior as what cameroncooke describes.

I have just found the cause of the freezing. But what do you mean by incosistent?

intitni avatar Apr 27 '23 01:04 intitni

By inconsistent I mean that it has been flaky. I can restart my computer and it will work for a brief period then locks up. Sometimes multiple restarts won't fix it. Everything was great with 0.12.0 for the week I was on it.

It's great you found the cause! If you need any help testing I would be glad to be of assistance.

chickdan avatar Apr 27 '23 01:04 chickdan

I have released 0.13.4 which solves the issue that the app will freeze.

For the inconsistency that @chickdan, I haven't been able to reproduce it. The only place that looked suspicious was the boostQoS tweak, but it was introduced in 0.12.0. Could you please describe the "locks up" in details?

  • What is locked up? The source editor extension or the helper app or both? Was it freezing or crashing?
  • Did you see the message "The command *** is still busy" message in Xcode when the app stopped working?

For any issue with the Accept button, the temporary solution is to turn on "Use Accessibility API to accept suggestion in widget".

For anyone who want's to help locating the bug in code, I will provide more details on how to test the helper app:

  1. Clone the source code and initialize the submodule copilot.vim.
  2. Run the Extension Service target in release mode.
  3. Delete the extension service from Accessibility permission list, and add the one in the derived data to the list. The location of it looks like ~/Library/Developer/Xcode/DerivedData/Copilot_for_Xcode-erkqouoboqhkzzfdeclxdksmuqox/Build/Products/Release/CopilotForXcodeExtensionService.app.
  4. Open the installed host app, click remove launch agent and reload launch agent. Keep it open.
  5. Back to Xcode, the source extension should now talk to the Xcode-running extension service.

When you click the accept button, it will call PseudoCommandHandler().acceptSuggestion(), in the else branch, it will call Environment.triggerAction("Accept Suggestion") which will click a button from the menu bar with Apple Script. If there is anything wrong with this feature, it must be the script.

The script does 2 things: 1. make Xcode active, 2. click the menu if the menu is not already open.

intitni avatar Apr 27 '23 03:04 intitni

A new workaround for the accept button is released in 0.14.0 beta 3

intitni avatar Apr 27 '23 07:04 intitni

I am having this issue still in 16.0. I have only had it work a few times on my machine (2020 m1 macbook air.) If anyone has found a solution please let me know.

jamesgasek avatar May 20 '23 22:05 jamesgasek

@jamesgasek You can turn on "Accept Suggestion with Accessibility API" to workaround this issue.

intitni avatar May 21 '23 03:05 intitni

I'm experiencing this as well. Sometimes the Accept button works and sometimes it doesn't. It's maddening! I have tried all the possible workarounds.

One thing I noticed is that once the accept button fails, if I get suggestions again, the window appears for a fraction of a second and disappears. And sometimes pressing the get suggestions and accept suggestion shortcut in quick succession works.

I'm using version 0.27.1 on Xcode 15.1.0 Beta 3, macOS 14.1.1.

wonderbit avatar Dec 02 '23 16:12 wonderbit

@wonderbit If the accept button/keybinding/tab doesn't work, it's very likely the Copilot menu in Xcode - Menu Bar - Editor is greyed out. It's an Xcode bug that usually happens right after you update the extension. So please remember to restart Xcode after updating the extension.

Another possible cause is you have multiple versions of Copilot for Xcode.app on your Mac, and Xcode is confused by them.

intitni avatar Dec 02 '23 16:12 intitni

Restarting Xcode works here! I thought the shortcut feature was locked behind the paywall now 😅

minhnh94 avatar Mar 31 '24 13:03 minhnh94