Skip to content

Commit

Permalink
feat(view): global status line option
Browse files Browse the repository at this point in the history
Add option to render single glboal status line instead of rendering
status line per view.

Fixes: helix-editor#2254
  • Loading branch information
matoous committed Oct 23, 2022
1 parent 5a84834 commit 9ecc14c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 10 deletions.
18 changes: 18 additions & 0 deletions helix-lsp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{

use anyhow::anyhow;
use helix_core::{find_root, ChangeSet, Rope};
use lsp::DocumentColorParams;
use lsp_types as lsp;
use serde::Deserialize;
use serde_json::Value;
Expand Down Expand Up @@ -364,6 +365,9 @@ impl Client {
publish_diagnostics: Some(lsp::PublishDiagnosticsClientCapabilities {
..Default::default()
}),
color_provider: Some(lsp::DocumentColorClientCapabilities {
..Default::default()
}),
..Default::default()
}),
window: Some(lsp::WindowClientCapabilities {
Expand Down Expand Up @@ -894,6 +898,20 @@ impl Client {
self.call::<lsp::request::DocumentSymbolRequest>(params)
}

pub fn document_colors(
&self,
text_document: lsp::TextDocumentIdentifier,
work_done_token: Option<lsp::ProgressToken>,
) -> impl Future<Output = Result<Value>> {
self.call::<lsp::request::DocumentColor>(DocumentColorParams {
text_document,
work_done_progress_params: lsp::WorkDoneProgressParams { work_done_token },
partial_result_params: lsp::PartialResultParams {
partial_result_token: None,
},
})
}

// empty string to get all symbols
pub fn workspace_symbols(&self, query: String) -> impl Future<Output = Result<Value>> {
let params = lsp::WorkspaceSymbolParams {
Expand Down
55 changes: 45 additions & 10 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use helix_core::{
use helix_view::{
apply_transaction,
document::{Mode, SCRATCH_BUFFER_NAME},
editor::{CompleteAction, CursorShapeConfig},
editor::{CompleteAction, CursorShapeConfig, StatusLineRenderConfig},
graphics::{Color, CursorKind, Modifier, Rect, Style},
input::{KeyEvent, MouseButton, MouseEvent, MouseEventKind},
keyboard::{KeyCode, KeyModifiers},
Expand Down Expand Up @@ -80,7 +80,10 @@ impl EditorView {
is_focused: bool,
) {
let inner = view.inner_area();
let area = view.area;
let area = match editor.config().statusline.render {
StatusLineRenderConfig::Single => view.area.clip_bottom(1),
StatusLineRenderConfig::PerView => view.area,
};
let theme = &editor.theme;

// DAP: Highlight current stack frame position
Expand Down Expand Up @@ -171,22 +174,37 @@ impl EditorView {
for y in area.top()..area.bottom() {
surface[(x, y)]
.set_symbol(tui::symbols::line::VERTICAL)
//.set_symbol(" ")
.set_style(border_style);
}
}

self.render_diagnostics(doc, view, inner, surface, theme);

let statusline_area = view
.area
.clip_top(view.area.height.saturating_sub(1))
.clip_bottom(1); // -1 from bottom to remove commandline
match editor.config().statusline.render {
StatusLineRenderConfig::PerView => {
let statusline_area = view
.area
.clip_top(view.area.height.saturating_sub(1))
.clip_bottom(1); // -1 from bottom to remove commandline

let mut context =
statusline::RenderContext::new(editor, doc, view, is_focused, &self.spinners);
let mut context =
statusline::RenderContext::new(editor, doc, view, is_focused, &self.spinners);

statusline::render(&mut context, statusline_area, surface);
statusline::render(&mut context, statusline_area, surface);
}
StatusLineRenderConfig::Single => {
// -1 for command line
if viewport.bottom() - 1 != view.area.bottom() {
let y = area.bottom();
let border_style = theme.get("ui.window");
for x in area.left()..area.right() {
surface[(x, y)]
.set_symbol(tui::symbols::line::HORIZONTAL)
.set_style(border_style);
}
}
}
};
}

pub fn render_rulers(
Expand Down Expand Up @@ -1469,6 +1487,23 @@ impl Component for EditorView {
self.render_view(cx.editor, doc, view, area, surface, is_focused);
}

if config.statusline.render == StatusLineRenderConfig::Single {
if let Some((view, is_focused)) =
cx.editor.tree.views().find(|&(_, is_focused)| is_focused)
{
let doc = cx.editor.document(view.doc).unwrap();
let mut context = statusline::RenderContext::new(
cx.editor,
doc,
view,
is_focused,
&self.spinners,
);
let statusline_area = area.clip_top(area.height.saturating_sub(2)).clip_bottom(1); // -1 from bottom to remove commandline
statusline::render(&mut context, statusline_area, surface);
}
}

if config.auto_info {
if let Some(mut info) = cx.editor.autoinfo.take() {
info.render(area, surface, cx);
Expand Down
9 changes: 9 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ pub struct StatusLineConfig {
pub right: Vec<StatusLineElement>,
pub separator: String,
pub mode: ModeConfig,
pub render: StatusLineRenderConfig,
}

impl Default for StatusLineConfig {
Expand All @@ -279,6 +280,7 @@ impl Default for StatusLineConfig {
right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding],
separator: String::from("│"),
mode: ModeConfig::default(),
render: StatusLineRenderConfig::PerView,
}
}
}
Expand All @@ -301,6 +303,13 @@ impl Default for ModeConfig {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum StatusLineRenderConfig {
Single,
PerView,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum StatusLineElement {
Expand Down

0 comments on commit 9ecc14c

Please sign in to comment.