系列文章:
编程AI深度实战:私有模型deep seek r1,必会ollama-CSDN博客
编程AI深度实战:自己的AI,必会LangChain-CSDN博客
编程AI深度实战:火的编程AI,都在用语法树(AST)-CSDN博客
编程AI深度实战:让verilog不再是 AI 的小众语言-CSDN博客
【痛点】
传统Verilog开发中,工程师不断"编码→仿真→查错"的循环。本文整合AST解析与Vim编辑器,在编码阶段即实现:
✔️ 自动标记逻辑问题
✔️ AI+ 发现涉及多模块逻辑错误
✔️ 强制代码风格
【解决方案】
1️⃣ 基于AST的精准模式匹配
- 深度集成ast-grep与coc.nvim
- 可视化错误标注
2️⃣ 开箱即用的开发环境
- my-language.so高性能解析器
- 支持Verilog/SystemVerilog
【基础环境】
1️⃣ vim + coc.nvim
- 安装
git clone https://github.com/neoclide/coc.nvim.git ~/.vim/pack/others/start/ast-grep
- ~/.vimrc 配置
:filetype on
" https://raw.githubusercontent.com/neoclide/coc.nvim/master/doc/coc-example-config.vim “可能需要 Vim(不是 Neovim),因为 coc.nvim 通过计数计算字节偏移量 ” utf-8 字节序列 set encoding=utf-8 “某些服务器的备份文件存在问题,请参阅#649 set nobackup set nowritebackup “更新时间过长(默认为 4000 毫秒 = 4 秒)会导致明显的 ”延迟和糟糕的用户体验 set updatetime=300 “始终显示符号列,否则每次都会移动文本 ”诊断出现/得到解决 set signcolumn=yes
2️⃣ ast-grep
- 安装
pip install ast-grep-cli
sg --version 查看是否成功
【订阅即得】
👉 文末附my-language.so下载链接(百度网盘)
本文基于ast-grep,以及coc.nvim,并基于以下verilog parser(my-language.so,文末下载链接), 可以在vim中实时显示自定义的verilog 匹配。效果图如下:
这个标记来自一个id为‘b‘的rule。它寻找always块。 rule在rules/x.yml中定义。
当然可以定义更复杂的规则。
除了rules,再设置sgconfig.yml以支持自定义的verilog语言。其中就要用到这个my-language.so库,库已经编好。开箱即用。
coc.nvim的设定中,也就是coc-settings.json中应该把ast-grep设置为lsp。这样vim内就可以实时的检查ast-grep定义的规则!
需要的配置如下:
什么是AST
大模型火了之后,有非常多的LLM 代码生成,编辑,和普通对话的开源vim/neovim插件,文末列了一下github上几乎所有的了。
但是,并不是各个都好用。其实star多的就那么几个,为什么呢,
从aider, cursor这些火的软件大概可以看出端倪。这两个软件都利用了AST来indexing或者map codebase。
这也是ast重要性的体现。
下面是aider的支持的语言列表,对verilog默认是不支持的。
Language | File extension | Repo map | Linter |
---|---|---|---|
bash | .bash | ✓ | |
c | .c | ✓ | ✓ |
c_sharp | .cs | ✓ | ✓ |
commonlisp | .cl | ✓ | |
cpp | .cc | ✓ | ✓ |
cpp | .cpp | ✓ | ✓ |
css | .css | ✓ | |
dockerfile | .dockerfile | ✓ | |
dot | .dot | ✓ | |
elisp | .el | ✓ | ✓ |
elixir | .ex | ✓ | ✓ |
elm | .elm | ✓ | ✓ |
embedded_template | .et | ✓ | |
erlang | .erl | ✓ | |
go | .go | ✓ | ✓ |
gomod | .gomod | ✓ | |
hack | .hack | ✓ | |
haskell | .hs | ✓ | |
hcl | .hcl | ✓ | |
html | .html | ✓ | |
java | .java | ✓ | ✓ |
javascript | .js | ✓ | ✓ |
javascript | .mjs | ✓ | ✓ |
jsdoc | .jsdoc | ✓ | |
json | .json | ✓ | |
julia | .jl | ✓ | |
kotlin | .kt | ✓ | ✓ |
lua | .lua | ✓ | |
make | .mk | ✓ | |
objc | .m | ✓ | |
ocaml | .ml | ✓ | ✓ |
perl | .pl | ✓ | |
php | .php | ✓ | ✓ |
python | .py | ✓ | ✓ |
ql | .ql | ✓ | ✓ |
r | .R | ✓ | |
r | .r | ✓ | |
regex | .regex | ✓ | |
rst | .rst | ✓ | |
ruby | .rb | ✓ | ✓ |
rust | .rs | ✓ | ✓ |
scala | .scala | ✓ | |
sql | .sql | ✓ | |
sqlite | .sqlite | ✓ | |
toml | .toml | ✓ | |
tsq | .tsq | ✓ | |
typescript | .ts | ✓ | ✓ |
typescript | .tsx | ✓ | ✓ |
yaml | .yaml | ✓ |
VIM AI插件列表
代码编辑类
成熟、功能齐全、可配置的插件以粗体突出显示。
- 2023-01-16 naps62/pair-gpt.nvim (35☆)
#inline
model:openai
- 2023-02-08 jdnewman85/openai-vim (5☆)
#inline
model:openai
- 2023-04-06 thmsmlr/gpt.nvim (20☆)
#inline
model:openai
- 2023-04-06 aduros/ai.vim (265☆)
#inline
model:openai
- 2023-05-02 dpayne/CodeGPT.nvim (698☆)
#inline
#templates
model:openai
- 2023-06-25 madox2/vim-ai (354☆)
#inline
#chat
#templates
model:openai
- 2023-07-03 oelmekki/make-my-code-better.vim (2☆)
#inline
model:openai
- 2023-07-13 tom-doerr/vim_codex (245☆)
#inline
model:openai
- 2023-07-20 gsuuon/llm.nvim (38☆)
#inline
#templates
model:openai
model:bard
model:huggingface
model:local
- 2023-08-02 CoderCookE/vim-chatgpt (141☆)
#inline
model:openai
- 2023-08-16 jackMort/ChatGPT.vim (2500☆)
#inline
#workflow
#chat
#templates
model:openai
- 2023-08-18 dense-analysis/neural (313☆)
#inline
model:openai
- 2023-08-19 jayli/nvim-ai-coding (6☆)
#inline
model:openai
- 2023-03-18 0xStabby/chatgpt-vim (47☆)
#inline
model:chatgpt
model:openai
聊天类
这些插件的功能都非常相似。Robitx/gp.nvim 具有丰富的配置选项,还包括用于编写和编辑代码的命令(即与上面的部分重叠)。
- 2023-01-07 lambdalisue/butler.vim (29☆)
#chat
model:openai
- 2023-03-26 IwasakiYuuki/ai-assistant.nvim (3☆)
#chat
model:openai
- 2023-04-22 macrat/askgpt.vim (2☆)
#chat
model:openai
- 2023-07-26 yuki-yano/ai-review.vim (16☆)
#chat
model:openai
- 2023-08-11 charlespascoe/vim-chatgpt (1☆)
#chat
model:openai
- 2023-08-12 micheam/ai-assistant-console (0☆)
#chat
model:openai
- 2023-08-23 CamdenClark/flyboy (25☆)
#chat
model:openai
- 2023-08-28 Robitx/gp.nvim (55☆)
#inline
#chat
#templates
model:openai
- 2023-08-29 martineausimon/nvim-bard (21☆)
#chat
model:bard
代码自动补全类
这些插件的功能也几乎相同,也许更重要的是比较 (1) 订阅费用是多少,以及 (2) 输出质量。一个突出的插件是 huggingface/llm.nvim,它使用托管在 Hugging Face 上的免费推理端点。
- 2023-05-10 tzachar/cmp-tabnine (263☆)
#autocomplete
model:custom
- 2023-08-22 github/copilot.vim (6000☆)
#autocomplete
model:custom
- 2023-08-25 zbirenbaum/copilot.lua (1400☆)
#autocomplete
model:custom
- 2023-08-28 codota/tabnine-nvim (206☆)
#autocomplete
#chat
model:custom
- 2023-08-30 Exafunction/codeium.vim (2100☆)
#autocomplete
model:custom
- 2023-08-31 huggingface/llm.nvim (243☆)
#autocomplete
model:huggingface
- 2023-08-31 zbirenbaum/copilot-cmp (723☆)
#autocomplete
model:custom
- 2023-09-01 TabbyML/tabby (9500☆)
#autocomplete
model:custom
其他类型
james1236/backseat.nvim 在代码行之间提供注释,而 svermeulen/text-to-colorscheme 有助于在编程时设定氛围。
- 2023-04-15 james1236/backseat.nvim (143☆)
#augment
model:openai
- 2023-05-27 mthbernardes/codeexplain.nvim (79☆)
#augment
model:local
- 2023-06-26 svermeulen/text-to-colorscheme (187☆)
#other
model:openai
my-language.so下载地址
链接:https://pan.baidu.com/s/1_ZGXWCvc_64IiIWUc5fwNw
提取码:vpar