Language Server for protocol buffers
Protols is an open-source, feature-rich Language Server Protocol (LSP) for Protocol Buffers (proto) files. Powered by the efficient tree-sitter parser, Protols offers intelligent code assistance for protobuf development, including features like auto-completion, diagnostics, formatting, and more.
.proto files.protoc..proto files using clang-format for a consistent style.You can install Protols via mason.nvim, or install it directly from crates.io:
cargo install protolsThen, configure it in your init.lua using nvim-lspconfig:
require'lspconfig'.protols.setup{}For dynamic configuration of include paths, you can use the before_init callback to set them via initializationParams:
require'lspconfig'.protols.setup{
before_init = function(_, config)
config.init_options = {
include_paths = {
"/usr/local/include/protobuf",
"vendor/protos",
"../shared-protos"
}
}
end
}Protols supports various command line options to customize its behavior:
…You can provide include paths using a comma-separated list or by repeating the flag:
protols --include-paths=/path/to/protos,/another/path/to/protos
# or
protols -i /path/to/protos -i /another/path/to/protosTCP transport is useful when the language server and the IDE run in different environments.
protols --port 7301protols --socket 0.0.0.0:7301protols --socket 192.168.1.10:7301On Linux or macOS, you can use a socket file for communication:
protols --pipe /tmp/protols.sockOn Windows, you can specify a pipe name. protols handles the \\.\pipe\ prefix automatically:
protols --pipe protols-pipeIf you're using Visual Studio Code, you can install the Protobuf Language Support extension, which uses this LSP under the hood.
Note: This extension is open source, but is not officially maintained by us.
Protols can be configured using a protols.toml file, which you can place in root of your project directory.
protols.toml[config]
include_paths = ["foobar", "bazbaaz"] # Include paths to look for protofiles during parsing
[config.path]
clang_format = "clang-format"
protoc = "protoc"
[config.rename]
chain_rpc_request_response = false # Also rename Request/Response messages when renaming an rpcThe [config] section contains stable settings that should generally remain unchanged.
include_paths: These are directories where .proto files are searched. Paths can be absolute or relative to the LSP workspace root, which is already included in the include_paths. You can also specify include paths using:
protols.toml--include-paths flag that apply to all workspacesinitializationParams (useful for editors like Neovim)When a file is not found in any of the paths above, the following directories are searched:
pkg-config (requires pkg-config present in environment and capable of finding the installation of protobuf)All include paths from these sources are combined when resolving proto imports.
The [config.path] section contains path for various tools used by LSP.
clang_format: Uses clang_format from this path for formattingprotoc: Uses protoc from this path for diagnosticsThe [config.rename] section tunes rename behaviour.
chain_rpc_request_response (default false): when enabled, renaming an rpc
also renames its convention-named Request and Response messages —
and renaming such a message renames the rpc and its sibling message. The chain
only fires when the names follow the Google API design guide
convention and the messages are used by exactly one rpc.For detailed usage instructions, see the Usage Guide.
Protols does not ship with the Protocol Buffers Well-Known Types unless configured to do so by a distribution.
In order for features above to work for the well-known types, the well-known imports must either resolve against one of the configured import paths or the environment must contain in PATH a pkg-config executable capable of resolving the package protobuf.
You can verify this by running
pkg-config --modversion protobufin protols' environment.
Distributions may set an absolute include path which contains the Protocol Buffers Well-Known Types,
for example pointing to the files provided by the protobuf package, by compiling protols with the
environment variable FALLBACK_INCLUDE_PATH set to the desired path. This path will be used by the
compiled executable for resolution of any proto files that could not be resolved otherwise.
We welcome contributions from developers of all experience levels! To get started:
The project includes a pre-configured Dev Container, which sets up Rust, Neovim, and all dependencies automatically.
Prerequisites:
Steps:
F1 -> Dev Containers: Reopen in Container).[!TIP] A pre-configured Neovim is included in the container for instant LSP testing.
Clone the repository:
git clone https://github.com/coder3101/protols.git
cd protolsBuild and test the project:
cargo build
cargo testIf you want to contribute or debug the server logic, please refer to the Debugging Guide for instructions on setting up a TCP-based debug session with VS Code and Neovim.
This project is licensed under the MIT License. See the LICENSE file for more details.
No open issues yet, or sync has not completed.