From 0810b2c79ad2e09ed07dfe69bb454a1968fd8a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Sun, 4 Aug 2024 22:49:23 +0200 Subject: [PATCH] fix: dont panic if cant find language --- Cargo.lock | 2 +- lsp/Cargo.toml | 2 +- lsp/src/languages.rs | 10 +++++----- lsp/src/util.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0f6f2b0..229bec0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -124,7 +124,7 @@ dependencies = [ [[package]] name = "discord-presence-lsp" -version = "0.4.0" +version = "0.4.1" dependencies = [ "discord-rich-presence", "git2", diff --git a/lsp/Cargo.toml b/lsp/Cargo.toml index 82880b1..90c388f 100644 --- a/lsp/Cargo.toml +++ b/lsp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "discord-presence-lsp" -version = "0.4.0" +version = "0.4.1" edition = "2021" [dependencies] diff --git a/lsp/src/languages.rs b/lsp/src/languages.rs index 2ecc0f8..c48abec 100644 --- a/lsp/src/languages.rs +++ b/lsp/src/languages.rs @@ -14,13 +14,13 @@ lazy_static! { }; } -pub fn get_language(document: &Document) -> Option { +pub fn get_language(document: &Document) -> String { let map = LANGUAGE_MAP.lock().unwrap(); let filename = document.get_filename().to_string(); let extension = format!(".{}", document.get_extension()); if let Some(s) = map.get(&filename) { - return Some(s.to_string()); + return s.to_string(); } for (pattern, language) in map.iter() { @@ -31,14 +31,14 @@ pub fn get_language(document: &Document) -> Option { if let Ok(re) = Regex::new(pattern.unwrap()) { if re.is_match(&filename) || re.is_match(&extension) { - return Some(language.to_string()); + return language.to_string(); } } } if let Some(s) = map.get(&extension) { - return Some(s.to_string()); + return s.to_string(); } - map.get("text").map(|s| s.to_string()) + String::from("text") } diff --git a/lsp/src/util.rs b/lsp/src/util.rs index 271fedd..e69ad90 100644 --- a/lsp/src/util.rs +++ b/lsp/src/util.rs @@ -24,7 +24,7 @@ impl<'a> Placeholders<'a> { Self { filename: doc.get_filename(), workspace, - language: get_language(doc).unwrap(), + language: get_language(doc), base_icons_url: &config.base_icons_url, } }