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]: real-time Suggestion do not working properly. #516

Closed yuhuajun100 closed 4 months ago

yuhuajun100 commented 6 months ago

Before Reporting

What happened?

The software enables real-time Suggestion. As the code was being written, a feature was triggered, but no advice was given. If this feature is triggered manually, any recommendations are still given。

https://github.com/intitni/CopilotForXcode/assets/15060885/91e3ca3a-92a4-4498-bcc8-ac3eea3b28f9

How to reproduce the bug.

It just happened!

Relevant log output

No response

macOS version

14.5

Xcode version

xcode 15.4

Copilot for Xcode version

0.31.3

intitni commented 6 months ago

Please try updating the app to the latest version.

If the issue persists, please let me know:

yuhuajun100 commented 6 months ago

Codeium for Xcode 0.31.3 is currently the newest version available. Xcode app 15.4 is currently the newest version available. Watch the video below

https://github.com/intitni/CopilotForXcode/assets/15060885/fd067164-ac96-411d-a036-c8c1f9bbf259

intitni commented 6 months ago

Please simply use Copilot for Xcode. Codeium for Xcode is just a subset of the app.

Moving text cursor will not trigger realtime suggestion and will cancel all previous requests, please don't move the text cursor by clicking or arrow keys in the video.

nenseso commented 6 months ago

I have the same problem only use Copilot for Xcode. version: 0.33.0. circular widget animates when I stop typing widgets aslo updates their position when the Xcode window moves. image image image

intitni commented 6 months ago

@nenseso If you saw the animation that means the app was working. Maybe there was something wrong with the GitHub Copilot language server.

Please turn on verbose log. Open Console.app and click start streaming, set the filter to category:GitHubCopilot. Try to trigger real-time suggestion and see what the logs are. If you don't see any log, restart the service app.

nenseso commented 6 months ago

@nenseso If you saw the animation that means the app was working. Maybe there was something wrong with the GitHub Copilot language server.

Please turn on verbose log. Open Console.app and click start streaming, set the filter to category:GitHubCopilot. Try to trigger real-time suggestion and see what the logs are. If you don't see any log, restart the service app.

Thanks for your response! I wasn’t sure what happened, but today when I upgraded my version to 0.33.1 beta, everything started working fine. Here's what I did:

  1. Uninstall version 0.33.0.
  2. Downloaded version 0.33.1 beta and placed it in the Applications folder.
  3. Removed Accessibility API permission and re-added it again.
  4. open Copilot for Xcode.app again
  5. open Xcode After these steps, it worked! Thanks again for your help. Next time, I'll know to check Console.app for GitHub Copilot logs. image
arigatou1985 commented 6 months ago

I started experiencing the same issue just a few days ago. It used to work perfectly say for 2 ~ 3 weeks ago. In the Console.app, I found the following message when the suggestion stops working:

Try getting suggestions again: Language server error: Server error: -32603 non-abort error on ghost text request nil

Restarting Xcode and Copilot for Xcode together will bring back the suggestion prompts, but after a few minutes, the suggestions will stop again, i.e., no suggestion prompt during coding. I tried to re-install Copilot for Xcode, I even tried it with Xcode 15.4, 15.3, the issue persists.

intitni commented 6 months ago

@arigatou1985 This error happens when the the network request failed inside the language server. It's hard to tell what was going on.

Please try setting the console filter to

any:CopilotForXcodeExtensionService
category:ProtocolTransport

Hopefully we can get more information from it.

intitni commented 6 months ago

@arigatou1985 By the way, are you using self-signed certificates? I found that it can happen when I was using MITM on the GitHub Copilot domain names. It works at the beginning but stops working later.

arigatou1985 commented 6 months ago

@arigatou1985 This error happens when the the network request failed inside the language server. It's hard to tell what was going on.

Please try setting the console filter to

any:CopilotForXcodeExtensionService
category:ProtocolTransport

Hopefully we can get more information from it.

I tried to filter console logs using the same exact two filters above, but didn't get anything at all when the suggestion prompt stops working. Only console message relevant are from single filter: process CopilotForXcodeExtensionService, regarding server error as mentioned above.

