Skip to content

Commit f09819a

Browse files
breaking: refactor config to be simpler (#64)
closes #63
1 parent 8952a69 commit f09819a

13 files changed

+50
-95
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 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.10.0"
4+
version = "0.2.0"
55
edition = "2024"
66
license = "MIT"
77
homepage = "https://github.com/coder3101/protols"

README.md

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
[![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-
**WARNING** : Master branch is undergoing a massive refactoring, please use last relesed tag instead.
7-
86
**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.
97

10-
![Protols Demo](./assets/protols.mov)
11-
128
## ✨ Features
139

1410
-**Code Completion**: Auto-complete messages, enums, and keywords in your `.proto` files.
15-
-**Diagnostics**: Syntax errors and import error detected with the tree-sitter parser.
11+
-**Diagnostics**: Syntax errors, import error detected with the tree-sitter and advanced diagnostics from `protoc` parser.
1612
-**Document Symbols**: Navigate and view all symbols, including messages and enums.
1713
-**Code Formatting**: Format `.proto` files using `clang-format` for a consistent style.
1814
-**Go to Definition**: Jump to the definition of symbols like messages or enums and imports.
@@ -29,9 +25,7 @@
2925
- [For Visual Studio Code](#for-visual-studio-code)
3026
- [Configuration](#configuration)
3127
- [Basic Configuration](#basic-configuration)
32-
- [Experimental Configuration](#experimental-configuration)
33-
- [Formatter Configuration](#formatter-configuration)
34-
- [Multiple Configuration Files](#multiple-configuration-files)
28+
- [Path Configuration](#path-configuration)
3529
- [Usage](#usage)
3630
- [Code Completion](#code-completion)
3731
- [Diagnostics](#diagnostics)
@@ -78,16 +72,12 @@ Protols is configured using a `protols.toml` file, which you can place in any di
7872
### Sample `protols.toml`
7973

8074
```toml
81-
[config] # Base configuration; these are considered stable and should not change
75+
[config]
8276
include_paths = ["foobar", "bazbaaz"] # Include paths to look for protofiles during parsing
83-
disable_parse_diagnostics = true # Disable diagnostics for parsing
84-
85-
[config.experimental] # experimental configuration; this should be considered unsafe and not fully tested
86-
use_protoc_diagnostics = true # use diagnostics from protoc
87-
protoc_path = "protoc" # Path to proto compiler (protoc)
8877

89-
[formatter] # Formatter specific configuration
90-
clang_format_path = "/usr/bin/clang-format" # clang-format binary to execute in formatting
78+
[config.path]
79+
clang_format = "clang-format"
80+
protoc = "protoc"
9181
```
9282

9383
### Configuration Sections
@@ -96,21 +86,14 @@ clang_format_path = "/usr/bin/clang-format" # clang-format binary to execute in
9686

9787
The `[config]` section contains stable settings that should generally remain unchanged.
9888

99-
- `include_paths`: Directories to search for `.proto` files. Absolute or relative to LSP workspace root.
100-
- `disable_parse_diagnostics`: Set to `true` to disable tree-sitter parse diagnostics during parsing.
101-
102-
#### Experimental Configuration
103-
104-
The `[config.experimental]` section contains settings that are in development or not fully tested.
105-
106-
- `use_protoc_diagnostics`: Enable diagnostics from the `protoc` compiler when set to `true`.
107-
- `protoc_path`: Uses protoc from this path for diagnostics
89+
- `include_paths`: Directories to search for `.proto` files. Absolute or relative to LSP workspace root. Worspace root is already included in include_paths
10890

109-
#### Formatter Configuration
91+
#### Path Configuration
11092

111-
The `[formatter]` section allows configuration for code formatting.
93+
The `[config.path]` section contains path for various tools used by LSP.
11294

113-
- `clang_format_path`: Specify the path to the `clang-format` binary.
95+
- `clang_format`: Uses clang_format from this path for formatting
96+
- `protoc`: Uses protoc from this path for diagnostics
11497

11598
---
11699

@@ -124,7 +107,7 @@ Protols offers a rich set of features to enhance your `.proto` file editing expe
124107

125108
### Diagnostics
126109

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.
110+
Syntax errors are caught by the tree-sitter parser, which highlights issues directly in your editor. More advanced error reporting, is done by `protoc` which runs after a file saved. You must have `protoc` installed and added to your path or you can specify its path in the configuration above
128111

129112
### Code Formatting
130113

src/config/input/protols-valid.toml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
[config]
22
include_paths = ["foobar", "bazbaaz"]
3-
disable_parse_diagnostics = true
43

5-
[config.experimental]
6-
use_protoc_diagnostics = true
7-
8-
[formatter]
9-
clang_format_path = "/usr/bin/clang-format"
4+
[config.path]
5+
protoc = "/usr/bin/protoc"
6+
clang_format = "/usr/bin/clang-format"

src/config/mod.rs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,31 @@ fn default_protoc_path() -> String {
1414
#[serde(default)]
1515
pub struct ProtolsConfig {
1616
pub config: Config,
17-
pub formatter: FormatterConfig,
1817
}
1918

2019
#[derive(Serialize, Deserialize, Debug, Clone)]
2120
pub struct FormatterConfig {
22-
#[serde(default = "default_clang_format_path")]
23-
pub clang_format_path: String,
2421
}
2522

2623
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
2724
#[serde(default)]
2825
pub struct Config {
2926
pub include_paths: Vec<String>,
30-
pub single_file_mode: bool,
31-
pub disable_parse_diagnostics: bool,
32-
pub experimental: ExperimentalConfig,
27+
pub path: PathConfig,
3328
}
3429

3530
#[derive(Serialize, Deserialize, Debug, Clone)]
3631
#[serde(default)]
37-
pub struct ExperimentalConfig {
38-
pub use_protoc_diagnostics: bool,
39-
pub protoc_path: String,
32+
pub struct PathConfig {
33+
pub clang_format: String,
34+
pub protoc: String,
4035
}
4136

42-
impl Default for FormatterConfig {
37+
impl Default for PathConfig {
4338
fn default() -> Self {
4439
Self {
45-
clang_format_path: default_clang_format_path(),
46-
}
47-
}
48-
}
49-
50-
impl Default for ExperimentalConfig {
51-
fn default() -> Self {
52-
Self {
53-
protoc_path: default_protoc_path(),
54-
use_protoc_diagnostics: false,
40+
clang_format: default_clang_format_path(),
41+
protoc: default_protoc_path()
5542
}
5643
}
5744
}

src/config/snapshots/protols__config__workspace__test__get_for_workspace-2.snap

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ expression: ws.get_config_for_uri(&inworkspace2).unwrap()
44
---
55
config:
66
include_paths: []
7-
single_file_mode: false
8-
disable_parse_diagnostics: false
9-
experimental:
10-
use_protoc_diagnostics: false
11-
protoc_path: protoc
12-
formatter:
13-
clang_format_path: clang-format
7+
path:
8+
clang_format: clang-format
9+
protoc: protoc

src/config/snapshots/protols__config__workspace__test__get_for_workspace.snap

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ config:
66
include_paths:
77
- foobar
88
- bazbaaz
9-
single_file_mode: false
10-
disable_parse_diagnostics: true
11-
experimental:
12-
use_protoc_diagnostics: true
13-
protoc_path: protoc
14-
formatter:
15-
clang_format_path: /usr/bin/clang-format
9+
path:
10+
clang_format: /usr/bin/clang-format
11+
protoc: /usr/bin/protoc

src/config/workspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl WorkspaceProtoConfigs {
5757

5858
let wr: ProtolsConfig = basic_toml::from_str(&content).unwrap_or_default();
5959
let fmt = ClangFormatter::new(
60-
&wr.formatter.clang_format_path,
60+
&wr.config.path.clang_format,
6161
wpath.to_str().expect("non-utf8 path"),
6262
);
6363

src/lsp.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ impl LanguageServer for ProtoLanguageServer {
406406

407407
if let Some(diagnostics) = self
408408
.state
409-
.upsert_file(&uri, content, &ipath, 8, &pconf.config)
409+
.upsert_file(&uri, content, &ipath, 8, &pconf.config, true)
410410
{
411411
if let Err(e) = self.client.publish_diagnostics(diagnostics) {
412412
error!(error=%e, "failed to publish diagnostics")
@@ -433,7 +433,7 @@ impl LanguageServer for ProtoLanguageServer {
433433

434434
if let Some(diagnostics) = self
435435
.state
436-
.upsert_file(&uri, content, &ipath, 8, &pconf.config)
436+
.upsert_file(&uri, content, &ipath, 8, &pconf.config, true)
437437
{
438438
if let Err(e) = self.client.publish_diagnostics(diagnostics) {
439439
error!(error=%e, "failed to publish diagnostics")
@@ -454,10 +454,7 @@ impl LanguageServer for ProtoLanguageServer {
454454
return ControlFlow::Continue(());
455455
};
456456

457-
// override config to disable protoc diagnostics during change
458-
let mut pconf = pconf.config.clone();
459-
pconf.experimental.use_protoc_diagnostics = false;
460-
if let Some(diagnostics) = self.state.upsert_file(&uri, content, &ipath, 8, &pconf) {
457+
if let Some(diagnostics) = self.state.upsert_file(&uri, content, &ipath, 8, &pconf.config, false) {
461458
if let Err(e) = self.client.publish_diagnostics(diagnostics) {
462459
error!(error=%e, "failed to publish diagnostics")
463460
}

src/state.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,21 @@ impl ProtoLanguageState {
223223
ipath: &[PathBuf],
224224
depth: usize,
225225
config: &Config,
226+
protoc_diagnostics: bool,
226227
) -> Option<PublishDiagnosticsParams> {
227228
info!(%uri, %depth, "upserting file");
228229
let diag = self.upsert_content(uri, content.clone(), ipath, depth);
229230
self.get_tree(uri).map(|tree| {
230231
let mut d = vec![];
231-
if !config.disable_parse_diagnostics {
232-
d.extend(tree.collect_parse_diagnostics());
233-
}
232+
d.extend(tree.collect_parse_diagnostics());
234233
d.extend(tree.collect_import_diagnostics(content.as_ref(), diag));
235234

236235
// Add protoc diagnostics if enabled
237-
if config.experimental.use_protoc_diagnostics {
236+
if protoc_diagnostics {
238237
if let Ok(protoc_diagnostics) = self.protoc_diagnostics.lock() {
239238
if let Ok(file_path) = uri.to_file_path() {
240239
let protoc_diags = protoc_diagnostics.collect_diagnostics(
241-
&config.experimental.protoc_path,
240+
&config.path.protoc,
242241
file_path.to_str().unwrap_or_default(),
243242
&ipath
244243
.iter()

src/workspace/definition.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ mod test {
6666
let c = include_str!("input/c.proto");
6767

6868
let mut state: ProtoLanguageState = ProtoLanguageState::new();
69-
state.upsert_file(&a_uri, a.to_owned(), &ipath, 2, &Config::default());
70-
state.upsert_file(&b_uri, b.to_owned(), &ipath, 2, &Config::default());
71-
state.upsert_file(&c_uri, c.to_owned(), &ipath, 2, &Config::default());
69+
state.upsert_file(&a_uri, a.to_owned(), &ipath, 2, &Config::default(), false);
70+
state.upsert_file(&b_uri, b.to_owned(), &ipath, 2, &Config::default(), false);
71+
state.upsert_file(&c_uri, c.to_owned(), &ipath, 2, &Config::default(), false);
7272

7373
assert_yaml_snapshot!(state.definition(
7474
&ipath,

src/workspace/hover.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,9 +679,9 @@ mod test {
679679
let c = include_str!("input/c.proto");
680680

681681
let mut state: ProtoLanguageState = ProtoLanguageState::new();
682-
state.upsert_file(&a_uri, a.to_owned(), &ipath, 3, &Config::default());
683-
state.upsert_file(&b_uri, b.to_owned(), &ipath, 2, &Config::default());
684-
state.upsert_file(&c_uri, c.to_owned(), &ipath, 2, &Config::default());
682+
state.upsert_file(&a_uri, a.to_owned(), &ipath, 3, &Config::default(), false);
683+
state.upsert_file(&b_uri, b.to_owned(), &ipath, 2, &Config::default(), false);
684+
state.upsert_file(&c_uri, c.to_owned(), &ipath, 2, &Config::default(), false);
685685

686686
assert_yaml_snapshot!(state.hover(
687687
&ipath,

src/workspace/rename.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ mod test {
8585
let c = include_str!("input/c.proto");
8686

8787
let mut state: ProtoLanguageState = ProtoLanguageState::new();
88-
state.upsert_file(&a_uri, a.to_owned(), &ipath, 2, &Config::default());
89-
state.upsert_file(&b_uri, b.to_owned(), &ipath, 2, &Config::default());
90-
state.upsert_file(&c_uri, c.to_owned(), &ipath, 2, &Config::default());
88+
state.upsert_file(&a_uri, a.to_owned(), &ipath, 2, &Config::default(), false);
89+
state.upsert_file(&b_uri, b.to_owned(), &ipath, 2, &Config::default(), false);
90+
state.upsert_file(&c_uri, c.to_owned(), &ipath, 2, &Config::default(), false);
9191

9292
assert_yaml_snapshot!(state.rename_fields(
9393
"com.workspace",
@@ -124,9 +124,9 @@ mod test {
124124
let c = include_str!("input/c.proto");
125125

126126
let mut state: ProtoLanguageState = ProtoLanguageState::new();
127-
state.upsert_file(&a_uri, a.to_owned(), &ipath, 2, &Config::default());
128-
state.upsert_file(&b_uri, b.to_owned(), &ipath, 2, &Config::default());
129-
state.upsert_file(&c_uri, c.to_owned(), &ipath, 2, &Config::default());
127+
state.upsert_file(&a_uri, a.to_owned(), &ipath, 2, &Config::default(), false);
128+
state.upsert_file(&b_uri, b.to_owned(), &ipath, 2, &Config::default(), false);
129+
state.upsert_file(&c_uri, c.to_owned(), &ipath, 2, &Config::default(), false);
130130

131131
assert_yaml_snapshot!(state.reference_fields(
132132
"com.workspace",

0 commit comments

Comments
 (0)