GitHub Copilot Labs 中文解释技巧及其它不靠谱的功能
![](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/2b7b2c114379ae6ae915f760359a7b4f.jpeg)
前言
网址: https://githubnext.com/projects/copilot-labs
![image-20230420232705404](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/039d3b55055c2b4d5d22616a6238d8ee.png)
Copilot Labs 是一个实验性的项目,目前除了 vscode 插件。
主要功能有:
- 解释代码
- 翻译代码
- 各种工具刷子(加注释、加类型、抽取代码、去注释、加安全代码,自定义。。。)
- 编写测试
估计你和我一样都是想看看这个 copilot labs 能做到什么程度的工作。
正文
安装 GitHub Copilot Labs
目前只有 vscode 插件,安装顺序:
- github copilot 插件先安装,激活
- github copilot labs 插件安装,激活
![image-20230420232902177](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/39326ab7fe6e0f21a265447ba5c67d02.png)
左侧面板打开侧栏
![image-20230420233019317](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/23f52d3fb636e48186f6908c5a972728.png)
选中代码后左侧栏自动显示
![image-20230420233152533](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/c278fade3a60738bdab97293cb79b2be.png)
中文解释代码
这不错
很多同学反应解释这个代码英文的,看着不习惯。
![image-20230421001301963](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/aaee6c4c3e6f2ce2d9403bf68fca87f6.png)
类型选 custom , 在 prompt 中加入中文要求。
代码转换
![image-20230421091551819](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/aac4e89196687ddfe6426c0eaf2d8fd1.png)
支持的语言很多
![image-20230421091629841](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/264bd3cff5dedee15d08f2aef68bad45.png)
提升代码可读性
不敢用,破坏代码
处理之前
chapterCount = course?.chapters?.length ?? 0;
for (int i = 0; i < chapterCount; i++) {
var chapter = course?.chapters?[i];
sectionCount += chapter?.sections?.length ?? 0;
for (int j = 0; j < (chapter?.sections?.length ?? 0); j++) {
var section = chapter?.sections?[j];
minutesAll += section?.minutes ?? 0;
}
}
可读性处理
![image-20230421092005609](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/7431dac4b51b6ec7fbf99eb6f6da4b85.png)
加类型定义
还可以
之前
// 载入播放器
Future<void> loadVideoPlayer({ nextSuri}) async {
suri = nextSuri ?? suri;
videoController?.pause();
videoController?.dispose();
chewieController?.dispose();
之后
![image-20230421092714884](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/b0c0a63441067db3bc6437ac087221ad.png)
修改bug
不敢用,破坏代码
之前
// 载入播放器
Future<void> loadVideoPlayer({String nextSuri}) async {
suri = nextSuri ?? suri;
videoController.pause();
videoController.dispose();
chewieController.dispose();
if (section?.minutes == 0) {
return;
}
之后
![image-20230421093100406](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/6682a7ffde7a51109df164db02529d9e.png)
调试
不敢用,破坏代码
![image-20230421093158039](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/1e668d59e38135c289a730fda4d6e844.png)
就是给你加入了 print 代码
清除注释
不敢用,破坏代码
![image-20230421093317907](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/cddc00459d8890d22684540402fdab7c.png)
逐行注释
还可以,不会破坏代码
![image-20230421093423245](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/034729ad4b2b006915c8448762fc57c6.png)
加安全代码
还可以, 但是需要我仔细的调试代码
![image-20230421093623749](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/a727c90a2a8c11a6a45b7f71d1355e6c.png)
抽取代码
还可以,但是需要自己测试好
![image-20230421093851421](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/9436fa5dda56c9fda1c90e2b768421c5.png)
文档编写
看着还可以,挺能忽悠
![image-20230421093930461](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/4f03593552804af44ccdf9ced67d18b5.png)
自定义执行
接着用中文忽悠
输入: 加入中文函数注释,包括函数入参、返回值、每一步执行过程说明
![image-20230421094612105](https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2023/04/85e421159c8d3353f1102545f78441dc.png)
小结
GitHub Copilot Labs 是一个强有力的 copilot 补强,但是目前还在测试阶段,很多功能都是有问题的。造成很多 bug,所以你要自己去阅读调试。
一句话总结,只能帮上很基础的代码工作,但是往往这种工作是耗费体力的,正好可以用上。
end