I'm sure my computer doesn't have self-signed certificates doing MITM related work when I experience the issue. GitHub copilot works perfectly fine continuously in my Visual Studio Code.

From what I experimented with so far, when I restart Xcode, and copilot for Xcode, after about 4 minutes, suggestions prompt will stop working.

intitni commented 6 months ago

@arigatou1985 Oh you have to turn on verbose log in the GitHub Copilot settings then restart the app.

arigatou1985 commented 6 months ago

@arigatou1985 Oh you have to turn on verbose log in the GitHub Copilot settings then restart the app.

Yes, it was "checked" in the Service -> GitHub Copilot -> Advanced -> Verbose Log.

intitni commented 6 months ago

@arigatou1985 It's weird. The only possible situation that I can think of is the language server has crashed. Please give this version a try: https://github.com/intitni/CopilotForXcode/releases/download/0.1.0/Copilot.for.Xcode.app.debug.20240530.1824.zip

This version fixes a few bugs about the life cycle of the language server processes.

If this version fixes it for you, could you please let me know if you were opening any files that seems suspicious to crash the language server? For example, large file, non-text file, file contains weird symbols?

arigatou1985 commented 6 months ago

@arigatou1985 It's weird. The only possible situation that I can think of is the language server has crashed. Please give this version a try: https://github.com/intitni/CopilotForXcode/releases/download/0.1.0/Copilot.for.Xcode.app.debug.20240530.1824.zip

This version fixes a few bugs about the life cycle of the language server processes.

If this version fixes it for you, could you please let me know if you were opening any files that seems suspicious to crash the language server? For example, large file, non-text file, file contains weird symbols?

I trie this build, it doesn't help with the issue unfortunately. I tried on a small iOS project with less than 50 source files, approximately 1000 lines of code in total. No big binary files, or strange symbols in any source code.

I extract a console log. Hope you can find something useful. no_suggestions_log.txt

intitni commented 6 months ago

@arigatou1985 sadly there is no useful information. It’s really weird that you can't see and logs from the ProtocolTransport category. Can you constantly get the errors you showed me after it stops working?

Would you mind trying the following:

intitni commented 6 months ago

I will submit a build later to always post the logs no matter what the state of the toggle is later.

arigatou1985 commented 6 months ago

@arigatou1985 sadly there is no useful information. It’s really weird that you can't see and logs from the ProtocolTransport category. Can you constantly get the errors you showed me after it stops working?

Would you mind trying the following:

  • Turn the verbose log toggle off and back on.
  • Kill the node processes created by CopilotForXcodeExtensionService in Activity Monitor and try to get suggestions again.

I get those logs every time when suggestions stop working. But nothing from ProtocolTransport category. I tried to turn verbose log off and on. Restarted the copilot for xcode a couple of times. Also tried to kill the node processes created by CopilotForXcodeExtensionService. Unfortunately none of them helped.

intitni commented 6 months ago

@arigatou1985 https://github.com/intitni/CopilotForXcode/releases/download/0.1.0/Copilot.for.Xcode.app.debug.20240530.2023.zip

If you still can't see the logs, I honestly don't know what else we can do. You can still try:

arigatou1985 commented 6 months ago

@arigatou1985 https://github.com/intitni/CopilotForXcode/releases/download/0.1.0/Copilot.for.Xcode.app.debug.20240530.2023.zip

If you still can't see the logs, I honestly don't know what else we can do. You can still try:

  • Deleting the app completely including ~/Library/Application Support/com.intii.CopilotForXcode and reinstall.
  • Change "run node with" to other values.
  • MitM the requests to copilot-proxy.githubusercontent.com to see what is going on. You may need to turn on "Load certificates in keychain".
  • Run the app in Xcode. You need to run both the ExtensionService target and the CommunicationBridge target. You can set a break point to /Tool/Sources/GitHubCopilotService/LanguageServer/GitHubCopilotService.swift:408. Hopefully you can see the logs in the debug area.

