Hold `Config` in `Application`, expect at least one editor view

imgbot
wojciechkepka 4 years ago committed by Blaž Hrastnik
parent cc357d5096
commit aca9d73fe4

@ -44,12 +44,13 @@ pub struct Application {
compositor: Compositor, compositor: Compositor,
editor: Editor, editor: Editor,
config: Config,
theme_loader: Arc<theme::Loader>, theme_loader: Arc<theme::Loader>,
syn_loader: Arc<syntax::Loader>, syn_loader: Arc<syntax::Loader>,
callbacks: LspCallbacks,
callbacks: LspCallbacks,
lsp_progress: LspProgressMap, lsp_progress: LspProgressMap,
lsp_display_messages: bool,
} }
impl Application { impl Application {
@ -86,7 +87,7 @@ impl Application {
let mut editor = Editor::new(size, theme_loader.clone(), syn_loader.clone()); let mut editor = Editor::new(size, theme_loader.clone(), syn_loader.clone());
let mut editor_view = Box::new(ui::EditorView::new(config.keymaps)); let mut editor_view = Box::new(ui::EditorView::new(config.keymaps.clone()));
compositor.push(editor_view); compositor.push(editor_view);
if !args.files.is_empty() { if !args.files.is_empty() {
@ -115,11 +116,13 @@ impl Application {
compositor, compositor,
editor, editor,
config,
theme_loader, theme_loader,
syn_loader, syn_loader,
callbacks: FuturesUnordered::new(), callbacks: FuturesUnordered::new(),
lsp_progress: LspProgressMap::new(), lsp_progress: LspProgressMap::new(),
lsp_display_messages: config.lsp.display_messages,
}; };
Ok(app) Ok(app)
@ -205,6 +208,15 @@ impl Application {
server_id: usize, server_id: usize,
) { ) {
use helix_lsp::{Call, MethodCall, Notification}; use helix_lsp::{Call, MethodCall, Notification};
let editor_view = self
.compositor
.find(std::any::type_name::<ui::EditorView>())
.expect("expected at least one EditorView");
let editor_view = editor_view
.as_any_mut()
.downcast_mut::<ui::EditorView>()
.unwrap();
match call { match call {
Call::Notification(helix_lsp::jsonrpc::Notification { method, params, .. }) => { Call::Notification(helix_lsp::jsonrpc::Notification { method, params, .. }) => {
let notification = match Notification::parse(&method, params) { let notification = match Notification::parse(&method, params) {
@ -313,15 +325,7 @@ impl Application {
} else { } else {
self.lsp_progress.end_progress(server_id, &token); self.lsp_progress.end_progress(server_id, &token);
if !self.lsp_progress.is_progressing(server_id) { if !self.lsp_progress.is_progressing(server_id) {
let ui = self editor_view.spinners_mut().get_or_create(server_id).stop();
.compositor
.find(std::any::type_name::<ui::EditorView>())
.unwrap();
if let Some(ui) =
ui.as_any_mut().downcast_mut::<ui::EditorView>()
{
ui.spinners_mut().get_or_create(server_id).stop();
};
} }
self.editor.clear_status(); self.editor.clear_status();
return; return;
@ -362,19 +366,13 @@ impl Application {
if let lsp::WorkDoneProgress::End(_) = work { if let lsp::WorkDoneProgress::End(_) = work {
self.lsp_progress.end_progress(server_id, &token); self.lsp_progress.end_progress(server_id, &token);
if !self.lsp_progress.is_progressing(server_id) { if !self.lsp_progress.is_progressing(server_id) {
let ui = self editor_view.spinners_mut().get_or_create(server_id).stop();
.compositor
.find(std::any::type_name::<ui::EditorView>())
.unwrap();
if let Some(ui) = ui.as_any_mut().downcast_mut::<ui::EditorView>() {
ui.spinners_mut().get_or_create(server_id).stop();
};
} }
} else { } else {
self.lsp_progress.update(server_id, token, work); self.lsp_progress.update(server_id, token, work);
} }
if self.lsp_display_messages { if self.config.lsp.display_messages {
self.editor.set_status(status); self.editor.set_status(status);
} }
self.render(); self.render();
@ -400,16 +398,10 @@ impl Application {
MethodCall::WorkDoneProgressCreate(params) => { MethodCall::WorkDoneProgressCreate(params) => {
self.lsp_progress.create(server_id, params.token); self.lsp_progress.create(server_id, params.token);
let ui = self let spinner = editor_view.spinners_mut().get_or_create(server_id);
.compositor
.find(std::any::type_name::<ui::EditorView>())
.unwrap();
if let Some(ui) = ui.as_any_mut().downcast_mut::<ui::EditorView>() {
let spinner = ui.spinners_mut().get_or_create(server_id);
if spinner.is_stopped() { if spinner.is_stopped() {
spinner.start(); spinner.start();
} }
};
let doc = self.editor.documents().find(|doc| { let doc = self.editor.documents().find(|doc| {
doc.language_server() doc.language_server()

Loading…
Cancel
Save