Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
coder3101 committed Jan 11, 2025
1 parent 0de56c4 commit 6885a08
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 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 Down
14 changes: 11 additions & 3 deletions src/formatter/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl ClangFormatter {
Self {
temp_dir: tempdir().expect("faile to creat temp dir"),
path: cmd.to_owned(),
working_dir: wdir.to_owned()
working_dir: wdir.to_owned(),
}
}

Expand All @@ -85,7 +85,10 @@ impl ClangFormatter {
let mut c = Command::new(self.path.as_str());
c.current_dir(self.working_dir.as_str());
c.stdin(File::open(u).ok()?);
c.args(["--output-replacements-xml", format!("--assume-filename={f}").as_str()]);
c.args([
"--output-replacements-xml",
format!("--assume-filename={f}").as_str(),
]);
Some(c)
}

Expand Down Expand Up @@ -116,7 +119,12 @@ impl ProtoFormatter for ClangFormatter {
self.output_to_textedit(&String::from_utf8_lossy(&output.stdout), content)
}

fn format_document_range(&self, r: &Range, filename: &str, content: &str) -> Option<Vec<TextEdit>> {
fn format_document_range(
&self,
r: &Range,
filename: &str,
content: &str,
) -> Option<Vec<TextEdit>> {
let p = self.get_temp_file_path(content)?;
let start = r.start.line + 1;
let end = r.end.line + 1;
Expand Down
7 changes: 6 additions & 1 deletion src/formatter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ pub mod clang;

pub trait ProtoFormatter: Sized {
fn format_document(&self, filename: &str, content: &str) -> Option<Vec<TextEdit>>;
fn format_document_range(&self, r: &Range, filename: &str, content: &str) -> Option<Vec<TextEdit>>;
fn format_document_range(
&self,
r: &Range,
filename: &str,
content: &str,
) -> Option<Vec<TextEdit>>;
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use server::{ProtoLanguageServer, TickEvent};
use tower::ServiceBuilder;
use tracing::Level;

mod config;
mod formatter;
mod lsp;
mod nodekind;
Expand All @@ -17,7 +18,6 @@ mod server;
mod state;
mod utils;
mod workspace;
mod config;

#[tokio::main(flavor = "current_thread")]
async fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/workspace/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ mod test {
let b = include_str!("input/b.proto");
let c = include_str!("input/c.proto");

let mut state: ProtoLanguageState<ClangFormatter> = ProtoLanguageState::new();
let mut state: ProtoLanguageState = ProtoLanguageState::new();
state.upsert_file(&a_uri, a.to_owned());
state.upsert_file(&b_uri, b.to_owned());
state.upsert_file(&c_uri, c.to_owned());
Expand Down

0 comments on commit 6885a08

Please sign in to comment.