I tried to delete the directory for complete uninstallation. Didn't help. I used a web proxy app to observe the communication between my computer to github, didn't find anything related to copilot-proxy.githubusercontent.com, but only copilot-telemetry.githubusercontent.com. I will try to set up and run the project in xcode. It might take more time, I'll come back if I find anything interesting. BTW, on another intel iMac, with latest MacOS and Xcode, and copilot for xcode, all works perfectly without any issue. The problem only occurs on my M3 chip macbook pro.

intitni commented 6 months ago

@arigatou1985 Thank you! Let me know if you need any help.

arigatou1985 commented 6 months ago

Thanks to your previous hints. I've experimented more with Node settings, and discovered that running node with /usr/bin/env always lead to no suggestions prompt issue few minutes after starting copilot and Xcode, while /bin/bash/ -i -l works reliably. I switched between these options many times and tried very thoroughly and can confirm the problem roots from the node selection setting.

Screenshot 2024-06-01 at 07 29 56
pawel-movelab commented 5 months ago

Im having the same problem as described by OP. None of the suggestions in this thread helps. Icon shows for a seconds and disappears without any suggestion of code snippet. Really annoying issue.

My console logs indicates that file URI cannot be accessed...

Try getting suggestions again: Language server error: Server error: -32602 Document for URI could not be found: file:///Users/username/filename.swift, URIs of the known document are: nil

intitni commented 5 months ago

@pawel-movelab please provide your settings in screenshots, logs, node version so that I can help you.

You can get the logs by turning on verbose log in the GitHub Copilot settings, restart the service app if, open Console.app, click start streaming, and set the filter to one of the following

any:CopilotForXcodeExtensionService
category:ProtocolTransport

Or

any:CopilotForXcodeExtensionService
category:GitHubCopilot

You mentioned that the widget appears and disappears, did it crash? Or you have turned on “Hide circular widget”?

pawel-movelab commented 5 months ago

You mentioned that the widget appears and disappears, did it crash? Or you have turned on “Hide circular widget”?

Yes, I had that option checked. I unchecked it but no help.

I tried to get these logs but not getting any.

➜ ~ node --version v22.2.0 Screenshot 2024-06-03 at 14 52 11

Launching service app keeps on showing on the app screen: Screenshot 2024-06-03 at 14 52 53

Screenshot 2024-06-03 at 14 53 25

Screenshot 2024-06-03 at 14 53 46

intitni commented 5 months ago

Thanks to your previous hints. I've experimented more with Node settings, and discovered that running node with /usr/bin/env always lead to no suggestions prompt issue few minutes after starting copilot and Xcode, while /bin/bash/ -i -l works reliably. I switched between these options many times and tried very thoroughly and can confirm the problem roots from the node selection setting.

Screenshot 2024-06-01 at 07 29 56

Glad it worked. The key difference between these options is that different configuration files will be used.

I am not sure about /usr/bin/env, it seems to be using the shell in the current environment, either bash or your default shell, but not in the login interactive mode.

/bin/bash/ -i -l will use your bashrc and the last one will use the one for your default shell.

Maybe there are some settings generating conflicts to the node process or the language server.

intitni commented 5 months ago

@pawel-movelab If you don't see any log, I suspect that you are having a similar issue to that of arigatou1985. The language server is not launched properly.

Do you mind setting up the debug server of the app by running defaults write ~/Library/Group\ Containers/5YKZ4Y3DAW.group.com.intii.CopilotForXcode/Library/Preferences/5YKZ4Y3DAW.group.com.intii.CopilotForXcode.plist TestUtilityBaseURL "https://copilotforxcode-testutility.intii.com"

Once you trigger a suggestion, I will be able to see the logs of it. I can read the prompt, too so please make sure don't do it on your real code.

You can unset it later with defaults delete ~/Library/Group\ Containers/5YKZ4Y3DAW.group.com.intii.CopilotForXcode/Library/Preferences/5YKZ4Y3DAW.group.com.intii.CopilotForXcode.plist TestUtilityBaseURL

If I can't see the logs either, it's probably the issue I just mentioned. Please try different "Run node with" options, and take a look into your ~/bashrc or ~/zshrc or other similar files.

pawel-movelab commented 5 months ago

