Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add protols.toml to configure protols in a workspace #36

Merged
merged 7 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
301 changes: 118 additions & 183 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "protols"
description = "Language server for proto3 files"
version = "0.9.0"
version = "0.10.0"
edition = "2021"
license = "MIT"
homepage = "https://github.com/coder3101/protols"
Expand All @@ -26,6 +26,7 @@ walkdir = "2.5.0"
hard-xml = "1.36.0"
tempfile = "3.12.0"
serde = { version = "1.0.209", features = ["derive"] }
basic-toml = "0.1.9"

[dev-dependencies]
insta = { version = "1.39.0", features = ["yaml"] }
161 changes: 133 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,186 @@
# Protols - Protobuf Language Server

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

**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.
**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.

![](./assets/protols.mov)
![Protols Demo](./assets/protols.mov)

## ✨ Features

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

## 🚀 Getting Started
---

## Table of Contents

- [Installation](#installation)
- [For Neovim](#for-neovim)
- [For Visual Studio Code](#for-visual-studio-code)
- [Configuration](#configuration)
- [Basic Configuration](#basic-configuration)
- [Experimental Configuration](#experimental-configuration)
- [Formatter Configuration](#formatter-configuration)
- [Multiple Configuration Files](#multiple-configuration-files)
- [Usage](#usage)
- [Code Completion](#code-completion)
- [Diagnostics](#diagnostics)
- [Code Formatting](#code-formatting)
- [Document Symbols](#document-symbols)
- [Go to Definition](#go-to-definition)
- [Hover Information](#hover-information)
- [Rename Symbols](#rename-symbols)
- [Find References](#find-references)
- [Contributing](#contributing)
- [Setting Up Locally](#setting-up-locally)
- [License](#license)

---

### Installation
## 🚀 Installation

#### For Neovim
### For Neovim

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:
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):

```bash
cargo install protols
```

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

```lua
require'lspconfig'.protols.setup{}
```

#### For Visual Studio Code
### For Visual Studio Code

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.

> **Note**: This extension is [open source](https://github.com/ianandhum/vscode-protobuf-support), but is not officially maintained by us.

---

## ⚙️ Configuration

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.

### Sample `protols.toml`

```toml
[config] # Base configuration; these are considered stable and should not change
include_paths = ["foobar", "bazbaaz"] # Include paths to look for protofiles during parsing
disable_parse_diagnostics = true # Disable diagnostics for parsing

[config.experimental] # Experimental configuration; this should be considered unsafe and not fully tested
use_protoc_diagnostics = true # Use diagnostics from protoc

[formatter] # Formatter specific configuration
clang_format_path = "/usr/bin/clang-format" # clang-format binary to execute in formatting
```

### Configuration Sections

#### Basic Configuration

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

- `include_paths`: Directories to search for `.proto` files.
- `disable_parse_diagnostics`: Set to `true` to disable diagnostics during parsing.

#### Experimental Configuration

The `[config.experimental]` section contains settings that are in development or not fully tested.

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

> **Note:** This extension is [open source](https://github.com/ianandhum/vscode-protobuf-support) but is not maintained by us.
#### Formatter Configuration

The `[formatter]` section allows configuration for code formatting.

- `clang_format_path`: Specify the path to the `clang-format` binary.

### Multiple Configuration Files

You can place multiple `protols.toml` files across different directories. **Protols** will use the closest configuration file by searching up the directory tree.

---

## 🛠️ Usage

Protols offers a rich set of features to enhance your `.proto` file editing experience.

### Code Completion

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

### Diagnostics

Diagnostics are powered by the tree-sitter parser, which catches syntax errors but does not utilize `protoc` for more advanced error reporting.
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.

### Code Formatting

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.
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.

### Document Symbols

Provides symbols for the entire document, including nested symbols, messages, and enums.
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.

### Go to Definition

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

### Hover Information

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

### Rename Symbols

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

### Find References

Allows user defined types like messages and enums can be checked for references. Nested fields are completely supported.
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.

---

## 🤝 Contributing

We welcome contributions from developers of all experience levels! To get started:

1. **Fork** the repository and clone it to your local machine.
2. Create a **new branch** for your feature or fix.
3. Run the tests to ensure everything works as expected.
4. **Open a pull request** with a detailed description of your changes.

### Setting Up Locally

1. Clone the repository:

```bash
git clone https://github.com/coder3101/protols.git
cd protols
```

2. Build and test the project:

```bash
cargo build
cargo test
```

---

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! 🎉
## 📄 License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.

---
9 changes: 9 additions & 0 deletions src/config/input/protols-valid.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[config]
include_paths = ["foobar", "bazbaaz"]
disable_parse_diagnostics = true

[config.experimental]
use_protoc_diagnostics = true

[formatter]
clang_format_path = "/usr/bin/clang-format"
52 changes: 52 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use serde::{Deserialize, Serialize};

pub mod workspace;

fn default_clang_format_path() -> String {
"clang-format".to_string()
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(default)]
pub struct ProtolsConfig {
pub config: Config,
pub formatter: FormatterConfig,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct FormatterConfig {
#[serde(default = "default_clang_format_path")]
pub clang_format_path: String,
}

#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[serde(default)]
pub struct Config {
pub include_paths: Vec<String>,
pub single_file_mode: bool,
pub disable_parse_diagnostics: bool,
pub experimental: ExperimentalConfig,
}

#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[serde(default)]
pub struct ExperimentalConfig {
pub use_protoc_diagnostics: bool,
}

impl Default for ProtolsConfig {
fn default() -> Self {
Self {
config: Config::default(),
formatter: FormatterConfig::default(),
}
}
}

impl Default for FormatterConfig {
fn default() -> Self {
Self {
clang_format_path: default_clang_format_path(),
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: src/config/workspace.rs
expression: ws.get_config_for_uri(&inworkspace2).unwrap()
---
config:
include_paths: []
single_file_mode: false
disable_parse_diagnostics: false
experimental:
use_protoc_diagnostics: false
formatter:
clang_format_path: clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: src/config/workspace.rs
expression: ws.get_config_for_uri(&inworkspace).unwrap()
---
config:
include_paths:
- foobar
- bazbaaz
single_file_mode: false
disable_parse_diagnostics: true
experimental:
use_protoc_diagnostics: true
formatter:
clang_format_path: /usr/bin/clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: src/config/workspace.rs
expression: ws.get_config_for_uri(&inworkspace)
---
config:
include_paths:
- foobar
- bazbaaz
single_file_mode: false
disable_parse_diagnostics: true
experimental:
use_protoc_diagnostics: true
formatter:
clang_format_path: /usr/bin/clang-format
Loading
Loading