Protobuf 已支持 LSP。不客气。
Protobuf has LSP support. You're welcome

原始链接: https://buf.build/blog/protobuf-lsp

Buf 发布了首个功能完备、达到生产环境标准的 Protobuf 语言服务器协议(LSP)服务器。该工具由 Buf CLI 提供支持,首次为 VSCode 和 Neovim 等编辑器带来了现代 IDE 功能,包括代码补全、“跳转到定义”以及高级诊断。 Buf LSP 基于全新的查询驱动型编译器前端构建,相比传统的 `protoc` 编译器,它能够提供更快、更准确的错误报告,并具备更优的性能。该工具专为处理大规模工作空间而设计,并为支持如 Editions 2024 等即将推出的 Protobuf 特性做好了准备。 此次发布是 Buf 持续简化 Protobuf 开发,并与 ConnectRPC 和 Buf Schema Registry 等工具共同强化生态系统这一努力的一部分。展望未来,Buf 计划为 LSP 增加更多功能,包括自动导入、更智能的代码补全以及对 Protovalidate 的专门支持。Buf LSP 现已发布,用户可以通过 Buf VSCode 插件或配置其首选的 LSP 兼容编辑器进行集成。

Hacker News 最新 | 往期 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Protobuf 已支持 LSP。不客气 (buf.build) 6 点,由 theanonymousone 发布于 44 分钟前 | 隐藏 | 往期 | 收藏 | 1 条评论 echelon 5 分钟前 [–] 在 LLM(大语言模型)时代,Buf 提供的 Protobuf 注册表和代码生成 SDK 似乎没那么必要了。 我开始怀疑 Protobuf 的许多优势(也许线上传输格式除外)。再加上随着 LLM 的兴起,Monorepo(单体仓库)和其他 2010 年代的流行趋势也令人生疑。 我曾经是这些技术的忠实信徒,但我的核心假设正在迅速发生动摇。 回复 准则 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

Buf is proud to announce the first fully-featured, production-grade LSP server for Protobuf.

The Language Server Protocol is the standard API for integrating language support into your favorite IDE or text editor, such as VSCode, IntelliJ, or Neovim. An LSP server provides the smarts that power go to definition, code completion, finding references, and semantics-aware syntax highlighting.

Before today, Protobuf lacked the same LSP support other major programming languages enjoy. We don’t want to overstate our own work, but this is a game-changer for Protobuf development: Protobuf now has modern IDE support for the first time, all powered by the Buf CLI.

At Buf, we believe that Protobuf is the best schema language, thanks to its established ecosystem of libraries and tools. Protobuf shouldn’t just be the smart choice; it should be the easiest choice too. This is why we’re releasing the Buf LSP server, as part of our family of tools that complete the Protobuf ecosystem, including Protobuf-ES (used in Chromium!), Protovalidate, ConnectRPC, and the Buf Schema Registry. No matter your project or use-case, developing with Protobuf should be the easy, obvious choice.

Here’s how you can try it out!

Installing the Buf LSP

VSCode is one of the most popular graphical editors available, and it has stellar LSP support (LSP originated with VSCode). To use the Buf LSP, just install the Buf extension. This will automatically use your installed version of the Buf CLI (which bundles the LSP server), or install one if you need it.

Neovim is Buf engineers’ favorite editor, and the Buf LSP works great with it, too. All you need to do is install the Buf CLI, and configure Neovim to use it as an LSP server.

  1. Make sure you’ve installed the nvim-lspconfig repository, which provides default LSP config options. Follow the instructions here.
  2. Add lspconfig.buf_ls.setup {} to your .nvimrc .

Alternatively, you can add the following somewhere in init.lua (or another config file, if you like):

vim.lsp.config('buf-lsp', {
    cmd = { 'buf', 'lsp', 'serve' },
    filetypes = { 'proto' },
    root_markers = { 'buf.yaml', '.git' },
})

Then, you can enable it with vim.lsp.enable('buf-lsp') in your .nvimrc .

Learn more about LSP and Neovim here.

If you’re using another editor, first find out how LSP integration works, and just make sure the buf lsp serve command gets run to spawn the server.

Buf already maintains a Protobuf compiler frontend (the part that parses files and calls plugins, like protoc), which we call protocompile. Our implementation isn’t just fully-compliant, but it is much faster and more flexible than protoc. Our compiler is so good that even Google is using it alongside protoc in some parts of its massive codebase.

To build the Buf LSP, we’ve taken protocompile to the next level. We’ve developed a brand-new, query-driven frontend which enables incremental compilation and much better diagnostics. For example, unlike protoc, we correctly diagnose a duplicate repeated modifier:

error: encountered more than one type modifier
  --> testdata/parser/type/repeated.proto:23:14
   |
23 |     repeated repeated M x4 = 4;
   |     -------- ^^^^^^^^ help: consider removing this
   |     |
   |     first one is here

We designed a new AST and intermediate representation for precisely diagnosing these errors, instead of using FileDescriptorProto. Its flexibility makes it easy for us to implement new language features as they are added to Protobuf, such as upcoming features in Editions 2024. It is also memory-efficient, so it can handle workspaces that include very large Buf modules.

Our commitment

Our work on the Buf LSP is not done. We are always improving our diagnostics, and we’re planning to add more features to the LSP server, too:

  • Adding imports as an automatic fix.
  • Tighter integration with buf.yaml (such as automatically importing modules).
  • Code completion and reference lookup for custom options.
  • Automatic suggestion of field/enum numbers.
  • Dedicated Protovalidate support, including syntax highlighting for CEL snippets.

At Buf, we will always push the boundary of what you can accomplish with Protobuf, enabling schema-driven development for all!

If you want help enforcing standards on your organization’s data, contact us to see if Buf can help. If building excellent developer tooling excites you, check out our careers page!

联系我们 contact @ memedata.com