on master help sign in
Add progress spinners to status line
cc357d5wojciechkepka
helix-lsp/src/lib.rs+4
@@ -347,6 +347,10 @@ impl LspProgressMap {
347 self.0.get(&id)
347 self.0.get(&id)
348 }
348 }
349
349
350+ pub fn is_progressing(&self, id: usize) -> bool {
351+ self.0.get(&id).map(|it| !it.is_empty()).unwrap_or_default()
352+ }
353+
350 /// Returns last progress status for a given server with `id` and `token`.
354 /// Returns last progress status for a given server with `id` and `token`.
351 pub fn progress(&self, id: usize, token: &lsp::ProgressToken) -> Option<&ProgressStatus> {
355 pub fn progress(&self, id: usize, token: &lsp::ProgressToken) -> Option<&ProgressStatus> {
352 self.0.get(&id).and_then(|values| values.get(token))
356 self.0.get(&id).and_then(|values| values.get(token))
helix-term/src/application.rs+45−6
@@ -2,11 +2,18 @@ use helix_core::syntax;
2use helix_lsp::{lsp, LspProgressMap};
2use helix_lsp::{lsp, LspProgressMap};
3use helix_view::{document::Mode, theme, Document, Editor, Theme, View};
3use helix_view::{document::Mode, theme, Document, Editor, Theme, View};
4
4
5+use crate::{
6+ args::Args,
5−use crate::{args::Args, compositor::Compositor, config::Config, keymap::Keymaps, ui};
7+ compositor::Compositor,
8+ config::Config,
9+ keymap::Keymaps,
10+ ui::{self, Spinner},
11+};
6
12
7use log::{error, info};
13use log::{error, info};
8
14
9use std::{
15use std::{
16+ collections::HashMap,
10 future::Future,
17 future::Future,
11 io::{self, stdout, Stdout, Write},
18 io::{self, stdout, Stdout, Write},
12 path::PathBuf,
19 path::PathBuf,
@@ -42,7 +49,7 @@ pub struct Application {
42 callbacks: LspCallbacks,
49 callbacks: LspCallbacks,
43
50
44 lsp_progress: LspProgressMap,
51 lsp_progress: LspProgressMap,
45− lsp_progress_enabled: bool,
52+ lsp_display_messages: bool,
46}
53}
47
54
48impl Application {
55impl Application {
@@ -62,7 +69,7 @@ impl Application {
62 .as_deref()
69 .as_deref()
63 .unwrap_or(include_bytes!("../../languages.toml"));
70 .unwrap_or(include_bytes!("../../languages.toml"));
64
71
65− let theme = if let Some(theme) = &config.global.theme {
72+ let theme = if let Some(theme) = &config.theme {
66 match theme_loader.load(theme) {
73 match theme_loader.load(theme) {
67 Ok(theme) => theme,
74 Ok(theme) => theme,
68 Err(e) => {
75 Err(e) => {
@@ -112,7 +119,7 @@ impl Application {
112 syn_loader,
119 syn_loader,
113 callbacks: FuturesUnordered::new(),
120 callbacks: FuturesUnordered::new(),
114 lsp_progress: LspProgressMap::new(),
121 lsp_progress: LspProgressMap::new(),
115− lsp_progress_enabled: config.global.lsp_progress,
122+ lsp_display_messages: config.lsp.display_messages,
116 };
123 };
117
124
118 Ok(app)
125 Ok(app)
@@ -305,11 +312,23 @@ impl Application {
305 (None, message, &None)
312 (None, message, &None)
306 } else {
313 } else {
307 self.lsp_progress.end_progress(server_id, &token);
314 self.lsp_progress.end_progress(server_id, &token);
315+ if !self.lsp_progress.is_progressing(server_id) {
316+ let ui = self
317+ .compositor
318+ .find(std::any::type_name::<ui::EditorView>())
319+ .unwrap();
320+ if let Some(ui) =
321+ ui.as_any_mut().downcast_mut::<ui::EditorView>()
322+ {
323+ ui.spinners_mut().get_or_create(server_id).stop();
324+ };
325+ }
308 self.editor.clear_status();
326 self.editor.clear_status();
309 return;
327 return;
310 }
328 }
311 }
329 }
312 };
330 };
331+
313 let token_d: &dyn std::fmt::Display = match &token {
332 let token_d: &dyn std::fmt::Display = match &token {
314 lsp::NumberOrString::Number(n) => n,
333 lsp::NumberOrString::Number(n) => n,
315 lsp::NumberOrString::String(s) => s,
334 lsp::NumberOrString::String(s) => s,
@@ -342,14 +361,23 @@ impl Application {
342
361
343 if let lsp::WorkDoneProgress::End(_) = work {
362 if let lsp::WorkDoneProgress::End(_) = work {
344 self.lsp_progress.end_progress(server_id, &token);
363 self.lsp_progress.end_progress(server_id, &token);
364+ if !self.lsp_progress.is_progressing(server_id) {
365+ let ui = self
366+ .compositor
367+ .find(std::any::type_name::<ui::EditorView>())
368+ .unwrap();
369+ if let Some(ui) = ui.as_any_mut().downcast_mut::<ui::EditorView>() {
370+ ui.spinners_mut().get_or_create(server_id).stop();
371+ };
372+ }
345 } else {
373 } else {
346 self.lsp_progress.update(server_id, token, work);
374 self.lsp_progress.update(server_id, token, work);
347 }
375 }
348
376
349− if self.lsp_progress_enabled {
377+ if self.lsp_display_messages {
350 self.editor.set_status(status);
378 self.editor.set_status(status);
351− self.render();
352 }
379 }
380+ self.render();
353 }
381 }
354 _ => unreachable!(),
382 _ => unreachable!(),
355 }
383 }
@@ -372,6 +400,17 @@ impl Application {
372 MethodCall::WorkDoneProgressCreate(params) => {
400 MethodCall::WorkDoneProgressCreate(params) => {
373 self.lsp_progress.create(server_id, params.token);
401 self.lsp_progress.create(server_id, params.token);
374
402
403+ let ui = self
404+ .compositor
405+ .find(std::any::type_name::<ui::EditorView>())
406+ .unwrap();
407+ if let Some(ui) = ui.as_any_mut().downcast_mut::<ui::EditorView>() {
408+ let spinner = ui.spinners_mut().get_or_create(server_id);
409+ if spinner.is_stopped() {
410+ spinner.start();
411+ }
412+ };
413+
375 let doc = self.editor.documents().find(|doc| {
414 let doc = self.editor.documents().find(|doc| {
376 doc.language_server()
415 doc.language_server()
377 .map(|server| server.id() == server_id)
416 .map(|server| server.id() == server_id)
helix-term/src/commands.rs+1−1
@@ -19,7 +19,7 @@ use anyhow::anyhow;
19use helix_lsp::{
19use helix_lsp::{
20 lsp,
20 lsp,
21 util::{lsp_pos_to_pos, lsp_range_to_range, pos_to_lsp_pos, range_to_lsp_range},
21 util::{lsp_pos_to_pos, lsp_range_to_range, pos_to_lsp_pos, range_to_lsp_range},
22− OffsetEncoding,
22+ LspProgressMap, OffsetEncoding,
23};
23};
24use insert::*;
24use insert::*;
25use movement::Movement;
25use movement::Movement;
helix-term/src/compositor.rs+2−1
@@ -1,9 +1,10 @@
1// Each component declares it's own size constraints and gets fitted based on it's parent.
1// Each component declares it's own size constraints and gets fitted based on it's parent.
2// Q: how does this work with popups?
2// Q: how does this work with popups?
3// cursive does compositor.screen_mut().add_layer_at(pos::absolute(x, y), <component>)
3// cursive does compositor.screen_mut().add_layer_at(pos::absolute(x, y), <component>)
4+use helix_core::Position;
5+use helix_lsp::LspProgressMap;
4
6
5use crossterm::event::Event;
7use crossterm::event::Event;
6−use helix_core::Position;
7use tui::{buffer::Buffer as Surface, layout::Rect, terminal::CursorKind};
8use tui::{buffer::Buffer as Surface, layout::Rect, terminal::CursorKind};
8
9
9pub type Callback = Box<dyn FnOnce(&mut Compositor)>;
10pub type Callback = Box<dyn FnOnce(&mut Compositor)>;
helix-term/src/config.rs+12−21
@@ -1,35 +1,28 @@
1use anyhow::{Error, Result};
1use anyhow::{Error, Result};
2−use std::{collections::HashMap, str::FromStr};
2+use std::collections::HashMap;
3
3
4use serde::{de::Error as SerdeError, Deserialize, Serialize};
4use serde::{de::Error as SerdeError, Deserialize, Serialize};
5
5
6use crate::keymap::{parse_keymaps, Keymaps};
6use crate::keymap::{parse_keymaps, Keymaps};
7
7
8−pub struct GlobalConfig {
9− pub theme: Option<String>,
10− pub lsp_progress: bool,
11−}
12−
13−impl Default for GlobalConfig {
14− fn default() -> Self {
15− Self {
16− lsp_progress: true,
17− theme: None,
18− }
19− }
20−}
21−
22#[derive(Default)]
8#[derive(Default)]
23pub struct Config {
9pub struct Config {
24− pub global: GlobalConfig,
10+ pub theme: Option<String>,
11+ pub lsp: LspConfig,
25 pub keymaps: Keymaps,
12 pub keymaps: Keymaps,
26}
13}
27
14
15+#[derive(Default, Serialize, Deserialize)]
16+pub struct LspConfig {
17+ pub display_messages: bool,
18+}
19+
28#[derive(Serialize, Deserialize)]
20#[derive(Serialize, Deserialize)]
29#[serde(rename_all = "kebab-case")]
21#[serde(rename_all = "kebab-case")]
30struct TomlConfig {
22struct TomlConfig {
31 theme: Option<String>,
23 theme: Option<String>,
32− lsp_progress: Option<bool>,
24+ #[serde(default)]
25+ lsp: LspConfig,
33 keys: Option<HashMap<String, HashMap<String, String>>>,
26 keys: Option<HashMap<String, HashMap<String, String>>>,
34}
27}
35
28
@@ -40,10 +33,8 @@ impl<'de> Deserialize<'de> for Config {
40 {
33 {
41 let config = TomlConfig::deserialize(deserializer)?;
34 let config = TomlConfig::deserialize(deserializer)?;
42 Ok(Self {
35 Ok(Self {
43− global: GlobalConfig {
36+ theme: config.theme,
44− lsp_progress: config.lsp_progress.unwrap_or(true),
45− theme: config.theme,
37+ lsp: config.lsp,
46− },
47 keymaps: config
38 keymaps: config
48 .keys
39 .keys
49 .map(|r| parse_keymaps(&r))
40 .map(|r| parse_keymaps(&r))
helix-term/src/ui/editor.rs+21−2
@@ -3,7 +3,7 @@ use crate::{
3 compositor::{Component, Compositor, Context, EventResult},
3 compositor::{Component, Compositor, Context, EventResult},
4 key,
4 key,
5 keymap::{self, Keymaps},
5 keymap::{self, Keymaps},
6− ui::Completion,
6+ ui::{Completion, ProgressSpinners},
7};
7};
8
8
9use helix_core::{
9use helix_core::{
@@ -11,6 +11,7 @@ use helix_core::{
11 syntax::{self, HighlightEvent},
11 syntax::{self, HighlightEvent},
12 Position, Range,
12 Position, Range,
13};
13};
14+use helix_lsp::LspProgressMap;
14use helix_view::{document::Mode, Document, Editor, Theme, View};
15use helix_view::{document::Mode, Document, Editor, Theme, View};
15use std::borrow::Cow;
16use std::borrow::Cow;
16
17
@@ -31,6 +32,7 @@ pub struct EditorView {
31 on_next_key: Option<Box<dyn FnOnce(&mut commands::Context, KeyEvent)>>,
32 on_next_key: Option<Box<dyn FnOnce(&mut commands::Context, KeyEvent)>>,
32 last_insert: (commands::Command, Vec<KeyEvent>),
33 last_insert: (commands::Command, Vec<KeyEvent>),
33 completion: Option<Completion>,
34 completion: Option<Completion>,
35+ spinners: ProgressSpinners,
34}
36}
35
37
36const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
38const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
@@ -48,9 +50,15 @@ impl EditorView {
48 on_next_key: None,
50 on_next_key: None,
49 last_insert: (commands::Command::normal_mode, Vec::new()),
51 last_insert: (commands::Command::normal_mode, Vec::new()),
50 completion: None,
52 completion: None,
53+ spinners: ProgressSpinners::default(),
51 }
54 }
52 }
55 }
53
56
57+ pub fn spinners_mut(&mut self) -> &mut ProgressSpinners {
58+ &mut self.spinners
59+ }
60+
61+ #[allow(clippy::too_many_arguments)]
54 pub fn render_view(
62 pub fn render_view(
55 &self,
63 &self,
56 doc: &Document,
64 doc: &Document,
@@ -458,6 +466,7 @@ impl EditorView {
458 );
466 );
459 }
467 }
460
468
469+ #[allow(clippy::too_many_arguments)]
461 pub fn render_statusline(
470 pub fn render_statusline(
462 &self,
471 &self,
463 doc: &Document,
472 doc: &Document,
@@ -476,6 +485,15 @@ impl EditorView {
476 Mode::Select => "SEL",
485 Mode::Select => "SEL",
477 Mode::Normal => "NOR",
486 Mode::Normal => "NOR",
478 };
487 };
488+ let progress = doc
489+ .language_server()
490+ .and_then(|srv| {
491+ self.spinners
492+ .get(srv.id())
493+ .and_then(|spinner| spinner.frame())
494+ })
495+ .unwrap_or("");
496+
479 let style = if is_focused {
497 let style = if is_focused {
480 theme.get("ui.statusline")
498 theme.get("ui.statusline")
481 } else {
499 } else {
@@ -486,13 +504,14 @@ impl EditorView {
486 if is_focused {
504 if is_focused {
487 surface.set_string(viewport.x + 1, viewport.y, mode, style);
505 surface.set_string(viewport.x + 1, viewport.y, mode, style);
488 }
506 }
507+ surface.set_string(viewport.x + 5, viewport.y, progress, style);
489
508
490 if let Some(path) = doc.relative_path() {
509 if let Some(path) = doc.relative_path() {
491 let path = path.to_string_lossy();
510 let path = path.to_string_lossy();
492
511
493 let title = format!("{}{}", path, if doc.is_modified() { "[+]" } else { "" });
512 let title = format!("{}{}", path, if doc.is_modified() { "[+]" } else { "" });
494 surface.set_stringn(
513 surface.set_stringn(
495− viewport.x + 6,
514+ viewport.x + 8,
496 viewport.y,
515 viewport.y,
497 title,
516 title,
498 viewport.width.saturating_sub(6) as usize,
517 viewport.width.saturating_sub(6) as usize,