Skip to content

Commit 7709f3c

Browse files
authored
feat: add protols.toml to configure protols in a workspace (#36)
1 parent 8ffe219 commit 7709f3c

18 files changed

+569
-284
lines changed

Cargo.lock

Lines changed: 118 additions & 183 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "protols"
33
description = "Language server for proto3 files"
4-
version = "0.9.0"
4+
version = "0.10.0"
55
edition = "2021"
66
license = "MIT"
77
homepage = "https://github.com/coder3101/protols"
@@ -26,6 +26,7 @@ walkdir = "2.5.0"
2626
hard-xml = "1.36.0"
2727
tempfile = "3.12.0"
2828
serde = { version = "1.0.209", features = ["derive"] }
29+
basic-toml = "0.1.9"
2930

3031
[dev-dependencies]
3132
insta = { version = "1.39.0", features = ["yaml"] }

README.md

Lines changed: 133 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,186 @@
11
# Protols - Protobuf Language Server
22

3-
[![Crates.io](https://img.shields.io/crates/v/protols.svg)](https://crates.io/crates/protols)
3+
[![Crates.io](https://img.shields.io/crates/v/protols.svg)](https://crates.io/crates/protols)
44
[![Build and Test](https://github.com/coder3101/protols/actions/workflows/ci.yml/badge.svg)](https://github.com/coder3101/protols/actions/workflows/ci.yml)
55

6-
**Protols** is an open-source Language Server Protocol (LSP) for **proto** files, powered by the robust and efficient [tree-sitter](https://tree-sitter.github.io/tree-sitter/) parser. With Protols, you get powerful code assistance for protobuf files, including auto-completion, syntax diagnostics, and more.
6+
**Protols** is an open-source, feature-rich [Language Server Protocol (LSP)](https://microsoft.github.io/language-server-protocol/) for **Protocol Buffers (proto)** files. Powered by the efficient [tree-sitter](https://tree-sitter.github.io/tree-sitter/) parser, Protols offers intelligent code assistance for protobuf development, including features like auto-completion, diagnostics, formatting, and more.
77

8-
![](./assets/protols.mov)
8+
![Protols Demo](./assets/protols.mov)
99

1010
## ✨ Features
1111

12-
- ✅ Code Completion
13-
- ✅ Diagnostics
14-
- ✅ Document Symbols
15-
- ✅ Code Formatting
16-
- ✅ Go to Definition
17-
- ✅ Hover Information
18-
- ✅ Rename Symbols
19-
- ✅ Find references
12+
-**Code Completion**: Auto-complete messages, enums, and keywords in your `.proto` files.
13+
-**Diagnostics**: Syntax errors detected with the tree-sitter parser.
14+
-**Document Symbols**: Navigate and view all symbols, including messages and enums.
15+
-**Code Formatting**: Format `.proto` files using `clang-format` for a consistent style.
16+
-**Go to Definition**: Jump to the definition of symbols like messages or enums.
17+
-**Hover Information**: Get detailed information and documentation on hover.
18+
-**Rename Symbols**: Rename protobuf symbols and propagate changes across the codebase.
19+
-**Find References**: Find where messages, enums, and fields are used throughout the codebase.
2020

21-
## 🚀 Getting Started
21+
---
22+
23+
## Table of Contents
24+
25+
- [Installation](#installation)
26+
- [For Neovim](#for-neovim)
27+
- [For Visual Studio Code](#for-visual-studio-code)
28+
- [Configuration](#configuration)
29+
- [Basic Configuration](#basic-configuration)
30+
- [Experimental Configuration](#experimental-configuration)
31+
- [Formatter Configuration](#formatter-configuration)
32+
- [Multiple Configuration Files](#multiple-configuration-files)
33+
- [Usage](#usage)
34+
- [Code Completion](#code-completion)
35+
- [Diagnostics](#diagnostics)
36+
- [Code Formatting](#code-formatting)
37+
- [Document Symbols](#document-symbols)
38+
- [Go to Definition](#go-to-definition)
39+
- [Hover Information](#hover-information)
40+
- [Rename Symbols](#rename-symbols)
41+
- [Find References](#find-references)
42+
- [Contributing](#contributing)
43+
- [Setting Up Locally](#setting-up-locally)
44+
- [License](#license)
45+
46+
---
2247

23-
### Installation
48+
## 🚀 Installation
2449

25-
#### For Neovim
50+
### For Neovim
2651

27-
You can install [protols with mason.nvim](https://github.com/mason-org/mason-registry/blob/main/packages/protols/package.yaml) or directly from crates.io with:
52+
You can install **Protols** via [mason.nvim](https://github.com/mason-org/mason-registry/blob/main/packages/protols/package.yaml), or install it directly from [crates.io](https://crates.io/crates/protols):
2853

2954
```bash
3055
cargo install protols
3156
```
3257

33-
Then, configure it with [`nvim-lspconfig`](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#protols):
58+
Then, configure it in your `init.lua` using [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig):
3459

3560
```lua
3661
require'lspconfig'.protols.setup{}
3762
```
3863

39-
#### For Visual Studio Code
64+
### For Visual Studio Code
65+
66+
If you're using Visual Studio Code, you can install the [Protobuf Language Support](https://marketplace.visualstudio.com/items?itemName=ianandhum.protobuf-support) extension, which uses this LSP under the hood.
67+
68+
> **Note**: This extension is [open source](https://github.com/ianandhum/vscode-protobuf-support), but is not officially maintained by us.
69+
70+
---
71+
72+
## ⚙️ Configuration
73+
74+
Protols is configured using a `protols.toml` file, which you can place in any directory. **Protols** will search for the closest configuration file by recursively traversing the parent directories.
75+
76+
### Sample `protols.toml`
77+
78+
```toml
79+
[config] # Base configuration; these are considered stable and should not change
80+
include_paths = ["foobar", "bazbaaz"] # Include paths to look for protofiles during parsing
81+
disable_parse_diagnostics = true # Disable diagnostics for parsing
82+
83+
[config.experimental] # Experimental configuration; this should be considered unsafe and not fully tested
84+
use_protoc_diagnostics = true # Use diagnostics from protoc
85+
86+
[formatter] # Formatter specific configuration
87+
clang_format_path = "/usr/bin/clang-format" # clang-format binary to execute in formatting
88+
```
89+
90+
### Configuration Sections
91+
92+
#### Basic Configuration
93+
94+
The `[config]` section contains stable settings that should generally remain unchanged.
95+
96+
- `include_paths`: Directories to search for `.proto` files.
97+
- `disable_parse_diagnostics`: Set to `true` to disable diagnostics during parsing.
98+
99+
#### Experimental Configuration
100+
101+
The `[config.experimental]` section contains settings that are in development or not fully tested.
40102

41-
You can use the [Protobuf Language Support](https://marketplace.visualstudio.com/items?itemName=ianandhum.protobuf-support) extension, which leverages this LSP under the hood.
103+
- `use_protoc_diagnostics`: Enable diagnostics from the `protoc` compiler when set to `true`.
42104

43-
> **Note:** This extension is [open source](https://github.com/ianandhum/vscode-protobuf-support) but is not maintained by us.
105+
#### Formatter Configuration
106+
107+
The `[formatter]` section allows configuration for code formatting.
108+
109+
- `clang_format_path`: Specify the path to the `clang-format` binary.
110+
111+
### Multiple Configuration Files
112+
113+
You can place multiple `protols.toml` files across different directories. **Protols** will use the closest configuration file by searching up the directory tree.
114+
115+
---
44116

45117
## 🛠️ Usage
46118

119+
Protols offers a rich set of features to enhance your `.proto` file editing experience.
120+
47121
### Code Completion
48122

49-
Protols provides intelligent autocompletion for messages, enums, and proto3 keywords within the current package.
123+
**Protols** offers intelligent autocompletion for messages, enums, and proto3 keywords within the current package. Simply start typing, and Protols will suggest valid completions.
50124

51125
### Diagnostics
52126

53-
Diagnostics are powered by the tree-sitter parser, which catches syntax errors but does not utilize `protoc` for more advanced error reporting.
127+
Syntax errors are caught by the tree-sitter parser, which highlights issues directly in your editor. For more advanced error reporting, the LSP can be configured to use `protoc` diagnostics.
54128

55129
### Code Formatting
56130

57-
Formatting is enabled if [clang-format](https://clang.llvm.org/docs/ClangFormat.html) is available. You can control the [formatting style](https://clang.llvm.org/docs/ClangFormatStyleOptions.html) by placing a `.clang-format` file in the root of your workspace. Both document and range formatting are supported.
131+
Format your `.proto` files using `clang-format`. To customize the formatting style, add a `.clang-format` file to the root of your project. Both document and range formatting are supported.
58132

59133
### Document Symbols
60134

61-
Provides symbols for the entire document, including nested symbols, messages, and enums.
135+
Protols provides a list of symbols in the current document, including nested symbols such as messages and enums. This allows for easy navigation and reference.
62136

63137
### Go to Definition
64138

65-
Jump to the definition of any custom symbol, even across package boundaries.
139+
Jump directly to the definition of any custom symbol, including those in other files or packages. This feature works across package boundaries.
66140

67141
### Hover Information
68142

69-
Displays comments and documentation for protobuf symbols on hover. Works seamlessly across package boundaries.
143+
Hover over any symbol to get detailed documentation and comments associated with it. This works seamlessly across different packages and namespaces.
70144

71145
### Rename Symbols
72146

73-
Allows renaming of symbols like messages and enums, along with all their usages across packages. Currently, renaming fields within symbols is not supported directly.
147+
Rename symbols like messages or enums, and Propagate the changes throughout the codebase. Currently, field renaming within symbols is not supported.
74148

75149
### Find References
76150

77-
Allows user defined types like messages and enums can be checked for references. Nested fields are completely supported.
151+
Find all references to user-defined types like messages or enums. Nested fields are fully supported, making it easier to track symbol usage across your project.
152+
153+
---
154+
155+
## 🤝 Contributing
156+
157+
We welcome contributions from developers of all experience levels! To get started:
158+
159+
1. **Fork** the repository and clone it to your local machine.
160+
2. Create a **new branch** for your feature or fix.
161+
3. Run the tests to ensure everything works as expected.
162+
4. **Open a pull request** with a detailed description of your changes.
163+
164+
### Setting Up Locally
165+
166+
1. Clone the repository:
167+
168+
```bash
169+
git clone https://github.com/coder3101/protols.git
170+
cd protols
171+
```
172+
173+
2. Build and test the project:
174+
175+
```bash
176+
cargo build
177+
cargo test
178+
```
78179

79180
---
80181

81-
Protols is designed to supercharge your workflow with **proto** files. We welcome contributions and feedback from the community! Feel free to check out the [repository](https://github.com/coder3101/protols) and join in on improving this tool! 🎉
182+
## 📄 License
183+
184+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
185+
186+
---

src/config/input/protols-valid.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[config]
2+
include_paths = ["foobar", "bazbaaz"]
3+
disable_parse_diagnostics = true
4+
5+
[config.experimental]
6+
use_protoc_diagnostics = true
7+
8+
[formatter]
9+
clang_format_path = "/usr/bin/clang-format"

src/config/mod.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
pub mod workspace;
4+
5+
fn default_clang_format_path() -> String {
6+
"clang-format".to_string()
7+
}
8+
9+
#[derive(Serialize, Deserialize, Debug, Clone)]
10+
#[serde(default)]
11+
pub struct ProtolsConfig {
12+
pub config: Config,
13+
pub formatter: FormatterConfig,
14+
}
15+
16+
#[derive(Serialize, Deserialize, Debug, Clone)]
17+
pub struct FormatterConfig {
18+
#[serde(default = "default_clang_format_path")]
19+
pub clang_format_path: String,
20+
}
21+
22+
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
23+
#[serde(default)]
24+
pub struct Config {
25+
pub include_paths: Vec<String>,
26+
pub single_file_mode: bool,
27+
pub disable_parse_diagnostics: bool,
28+
pub experimental: ExperimentalConfig,
29+
}
30+
31+
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
32+
#[serde(default)]
33+
pub struct ExperimentalConfig {
34+
pub use_protoc_diagnostics: bool,
35+
}
36+
37+
impl Default for ProtolsConfig {
38+
fn default() -> Self {
39+
Self {
40+
config: Config::default(),
41+
formatter: FormatterConfig::default(),
42+
}
43+
}
44+
}
45+
46+
impl Default for FormatterConfig {
47+
fn default() -> Self {
48+
Self {
49+
clang_format_path: default_clang_format_path(),
50+
}
51+
}
52+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: src/config/workspace.rs
3+
expression: ws.get_config_for_uri(&inworkspace2).unwrap()
4+
---
5+
config:
6+
include_paths: []
7+
single_file_mode: false
8+
disable_parse_diagnostics: false
9+
experimental:
10+
use_protoc_diagnostics: false
11+
formatter:
12+
clang_format_path: clang-format
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: src/config/workspace.rs
3+
expression: ws.get_config_for_uri(&inworkspace).unwrap()
4+
---
5+
config:
6+
include_paths:
7+
- foobar
8+
- bazbaaz
9+
single_file_mode: false
10+
disable_parse_diagnostics: true
11+
experimental:
12+
use_protoc_diagnostics: true
13+
formatter:
14+
clang_format_path: /usr/bin/clang-format
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: src/config/workspace.rs
3+
expression: ws.get_config_for_uri(&inworkspace)
4+
---
5+
config:
6+
include_paths:
7+
- foobar
8+
- bazbaaz
9+
single_file_mode: false
10+
disable_parse_diagnostics: true
11+
experimental:
12+
use_protoc_diagnostics: true
13+
formatter:
14+
clang_format_path: /usr/bin/clang-format

0 commit comments

Comments
 (0)