@pawel-movelab If you don't see any log, I suspect that you are having a similar issue to that of arigatou1985. The language server is not launched properly.

Do you mind setting up the debug server of the app by running defaults write ~/Library/Group\ Containers/5YKZ4Y3DAW.group.com.intii.CopilotForXcode/Library/Preferences/5YKZ4Y3DAW.group.com.intii.CopilotForXcode.plist TestUtilityBaseURL "https://copilotforxcode-testutility.intii.com"

Once you trigger a suggestion, I will be able to see the logs of it. I can read the prompt, too so please make sure don't do it on your real code.

You can unset it later with defaults delete ~/Library/Group\ Containers/5YKZ4Y3DAW.group.com.intii.CopilotForXcode/Library/Preferences/5YKZ4Y3DAW.group.com.intii.CopilotForXcode.plist TestUtilityBaseURL

If I can't see the logs either, it's probably the issue I just mentioned. Please try different "Run node with" options, and take a look into your ~/bashrc or ~/zshrc or other similar files.

I just made few attempts to trigger it in empty repo I created. Can you see it?

intitni commented 5 months ago

@pawel-movelab I saw the error, it looks like the language server doesn't recognize the file.

Screenshot 2024-06-03 at 21 21 52

Please turn on enable Xcode Inspector debug menu in the advanced settings and show me the content in the menu. Also let me know if it works in a git enabled project.

Screenshot 2024-06-03 at 21 16 47
pawel-movelab commented 5 months ago

Screenshot 2024-06-03 at 15 21 43

intitni commented 5 months ago

@pawel-movelab Sorry I have no idea. Everything looks correct to me. If the language server can't find the file, it's very likely that the open file notification sent to the language server is failed or not fired. If it failed, you should see the logs, with or without verbose log on.

I still don't understand why you can't see the logs. Do you mind trying the Console.app again but this time set the filter to only category:GitHubCopilot, open a new tab in Xcode, make some changes and see if there is any open or change requests?

If you still can't see them, all I can suggest is to build and run the app in Xcode. You need to run both the ExtensionService target and the CommunicationBridge target. You may want to look at /Tool/Sources/GitHubCopilotService/GitHubCopilotExtension.swift:39 for the open file request and /Tool/Sources/GitHubCopilotService/LanguageServer/GitHubCopilotService.swift:362 for the get suggestion request.

pawel-movelab commented 5 months ago

I am getting hits in Console app with the filter you suggested:

Try getting suggestions again: Language server error: Server error: -32602 Document for URI could not be found: file:///user/file.swift, URIs of the known document are: nil

intitni commented 5 months ago

@pawel-movelab I can get the same error if I disable the files and folders permission, do you want to check that?

Screenshot 2024-06-03 at 21 44 45

System settings > Privacy and Security > Files and Folders

pawel-movelab commented 5 months ago

@pawel-movelab I can get the same error if I disable the files and folders permission, do you want to check that? Screenshot 2024-06-03 at 21 44 45

System settings > Privacy and Security > Files and Folders

After enabling access to all locations and restarting both Xcode and Copilot for Xcode apps it started to work! Thank you! 🥳

Btw I just noticed that tab aceepting suggestions in playground won't work.

intitni commented 5 months ago

@pawel-movelab Only in playground?

pawel-movelab commented 5 months ago

Yes, only there. In Xcode works normally

intitni commented 5 months ago

@pawel-movelab Can you accept the suggestions in other ways, for example the buttons?

pawel-movelab commented 5 months ago

Yes, the button accepting works

intitni commented 5 months ago

@pawel-movelab That's super weird. Does it work if you create a swift file in the Sources folder in the playground and try them out? Can you upload the playground file and let me know which folder/path it is in?

intitni commented 5 months ago

@pawel-movelab Oh yeah, I forgot there are a lot of logs about tab to accept were added to the latest build. Please set the Console.app filter to category:Debug, let me know what you observed.

pawel-movelab commented 5 months ago

@intitni I tested again and after our yesterday fix it works as well in Playgrounds! Thanks a lot for your fast help and replies!

github-actions[bot] commented 4 months ago

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

github-actions[bot] commented 4 months ago

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