Require theme directly when creating language
This commit is contained in:
parent
73620dad06
commit
6f99d59d38
4 changed files with 21 additions and 14 deletions
|
@ -14,7 +14,7 @@ use futures::{
|
||||||
future::{BoxFuture, Shared},
|
future::{BoxFuture, Shared},
|
||||||
FutureExt, TryFutureExt,
|
FutureExt, TryFutureExt,
|
||||||
};
|
};
|
||||||
use gpui::{MutableAppContext, Task};
|
use gpui::{AsyncAppContext, MutableAppContext, Task};
|
||||||
use highlight_map::HighlightMap;
|
use highlight_map::HighlightMap;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use parking_lot::{Mutex, RwLock};
|
use parking_lot::{Mutex, RwLock};
|
||||||
|
@ -339,8 +339,9 @@ impl LanguageRegistry {
|
||||||
Self::new(Task::ready(()))
|
Self::new(Task::ready(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(&self, language: Arc<Language>) {
|
pub fn add(&self, language: Arc<Language>, theme: &SyntaxTheme) {
|
||||||
self.languages.write().push(language.clone());
|
self.languages.write().push(language.clone());
|
||||||
|
language.set_theme(theme);
|
||||||
*self.subscription.write().0.borrow_mut() = ();
|
*self.subscription.write().0.borrow_mut() = ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,11 +388,14 @@ impl LanguageRegistry {
|
||||||
.read()
|
.read()
|
||||||
.iter()
|
.iter()
|
||||||
.find(|language| {
|
.find(|language| {
|
||||||
language
|
language.config.path_suffixes.iter().any(|suffix| {
|
||||||
.config
|
if path_suffixes.contains(&Some(suffix.as_str())) {
|
||||||
.path_suffixes
|
dbg!(format!("found {}", suffix));
|
||||||
.iter()
|
true
|
||||||
.any(|suffix| dbg!(path_suffixes.contains(&Some(dbg!(suffix.as_str())))))
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.cloned()
|
.cloned()
|
||||||
}
|
}
|
||||||
|
@ -713,6 +717,7 @@ impl Language {
|
||||||
if let Some(highlights_query) = &grammar.highlights_query {
|
if let Some(highlights_query) = &grammar.highlights_query {
|
||||||
*grammar.highlight_map.lock() =
|
*grammar.highlight_map.lock() =
|
||||||
HighlightMap::new(highlights_query.capture_names(), theme);
|
HighlightMap::new(highlights_query.capture_names(), theme);
|
||||||
|
dbg!("highlighting");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2028,7 +2028,7 @@ impl Project {
|
||||||
) -> Task<()> {
|
) -> Task<()> {
|
||||||
let mut subscription = languages.subscribe();
|
let mut subscription = languages.subscribe();
|
||||||
cx.spawn_weak(|project, mut cx| async move {
|
cx.spawn_weak(|project, mut cx| async move {
|
||||||
while let Some(_) = subscription.next().await {
|
while let Some(()) = subscription.next().await {
|
||||||
if let Some(project) = project.upgrade(&cx) {
|
if let Some(project) = project.upgrade(&cx) {
|
||||||
project.update(&mut cx, |project, cx| {
|
project.update(&mut cx, |project, cx| {
|
||||||
let mut buffers_without_language = Vec::new();
|
let mut buffers_without_language = Vec::new();
|
||||||
|
@ -2041,8 +2041,10 @@ impl Project {
|
||||||
}
|
}
|
||||||
|
|
||||||
for buffer in buffers_without_language {
|
for buffer in buffers_without_language {
|
||||||
|
dbg!("notified that new language was added");
|
||||||
project.assign_language_to_buffer(&buffer, cx);
|
project.assign_language_to_buffer(&buffer, cx);
|
||||||
project.register_buffer_with_language_server(&buffer, cx);
|
project.register_buffer_with_language_server(&buffer, cx);
|
||||||
|
dbg!(buffer.read(cx).language().map(|x| x.name()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2055,6 +2057,7 @@ impl Project {
|
||||||
buffer: &ModelHandle<Buffer>,
|
buffer: &ModelHandle<Buffer>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
|
dbg!("assigning language to buffer");
|
||||||
// If the buffer has a language, set it and start the language server if we haven't already.
|
// If the buffer has a language, set it and start the language server if we haven't already.
|
||||||
let full_path = buffer.read(cx).file()?.full_path(cx);
|
let full_path = buffer.read(cx).file()?.full_path(cx);
|
||||||
let language = self.languages.select_language(&full_path)?;
|
let language = self.languages.select_language(&full_path)?;
|
||||||
|
@ -2078,6 +2081,7 @@ impl Project {
|
||||||
language: Arc<Language>,
|
language: Arc<Language>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) {
|
) {
|
||||||
|
dbg!(format!("starting lsp for {:?}", language.name()));
|
||||||
if !cx
|
if !cx
|
||||||
.global::<Settings>()
|
.global::<Settings>()
|
||||||
.enable_language_server(Some(&language.name()))
|
.enable_language_server(Some(&language.name()))
|
||||||
|
@ -2343,6 +2347,8 @@ impl Project {
|
||||||
|
|
||||||
server_id
|
server_id
|
||||||
});
|
});
|
||||||
|
|
||||||
|
dbg!("Done starting lsp");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a list of all of the worktrees which no longer have a language server and the root path
|
// Returns a list of all of the worktrees which no longer have a language server and the root path
|
||||||
|
@ -3273,8 +3279,8 @@ impl Project {
|
||||||
position: T,
|
position: T,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<Vec<DocumentHighlight>>> {
|
) -> Task<Result<Vec<DocumentHighlight>>> {
|
||||||
|
// dbg!("getting highlights");
|
||||||
let position = position.to_point_utf16(buffer.read(cx));
|
let position = position.to_point_utf16(buffer.read(cx));
|
||||||
|
|
||||||
self.request_lsp(buffer.clone(), GetDocumentHighlights { position }, cx)
|
self.request_lsp(buffer.clone(), GetDocumentHighlights { position }, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -226,6 +226,7 @@ fn main() {
|
||||||
let languages = languages.clone();
|
let languages = languages.clone();
|
||||||
|cx| async move {
|
|cx| async move {
|
||||||
init_languages.await;
|
init_languages.await;
|
||||||
|
dbg!("all languages initialized, starting setting highlighting");
|
||||||
cx.read(|cx| languages.set_theme(&cx.global::<Settings>().theme.editor.syntax));
|
cx.read(|cx| languages.set_theme(&cx.global::<Settings>().theme.editor.syntax));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -27,13 +27,8 @@ pub fn fetch_latest_server_version() -> Option<String> {
|
||||||
versions: Vec<String>,
|
versions: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: command returns error code
|
|
||||||
let output =
|
let output =
|
||||||
command("npm info vscode-json-languageserver --json").expect("could not run command");
|
command("npm info vscode-json-languageserver --json").expect("could not run command");
|
||||||
// if !output.is_ok() {
|
|
||||||
// return None;
|
|
||||||
// }
|
|
||||||
|
|
||||||
let output = String::from_utf8(output).unwrap();
|
let output = String::from_utf8(output).unwrap();
|
||||||
|
|
||||||
let mut info: NpmInfo = serde_json::from_str(&output).ok()?;
|
let mut info: NpmInfo = serde_json::from_str(&output).ok()?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue