Skip to content

Commit

Permalink
fix: dont panic if cant find language
Browse files Browse the repository at this point in the history
  • Loading branch information
xhyrom committed Aug 4, 2024
1 parent 458f939 commit 0810b2c
Show file tree
Hide file tree
Showing 4 changed files with 8 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 lsp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "discord-presence-lsp"
version = "0.4.0"
version = "0.4.1"
edition = "2021"

[dependencies]
Expand Down
10 changes: 5 additions & 5 deletions lsp/src/languages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ lazy_static! {
};
}

pub fn get_language(document: &Document) -> Option<String> {
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() {
Expand All @@ -31,14 +31,14 @@ pub fn get_language(document: &Document) -> Option<String> {

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")
}
2 changes: 1 addition & 1 deletion lsp/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down

0 comments on commit 0810b2c

Please sign in to comment.