A high-performance Protocol Buffers language server implemented in Rust with complete LSP support.
This project is developed and maintained by CodeBuddy Code, an enterprise-grade AI programming assistant. Most of the code is automatically generated and maintained by CodeBuddy Code.
For more information about CodeBuddy Code, visit: https://copilot.tencent.com/cli/
- Code Completion - Support for protobuf keywords, built-in types, messages, enums, and services
- Go to Definition - Cross-file navigation with intelligent import resolution
- Hover Information - Display detailed information for messages, enums, and services
- Document Symbols - Hierarchical display of file structure with support for nested types
- Code Formatting - Integrated clang-format support with custom configuration
- Diagnostics - Real-time syntax and semantic checking with automatic error refresh
- Smart Import Resolution - Intelligent import resolution with additional directory support
- Additional Proto Directories - Configure additional directories to search for proto files with highest priority
- Async File Loading - Dynamic loading of uncached import files
- Cross-package Type Resolution - Support for package-qualified type names (e.g.,
package.Type) - RPC Method Support - Complete parsing of service and method definitions
git clone https://github.com/lasorda/protobuf-lsp.git
cd protobuf-lsp
cargo build --releaseAfter running cargo build --release, the executable will be located at target/release/protobuf-lsp.
Add to your settings.json:
{
"protobuf-langserver.trace.server": "messages",
"protobuf-langserver.executable": {
"command": "/path/to/protobuf-lsp/target/release/protobuf-lsp",
"args": []
}
}Using nvim-lspconfig:
require'lspconfig'.protobuf_lsp.setup{
cmd = {"/path/to/protobuf-lsp/target/release/protobuf-lsp"},
}Add to ~/.config/helix/languages.toml:
[[language]]
name = "proto"
language-servers = ["protobuf-lsp"]
[language-server.protobuf-lsp]
command = "/path/to/protobuf-lsp/target/release/protobuf-lsp"Supports completion for:
- Protobuf keywords (
syntax,message,enum,service,rpc,import,package) - Scalar types (
string,int32,int64,bool,double,bytes, etc.) - Defined messages, enums, and services
- Types from imported files
- Package-qualified types (type
package.to see all types in that package)
- Place cursor on a type name and use
F12orCtrl+Clickto jump - Supports cross-file navigation
- Automatically resolves import paths with upward search
The language server intelligently searches for imported files:
- Additional proto directories (highest priority, if configured)
- Relative to the current file's directory
- Walking up parent directories
You can configure additional directories to search for proto files. These directories have the highest priority when resolving imports.
VS Code configuration:
{
"protobuf-langserver.trace.server": "messages",
"protobuf-langserver.executable": {
"command": "/path/to/protobuf-lsp/target/release/protobuf-lsp",
"args": []
},
"protobuf-langserver.additionalProtoDirs": [
"/path/to/shared/proto/files",
"/path/to/external/api/proto"
]
}Neovim configuration:
require'lspconfig'.protobuf_lsp.setup{
cmd = {"/path/to/protobuf-lsp/target/release/protobuf-lsp"},
settings = {
additionalProtoDirs = {
"/path/to/shared/proto/files",
"/path/to/external/api/proto"
}
}
}Helix Editor configuration:
[language-server.protobuf-lsp]
command = "/path/to/protobuf-lsp/target/release/protobuf-lsp"
[language-server.protobuf-lsp.settings]
additionalProtoDirs = [
"/path/to/shared/proto/files",
"/path/to/external/api/proto"
]Example directory structure:
project/
βββ common/
β βββ types.proto
βββ api/
βββ service.proto
external-protos/
βββ google/
βββ protobuf/
βββ empty.proto
In service.proto:
import "common/types.proto"; // Found from relative path
import "google/protobuf/empty.proto"; // Found from additional-proto-dirsSupports formatting with clang-format:
- Create a
.clang-formatfile in your project root or any parent directory - The language server will automatically find and apply the configuration
Example .clang-format:
---
Language: Proto
BasedOnStyle: Google
ColumnLimit: 100
IndentWidth: 2
UseTab: NeverReal-time checking for:
- Syntax errors
- Duplicate message/enum/service names
- Duplicate field numbers
- Missing syntax declaration
Errors automatically refresh after file modifications.
src/
βββ main.rs # Program entry point
βββ server.rs # LSP server implementation
βββ parser/ # Protobuf parser
β βββ mod.rs # Module exports
β βββ proto.rs # Parser implementation
βββ features/ # LSP feature implementations
β βββ completion.rs # Code completion
β βββ definition.rs # Go to definition
β βββ hover.rs # Hover information
β βββ symbols.rs # Document symbols
β βββ formatting.rs # Code formatting
β βββ diagnostics.rs # Error diagnostics
βββ workspace/ # Workspace management
βββ mod.rs
βββ manager.rs # File cache management
- tower-lsp - Mature LSP framework
- tokio - Async runtime
- protobuf-parse - Pure Rust protobuf parser
- dashmap - Lock-free concurrent HashMap
- parking_lot - High-performance locks
- tracing - Structured logging
Compared to the Go version:
- Zero-cost abstractions - Rust's zero-overhead features
- Memory safety - No data races, no GC needed
- Concurrency safety - Compile-time concurrency checks
- Type safety - Stronger type system guarantees
Ensure clang-format is installed:
# Ubuntu/Debian
sudo apt install clang-format
# macOS
brew install clang-format
# Windows
# Download LLVM and add to PATH- Check if file paths are correct
- Ensure files exist
- The language server automatically searches upward, no additional path configuration needed
Issues and Pull Requests are welcome!
MIT License