DEV Community

Woody
Woody

Posted on

How to use github copilot config idea pycharm and vscode

太棒了,恭喜你成功登录并使用 GitHub Copilot!以下是为你整理好的一篇完整博客文章,可直接复制到你的博客平台发布或稍作润色。


💻 IntelliJ IDEA 配置 GitHub Copilot 全流程教程(适用于中国大陆用户)

在本文中,我将分享如何在 IntelliJ IDEA 中成功配置并使用 GitHub Copilot,包括科学上网设置、插件安装、登录失败的解决方法等。适用于大陆用户,亲测有效!


🧩 背景介绍

GitHub Copilot 是由 GitHub 和 OpenAI 推出的 AI 编程助手,可以在你写代码时实时补全整段函数、注释、逻辑代码,非常适合 Java、Python、JS 等多语言开发者。

但由于 Copilot 的服务在国内网络访问存在障碍,很多人在 IntelliJ IDEA 中登录会失败,比如:

Sign in failed. Reason: Request signInInitiate failed with message: connect ETIMEDOUT ...
Enter fullscreen mode Exit fullscreen mode

这类错误其实都是网络问题导致无法连接 Copilot 服务。


🛠️ 一、准备工作

1. 安装 GitHub Copilot 插件

  • 打开 IntelliJ IDEA;
  • 菜单栏:File → Settings → Plugins
  • 搜索 GitHub Copilot,点击安装;
  • 安装完成后重启 IDEA。

2. 配置科学上网工具(以 Clash 为例)

如果你已经可以通过 Chrome 访问 Google 和 GitHub,说明 Clash 已经生效。但 IDEA 默认并不会自动走代理,需要手动配置。

常见 Clash 默认端口:

协议 地址 端口
HTTP 127.0.0.1 7890
SOCKS5 127.0.0.1 7891

⚙️ 二、IntelliJ IDEA 设置代理

  1. 打开 IDEA,点击: File → Settings → Appearance & Behavior → System Settings → HTTP Proxy
  2. 选择:Manual proxy configuration
  3. 设置为:
   Host: 127.0.0.1
   Port: 7890
   ✅ 勾选 "Use proxy for HTTPS"
Enter fullscreen mode Exit fullscreen mode
  1. 点击 Check connection 测试 GitHub 是否可连;
  2. 成功后点击 OK 保存设置。

🔐 三、登录 GitHub Copilot 插件

  1. 打开菜单:File → Settings → GitHub Copilot
  2. 点击【Log In】按钮;
  3. IDEA 会弹出登录提示,内容如下:
   To authenticate, visit: https://github.com/login/device
   And enter the code: XXXX-XXXX
Enter fullscreen mode Exit fullscreen mode
  1. 打开浏览器访问:https://github.com/login/device 粘贴代码,登录 GitHub 并授权;
  2. IDEA 自动完成授权,Copilot 开始工作!

✨ 四、使用 GitHub Copilot 补全代码

使用方法非常简单,只需要在代码中写注释或方法名,Copilot 就会给出建议。

示例(Java):

// 判断一个数是否是质数
Enter fullscreen mode Exit fullscreen mode

Copilot 自动补全为:

public static boolean isPrime(int num) {
    if (num <= 1) return false;
    for (int i = 2; i <= Math.sqrt(num); i++) {
        if (num % i == 0) return false;
    }
    return true;
}
Enter fullscreen mode Exit fullscreen mode

🎯 快捷键小贴士

操作 Windows / Linux macOS
接受补全 Tab Tab
跳过建议 Esc Esc
下一个建议 Alt + ] Option + ]
上一个建议 Alt + [ Option + [

🧯 常见问题排查

问题 原因 解决方案
登录失败,connect ETIMEDOUT 网络连接 Copilot 超时 配置 Clash + IDEA 代理
没有弹出建议 未登录或未启用 检查插件是否启用、语言支持
GitHub 授权页打不开 网络问题 切换 Clash 为“全局模式”临时使用

✅ 总结

通过以下 4 步,即可顺利在 IDEA 使用 GitHub Copilot:

  1. 安装插件;
  2. 配置 Clash + IDEA 的代理;
  3. 登录 GitHub(device code 认证);
  4. 开始自动补全!

这套流程适用于 JetBrains 全系列 IDE,如 PyCharm、WebStorm 等。

Top comments (0)