Skip to content

Commit f1cf609

Browse files
committed
WIP
1 parent 9f6dab9 commit f1cf609

File tree

2 files changed

+45
-33
lines changed

2 files changed

+45
-33
lines changed

crates/copilot/src/copilot.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use language::{
2323
use lsp::{LanguageServer, LanguageServerBinary, LanguageServerId, LanguageServerName};
2424
use node_runtime::NodeRuntime;
2525
use parking_lot::Mutex;
26-
use request::DidChangeStatus;
26+
use request::{DidChangeStatus, WindowShowMessageRequest};
2727
use settings::SettingsStore;
2828
use sign_in::{reinstall_and_sign_in_within_workspace, sign_out_within_workspace};
2929
use std::{
@@ -503,24 +503,40 @@ impl Copilot {
503503
.on_notification::<DidChangeStatus, _>({
504504
let this = this.clone();
505505
move |params, cx| {
506-
507506
// Convert didChangeStatus to appropriate SignInStatus and update
508507
let sign_in_status = match params.kind.as_str() {
509-
"Error" => Some(request::SignInStatus::NotAuthorized { user: String::new() }),
510-
"Normal" => Some(request::SignInStatus::AlreadySignedIn { user: String::new() }),
508+
"Error" => Some(request::SignInStatus::NotAuthorized {
509+
user: String::new(),
510+
}),
511+
"Normal" => Some(request::SignInStatus::AlreadySignedIn {
512+
user: String::new(),
513+
}),
511514
"Inactive" | "Warning" => None, // Don't change auth status for these
512515
_ => None,
513516
};
514517

515518
if let Some(status) = sign_in_status {
516519
this.update(cx, |this, cx| {
517520
this.update_sign_in_status(status, cx);
518-
}).ok();
521+
})
522+
.ok();
519523
}
520524
}
521525
})
522526
.detach();
523527

528+
server
529+
.on_notification::<WindowShowMessageRequest, _>({
530+
let this = this.clone();
531+
move |params, cx| {
532+
// TODO: Display the message in Zed's UI
533+
534+
// Log the message
535+
log::info!("Copilot {}: {}", params.type_.as_str(), params.message);
536+
}
537+
})
538+
.detach();
539+
524540
let configuration = lsp::DidChangeConfigurationParams {
525541
settings: Default::default(),
526542
};

crates/copilot/src/request.rs

+24-28
Original file line numberDiff line numberDiff line change
@@ -224,46 +224,42 @@ impl lsp::notification::Notification for DidChangeStatus {
224224
const METHOD: &'static str = "didChangeStatus";
225225
}
226226

227-
// Standard LSP window/logMessage notification
228-
pub enum WindowLogMessage {}
227+
// Standard LSP window/showMessageRequest request
228+
pub enum WindowShowMessageRequest {}
229229

230230
#[derive(Debug, Serialize, Deserialize)]
231-
pub struct WindowLogMessageParams {
231+
pub struct ShowMessageParams {
232232
/// The message type. See {@link MessageType}
233233
#[serde(rename = "type")]
234-
pub type_: i32,
234+
pub type_: MessageType,
235235
/// The actual message
236236
pub message: String,
237237
}
238238

239-
impl lsp::notification::Notification for WindowLogMessage {
240-
type Params = WindowLogMessageParams;
241-
const METHOD: &'static str = "window/logMessage";
239+
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
240+
#[repr(i32)]
241+
pub enum MessageType {
242+
Error = 1,
243+
Warning = 2,
244+
Info = 3,
245+
Log = 4,
246+
Debug = 5,
242247
}
243248

244-
// Standard LSP window/showMessageRequest request
245-
pub enum WindowShowMessageRequest {}
246-
247-
#[derive(Debug, Serialize, Deserialize)]
248-
pub struct MessageActionItem {
249-
/// A short title like 'Retry', 'Open Log' etc.
250-
pub title: String,
251-
}
252-
253-
#[derive(Debug, Serialize, Deserialize)]
254-
pub struct WindowShowMessageRequestParams {
255-
/// The message type. See {@link MessageType}
256-
#[serde(rename = "type")]
257-
pub type_: i32,
258-
/// The actual message
259-
pub message: String,
260-
/// The message action items to present.
261-
pub actions: Option<Vec<MessageActionItem>>,
249+
impl MessageType {
250+
pub fn as_str(&self) -> &'static str {
251+
match self {
252+
MessageType::Error => "Error",
253+
MessageType::Warning => "Warning",
254+
MessageType::Info => "Info",
255+
MessageType::Log => "Log",
256+
MessageType::Debug => "Debug",
257+
}
258+
}
262259
}
263260

264-
impl lsp::request::Request for WindowShowMessageRequest {
265-
type Params = WindowShowMessageRequestParams;
266-
type Result = Option<MessageActionItem>;
261+
impl lsp::notification::Notification for WindowShowMessageRequest {
262+
type Params = ShowMessageParams;
267263
const METHOD: &'static str = "window/showMessageRequest";
268264
}
269265

0 commit comments

Comments
 (0)