From 0449fef97f2a66b96a43ac251e046161fa118206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Thu, 17 Oct 2024 20:23:46 +0200 Subject: [PATCH] fix: decode uri (#15) * fix: decode uri closes https://github.com/xhyrom/zed-discord-presence/issues/14 * refactor: remove --- Cargo.lock | 7 +++++++ lsp/Cargo.toml | 1 + lsp/src/main.rs | 7 +++++-- lsp/src/util.rs | 4 ++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 968247c..b8a57b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -133,6 +133,7 @@ dependencies = [ "serde_json", "tokio", "tower-lsp", + "urlencoding", ] [[package]] @@ -851,6 +852,12 @@ dependencies = [ "serde", ] +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + [[package]] name = "uuid" version = "0.8.2" diff --git a/lsp/Cargo.toml b/lsp/Cargo.toml index 13a4113..e252e31 100644 --- a/lsp/Cargo.toml +++ b/lsp/Cargo.toml @@ -11,3 +11,4 @@ git2 = { version = "0.19.0", default-features = false } serde_json = { version = "1.0.122", features = ["std"] } lazy_static = "1.5.0" regex = { version = "1.10.6", default-features = false, features = ["std", "perf", "unicode-case"] } +urlencoding = "2.1.3" diff --git a/lsp/src/main.rs b/lsp/src/main.rs index 71c6ade..1a58135 100644 --- a/lsp/src/main.rs +++ b/lsp/src/main.rs @@ -62,8 +62,11 @@ impl Document { } } - fn get_filename(&self) -> &str { - self.path.file_name().unwrap().to_str().unwrap() + fn get_filename(&self) -> String { + let filename = self.path.file_name().unwrap().to_str().unwrap(); + let filename = urlencoding::decode(filename).unwrap(); + + filename.to_string() } fn get_extension(&self) -> &str { diff --git a/lsp/src/util.rs b/lsp/src/util.rs index e69ad90..4da6473 100644 --- a/lsp/src/util.rs +++ b/lsp/src/util.rs @@ -13,7 +13,7 @@ macro_rules! replace_with_capitalization { } pub struct Placeholders<'a> { - filename: &'a str, + filename: String, workspace: &'a str, language: String, base_icons_url: &'a str, @@ -32,7 +32,7 @@ impl<'a> Placeholders<'a> { pub fn replace(&self, text: &str) -> String { replace_with_capitalization!( text, - "filename" => self.filename, + "filename" => self.filename.as_str(), "workspace" => self.workspace, "language" => self.language.as_str(), "base_icons_url" => self.base_icons_url