1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use std::collections::hash_map::DefaultHasher;
use crate::{errors::PsiResult, PsiError, LANGUAGE_REGISTRY_INSTANCE};
use super::*;
impl LanguageID {
pub fn any() -> Self {
Self(0)
}
pub fn is_any(&self) -> bool {
self.0 == 0
}
pub fn new(s: &str) -> LanguageID {
let normalized = normalize(s);
let mut hasher = DefaultHasher::new();
normalized.hash(&mut hasher);
Self(hasher.finish())
}
pub fn language_type(&self) -> PsiResult<LanguageType> {
match LANGUAGE_REGISTRY_INSTANCE.try_lock()?.find_language(LanguageID(self.0)) {
Some(s) => Ok(s.clone()),
None => Err(PsiError::runtime_error(format!("Language {} not found", self.0))),
}
}
}
fn normalize(s: &str) -> String {
s.to_ascii_lowercase()
}