Skip to content

Commit

Permalink
Handle window/showMessage and display it bellow status line
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoub-benali committed Mar 12, 2023
1 parent 1126af5 commit 16d1d88
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
3 changes: 2 additions & 1 deletion book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ The following statusline elements can be configured:
| Key | Description | Default |
| --- | ----------- | ------- |
| `enable` | Enables LSP integration. Setting to false will completely disable language servers regardless of language settings.| `true` |
| `display-messages` | Display LSP progress messages below statusline[^1] | `false` |
| `display-messages` | Display LSP window/showMessage messages below statusline | `false` |
| `display-progress-messages` | Display LSP progress messages below statusline[^1] | `false` |
| `auto-signature-help` | Enable automatic popup of signature help (parameter hints) | `true` |
| `display-inlay-hints` | Display inlay hints[^2] | `false` |
| `display-signature-help-docs` | Display docs under signature help popup | `true` |
Expand Down
16 changes: 13 additions & 3 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ use helix_core::{
path::get_relative_path,
pos_at_coords, syntax, Selection,
};
use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
use helix_lsp::{
lsp::{self, MessageType},
util::lsp_pos_to_pos,
LspProgressMap,
};
use helix_view::{
align_view,
document::DocumentSavedEventResult,
Expand Down Expand Up @@ -806,7 +810,13 @@ impl Application {
.insert(params.uri, params.diagnostics);
}
Notification::ShowMessage(params) => {
log::warn!("unhandled window/showMessage: {:?}", params);
if self.config.load().editor.lsp.display_messages {
match params.typ {
MessageType::ERROR => self.editor.set_error(params.message),
MessageType::WARNING => self.editor.set_warning(params.message),
_ => self.editor.set_status(params.message),
}
}
}
Notification::LogMessage(params) => {
log::info!("window/logMessage: {:?}", params);
Expand Down Expand Up @@ -890,7 +900,7 @@ impl Application {
self.lsp_progress.update(server_id, token, work);
}

if self.config.load().editor.lsp.display_messages {
if self.config.load().editor.lsp.display_progress_messages {
self.editor.set_status(status);
}
}
Expand Down
12 changes: 11 additions & 1 deletion helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ pub fn get_terminal_provider() -> Option<TerminalConfig> {
pub struct LspConfig {
/// Enables LSP
pub enable: bool,
/// Display LSP progress messages below statusline
/// Display LSP messagess from $/progress below statusline
pub display_progress_messages: bool,
/// Display LSP messages from window/showMessage below statusline
pub display_messages: bool,
/// Enable automatic pop up of signature help (parameter hints)
pub auto_signature_help: bool,
Expand All @@ -353,6 +355,7 @@ impl Default for LspConfig {
fn default() -> Self {
Self {
enable: true,
display_progress_messages: false,
display_messages: false,
auto_signature_help: true,
display_signature_help_docs: true,
Expand Down Expand Up @@ -1022,6 +1025,13 @@ impl Editor {
self.status_msg = Some((error, Severity::Error));
}

#[inline]
pub fn set_warning<T: Into<Cow<'static, str>>>(&mut self, warning: T) {
let warning = warning.into();
log::warn!("editor warning: {}", warning);
self.status_msg = Some((warning, Severity::Warning));
}

#[inline]
pub fn get_status(&self) -> Option<(&Cow<'static, str>, &Severity)> {
self.status_msg.as_ref().map(|(status, sev)| (status, sev))
Expand Down

0 comments on commit 16d1d88

Please sign in to comment.