1 个不稳定版本
0.1.0 | 2022 年 12 月 31 日 |
---|
#15 在 #建议
12KB
119 行
code-errrors
构建一个命令行工具,当开发人员在编码时遇到错误时提供建议!
工作原理
- 运行命令
code-errors gcc hello.c
。 - 它将运行给定的命令,并将我们得到的错误解析并发送到 OPEN AI。
- 打印 OPEN AI 给出的建议。
设置步骤
安装
对于 MacOS,运行以下命令
brew tap probro27/tap
brew install code-errors
- 在注册后从 https://openai.com/api/ 获取 OPENAI API 密钥。
- 创建一个名为
OPENAI_SK
的环境变量。在 MacOS 或 Linux 中设置此变量的示例是将export OPENAI_SK="<your_api_key>"
放入~/.bash_profile
并运行source ~/.bash_profile
。 - 现在,使用命令
code-errors <command>
运行您的代码。
用法 - 示例
编写一个包含代码的 hello.c
文件(如果可以找到明显的错误则加分)
#include <stdio.h>
int main() {
print("Hello world!");
return 0;
}
这看起来像是一个简单的 hello world 程序。让我们使用我们最喜欢的编译器 gcc
编译它。
运行: code-errors gcc hello.c
结果
Result: Code: 1, error/output:
hello.c:4:5: error: implicit declaration of function 'print' is invalid in C99
[-Werror,-Wimplicit-function-declaration]
print("Hello world!, %1f");
^
hello.c:4:5: note: did you mean 'printf'?
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer
/SDKs/MacOSX.sdk/usr/include/stdio.h:170:6: note: 'printf' declared here
int printf(const char * __restrict, ...) __printflike(1, 2);
^
1 error generated.
Suggestion is:
Suggestion:
The error message is telling that the implicit function 'print' is being used in line 4 -
it should either be changed to 'printf' or the library containing the definition of 'print' should
be included. It is also suggesting to include stdio.h header file which contains the definition
of printf() function.
Links:
1. Implicit function declaration - https://cppreference.cn/w/c/language/implicit_declaration
2. printf() - https://cppreference.cn/w/c/io/printf
依赖关系
~6–21MB
~288K SLoC