Skip to content

Commit

Permalink
lsp: Do not send status nmessages
Browse files Browse the repository at this point in the history
Nigel says those are annoying as they tend to overstay
their welcome.
  • Loading branch information
hunger committed Feb 11, 2025
1 parent 3fa3154 commit 5cab5f3
Show file tree
Hide file tree
Showing 9 changed files with 2 additions and 138 deletions.
43 changes: 0 additions & 43 deletions editors/vscode/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ import {
NotificationType,
} from "vscode-languageclient";

// server status:
export interface ServerStatusParams {
health: "ok" | "warning" | "error";
quiescent: boolean;
message?: string;
}

export const serverStatus = new NotificationType<ServerStatusParams>(
"experimental/serverStatus",
);

export class ClientHandle {
#client: BaseLanguageClient | null = null;
#updaters: ((c: BaseLanguageClient | null) => void)[] = [];
Expand Down Expand Up @@ -67,33 +56,6 @@ export class ClientHandle {

const client = new ClientHandle();

export function setServerStatus(
status: ServerStatusParams,
statusBar: vscode.StatusBarItem,
) {
let icon = "";
switch (status.health) {
case "ok":
statusBar.color = undefined;
break;
case "warning":
statusBar.color = new vscode.ThemeColor(
"notificationsWarningIcon.foreground",
);
icon = "$(warning) ";
break;
case "error":
statusBar.color = new vscode.ThemeColor(
"notificationsErrorIcon.foreground",
);
icon = "$(error) ";
break;
}
statusBar.tooltip = "Slint";
statusBar.text = `${icon} ${status.message ?? "Slint"}`;
statusBar.show();
}

// LSP related:

// Set up our middleware. It is used to redirect/forward to the WASM preview
Expand Down Expand Up @@ -187,11 +149,6 @@ export function activate(
statusBar.text = "Slint";

client.add_updater((cl) => {
if (cl !== null) {
cl.onNotification(serverStatus, (params: ServerStatusParams) =>
setServerStatus(params, statusBar),
);
}
wasm_preview.initClientForPreview(context, cl);
});

Expand Down
4 changes: 0 additions & 4 deletions editors/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ function startClient(
// Just make sure that the output channel is always present.
cl?.outputChannel.append("");

cl?.onNotification(common.serverStatus, (params: any) =>
common.setServerStatus(params, statusBar),
);

cl?.onDidChangeState((event) => {
const properly_stopped = cl.hasOwnProperty("slint_stopped");
if (
Expand Down
18 changes: 0 additions & 18 deletions tools/lsp/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,6 @@ impl PropertyChange {
#[allow(unused)]
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub enum PreviewToLspMessage {
/// Show a status message in the editor
Status { message: String, health: crate::lsp_ext::Health },
/// Report diagnostics to editor.
Diagnostics { uri: Url, version: SourceFileVersion, diagnostics: Vec<lsp_types::Diagnostic> },
/// Show a document in the editor.
Expand Down Expand Up @@ -583,22 +581,6 @@ impl ComponentInformation {

#[cfg(any(feature = "preview-external", feature = "preview-engine"))]
pub mod lsp_to_editor {
pub fn send_status_notification(
sender: &crate::ServerNotifier,
message: &str,
health: crate::lsp_ext::Health,
) {
sender
.send_notification::<crate::lsp_ext::ServerStatusNotification>(
crate::lsp_ext::ServerStatusParams {
health,
quiescent: false,
message: Some(message.into()),
},
)
.unwrap_or_else(|e| eprintln!("Error sending notification: {e:?}"));
}

pub fn notify_lsp_diagnostics(
sender: &crate::ServerNotifier,
uri: lsp_types::Url,
Expand Down
30 changes: 0 additions & 30 deletions tools/lsp/lsp_ext.rs

This file was deleted.

8 changes: 0 additions & 8 deletions tools/lsp/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ compile_error!("Feature preview-engine and preview-builtin need to be enabled to
mod common;
mod fmt;
mod language;
pub mod lsp_ext;
#[cfg(feature = "preview-engine")]
mod preview;
pub mod util;
Expand Down Expand Up @@ -544,13 +543,6 @@ async fn handle_preview_to_lsp_message(
) -> Result<()> {
use crate::common::PreviewToLspMessage as M;
match message {
M::Status { message, health } => {
crate::common::lsp_to_editor::send_status_notification(
&ctx.server_notifier,
&message,
health,
);
}
M::Diagnostics { uri, version, diagnostics } => {
crate::common::lsp_to_editor::notify_lsp_diagnostics(
&ctx.server_notifier,
Expand Down
12 changes: 2 additions & 10 deletions tools/lsp/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::common::{
self, component_catalog, rename_component, ComponentInformation, ElementRcNode,
PreviewComponent, PreviewConfig, PreviewToLspMessage, SourceFileVersion,
};
use crate::lsp_ext::Health;
use crate::preview::element_selection::ElementSelection;
use crate::util;
use i_slint_compiler::object_tree::ElementRc;
Expand Down Expand Up @@ -967,7 +966,6 @@ fn start_parsing() {
ui::set_diagnostics(ui, &[]);
}
});
send_status("Loading Preview…", Health::Ok);
}

fn extract_resources(
Expand Down Expand Up @@ -997,13 +995,8 @@ fn extract_resources(
result
}

fn finish_parsing(preview_url: &Url, ok: bool) {
fn finish_parsing(preview_url: &Url) {
set_status_text("");
if ok {
send_status("Preview Loaded", Health::Ok);
} else {
send_status("Preview not updated", Health::Error);
}

let (previewed_url, component, source_code) = {
let cache = CONTENT_CACHE.get_or_init(Default::default).lock().unwrap();
Expand Down Expand Up @@ -1398,10 +1391,9 @@ async fn reload_preview_impl(
notify_diagnostics(diags);
}

let success = compiled.is_some();
update_preview_area(compiled, behavior, open_import_fallback, source_file_versions)?;

finish_parsing(&component.url, success);
finish_parsing(&component.url);
Ok(())
}

Expand Down
9 changes: 0 additions & 9 deletions tools/lsp/preview/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::collections::HashMap;

use super::PreviewState;
use crate::common::{PreviewToLspMessage, SourceFileVersion};
use crate::lsp_ext::Health;
use crate::ServerNotifier;
use slint_interpreter::ComponentHandle;
use std::future::Future;
Expand Down Expand Up @@ -252,14 +251,6 @@ pub fn notify_diagnostics(
Some(())
}

pub fn send_status(message: &str, health: Health) {
let Some(sender) = SERVER_NOTIFIER.lock().unwrap().clone() else {
return;
};

crate::common::lsp_to_editor::send_status_notification(&sender, message, health)
}

pub fn ask_editor_to_show_document(file: &str, selection: lsp_types::Range, take_focus: bool) {
let Some(sender) = SERVER_NOTIFIER.lock().unwrap().clone() else {
return;
Expand Down
8 changes: 0 additions & 8 deletions tools/lsp/preview/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use std::collections::HashMap;

use crate::common::SourceFileVersion;
use crate::lsp_ext::Health;
use crate::wasm_prelude::*;
use slint_interpreter::ComponentHandle;
use std::cell::RefCell;
Expand Down Expand Up @@ -210,13 +209,6 @@ pub fn send_message_to_lsp(message: crate::common::PreviewToLspMessage) {
})
}

pub fn send_status(message: &str, health: Health) {
send_message_to_lsp(crate::common::PreviewToLspMessage::Status {
message: message.to_string(),
health,
});
}

pub fn notify_diagnostics(
diagnostics: HashMap<lsp_types::Url, (SourceFileVersion, Vec<lsp_types::Diagnostic>)>,
) -> Option<()> {
Expand Down
8 changes: 0 additions & 8 deletions tools/lsp/wasm_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
pub mod common;
mod fmt;
mod language;
pub mod lsp_ext;
#[cfg(feature = "preview-engine")]
mod preview;
pub mod util;
Expand Down Expand Up @@ -271,13 +270,6 @@ impl SlintServer {
};

match message {
M::Status { message, health } => {
crate::common::lsp_to_editor::send_status_notification(
&self.ctx.server_notifier,
&message,
health,
);
}
M::Diagnostics { diagnostics, version, uri } => {
crate::common::lsp_to_editor::notify_lsp_diagnostics(
&self.ctx.server_notifier,
Expand Down

0 comments on commit 5cab5f3

Please sign in to comment.