Added theme to language
This commit is contained in:
parent
6f99d59d38
commit
988f388165
6 changed files with 35 additions and 22 deletions
|
@ -279,6 +279,7 @@ pub struct Language {
|
|||
pub(crate) config: LanguageConfig,
|
||||
pub(crate) grammar: Option<Arc<Grammar>>,
|
||||
pub(crate) adapter: Option<Arc<LspAdapter>>,
|
||||
pub(crate) theme: RwLock<Option<Arc<SyntaxTheme>>>,
|
||||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
fake_adapter: Option<(
|
||||
|
@ -339,9 +340,8 @@ impl LanguageRegistry {
|
|||
Self::new(Task::ready(()))
|
||||
}
|
||||
|
||||
pub fn add(&self, language: Arc<Language>, theme: &SyntaxTheme) {
|
||||
pub fn add(&self, language: Arc<Language>) {
|
||||
self.languages.write().push(language.clone());
|
||||
language.set_theme(theme);
|
||||
*self.subscription.write().0.borrow_mut() = ();
|
||||
}
|
||||
|
||||
|
@ -349,9 +349,9 @@ impl LanguageRegistry {
|
|||
self.subscription.read().1.clone()
|
||||
}
|
||||
|
||||
pub fn set_theme(&self, theme: &SyntaxTheme) {
|
||||
pub fn set_theme(&self, theme: Arc<SyntaxTheme>) {
|
||||
for language in self.languages.read().iter() {
|
||||
language.set_theme(theme);
|
||||
language.set_theme(theme.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -576,6 +576,7 @@ impl Language {
|
|||
})
|
||||
}),
|
||||
adapter: None,
|
||||
theme: Default::default(),
|
||||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
fake_adapter: None,
|
||||
|
@ -712,12 +713,21 @@ impl Language {
|
|||
c.is_whitespace() || self.config.autoclose_before.contains(c)
|
||||
}
|
||||
|
||||
pub fn set_theme(&self, theme: &SyntaxTheme) {
|
||||
/// Sets the theme to the given theme, and then calls [`highlight`].
|
||||
pub fn set_theme(&self, theme: Arc<SyntaxTheme>) {
|
||||
*self.theme.write() = Some(theme.clone());
|
||||
self.highlight()
|
||||
}
|
||||
|
||||
/// Highlights the grammar according to the current theme,
|
||||
/// if one has been set using [`set_theme`].
|
||||
pub fn highlight(&self) {
|
||||
if let Some(grammar) = self.grammar.as_ref() {
|
||||
if let Some(highlights_query) = &grammar.highlights_query {
|
||||
*grammar.highlight_map.lock() =
|
||||
HighlightMap::new(highlights_query.capture_names(), theme);
|
||||
dbg!("highlighting");
|
||||
if let Some(theme) = self.theme.read().as_ref() {
|
||||
*grammar.highlight_map.lock() =
|
||||
HighlightMap::new(highlights_query.capture_names(), &theme);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue