mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
Avoid clones
This commit is contained in:
parent
80be61ed78
commit
1329dd4e28
4 changed files with 14 additions and 14 deletions
|
@ -51,7 +51,7 @@ pub fn run_server(
|
|||
pub fn handle_shutdown(req: RawRequest, sender: &Sender<RawMessage>) -> Option<RawRequest> {
|
||||
match req.cast::<Shutdown>() {
|
||||
Ok((id, ())) => {
|
||||
let resp = RawResponse::ok::<Shutdown>(id, ());
|
||||
let resp = RawResponse::ok::<Shutdown>(id, &());
|
||||
sender.send(RawMessage::Response(resp));
|
||||
None
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ fn initialize(
|
|||
msg =>
|
||||
bail!("expected initialize request, got {:?}", msg),
|
||||
};
|
||||
let resp = RawResponse::ok::<Initialize>(id, InitializeResult { capabilities: caps });
|
||||
let resp = RawResponse::ok::<Initialize>(id, &InitializeResult { capabilities: caps });
|
||||
sender.send(RawMessage::Response(resp));
|
||||
match receiver.recv() {
|
||||
Some(RawMessage::Notification(n)) => {
|
||||
|
|
|
@ -88,7 +88,7 @@ impl RawMessage {
|
|||
}
|
||||
|
||||
impl RawRequest {
|
||||
pub fn new<R>(id: u64, params: R::Params) -> RawRequest
|
||||
pub fn new<R>(id: u64, params: &R::Params) -> RawRequest
|
||||
where
|
||||
R: Request,
|
||||
R::Params: Serialize,
|
||||
|
@ -96,7 +96,7 @@ impl RawRequest {
|
|||
RawRequest {
|
||||
id: id,
|
||||
method: R::METHOD.to_string(),
|
||||
params: to_value(¶ms).unwrap(),
|
||||
params: to_value(params).unwrap(),
|
||||
}
|
||||
}
|
||||
pub fn cast<R>(self) -> ::std::result::Result<(u64, R::Params), RawRequest>
|
||||
|
@ -114,7 +114,7 @@ impl RawRequest {
|
|||
}
|
||||
|
||||
impl RawResponse {
|
||||
pub fn ok<R>(id: u64, result: R::Result) -> RawResponse
|
||||
pub fn ok<R>(id: u64, result: &R::Result) -> RawResponse
|
||||
where R: Request,
|
||||
R::Result: Serialize,
|
||||
{
|
||||
|
@ -135,14 +135,14 @@ impl RawResponse {
|
|||
}
|
||||
|
||||
impl RawNotification {
|
||||
pub fn new<N>(params: N::Params) -> RawNotification
|
||||
pub fn new<N>(params: &N::Params) -> RawNotification
|
||||
where
|
||||
N: Notification,
|
||||
N::Params: Serialize,
|
||||
{
|
||||
RawNotification {
|
||||
method: N::METHOD.to_string(),
|
||||
params: to_value(¶ms).unwrap(),
|
||||
params: to_value(params).unwrap(),
|
||||
}
|
||||
}
|
||||
pub fn cast<N>(self) -> ::std::result::Result<N::Params, RawNotification>
|
||||
|
|
|
@ -130,7 +130,7 @@ fn main_loop_inner(
|
|||
Event::Ws(ws) => {
|
||||
match ws {
|
||||
Ok(ws) => {
|
||||
let not = RawNotification::new::<req::DidReloadWorkspace>(vec![ws.clone()]);
|
||||
let not = RawNotification::new::<req::DidReloadWorkspace>(&vec![ws.clone()]);
|
||||
msg_sender.send(RawMessage::Notification(not));
|
||||
state.set_workspaces(vec![ws]);
|
||||
state_changed = true;
|
||||
|
@ -288,7 +288,7 @@ fn on_notification(
|
|||
let file_id = state.remove_mem_file(path.as_path())?;
|
||||
subs.remove_sub(file_id);
|
||||
let params = req::PublishDiagnosticsParams { uri, diagnostics: Vec::new() };
|
||||
let not = RawNotification::new::<req::PublishDiagnostics>(params);
|
||||
let not = RawNotification::new::<req::PublishDiagnostics>(¶ms);
|
||||
msg_sender.send(RawMessage::Notification(not));
|
||||
return Ok(())
|
||||
}
|
||||
|
@ -326,7 +326,7 @@ impl<'a> PoolDispatcher<'a> {
|
|||
let sender = self.sender.clone();
|
||||
self.pool.execute(move || {
|
||||
let resp = match f(world, params, token) {
|
||||
Ok(resp) => RawResponse::ok::<R>(id, resp),
|
||||
Ok(resp) => RawResponse::ok::<R>(id, &resp),
|
||||
Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()),
|
||||
};
|
||||
let task = Task::Respond(resp);
|
||||
|
@ -363,7 +363,7 @@ fn update_file_notifications_on_threadpool(
|
|||
error!("failed to compute diagnostics: {:?}", e)
|
||||
}
|
||||
Ok(params) => {
|
||||
let not = RawNotification::new::<req::PublishDiagnostics>(params);
|
||||
let not = RawNotification::new::<req::PublishDiagnostics>(¶ms);
|
||||
sender.send(Task::Notify(not));
|
||||
}
|
||||
}
|
||||
|
@ -372,7 +372,7 @@ fn update_file_notifications_on_threadpool(
|
|||
error!("failed to compute decorations: {:?}", e)
|
||||
}
|
||||
Ok(params) => {
|
||||
let not = RawNotification::new::<req::PublishDecorations>(params);
|
||||
let not = RawNotification::new::<req::PublishDecorations>(¶ms);
|
||||
sender.send(Task::Notify(not))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ impl Server {
|
|||
};
|
||||
for (path, text) in files {
|
||||
res.send_notification(RawNotification::new::<DidOpenTextDocument>(
|
||||
DidOpenTextDocumentParams {
|
||||
&DidOpenTextDocumentParams {
|
||||
text_document: TextDocumentItem {
|
||||
uri: Url::from_file_path(path).unwrap(),
|
||||
language_id: "rust".to_string(),
|
||||
|
@ -149,7 +149,7 @@ impl Server {
|
|||
R: Request,
|
||||
R::Params: Serialize,
|
||||
{
|
||||
let r = RawRequest::new::<R>(id, params);
|
||||
let r = RawRequest::new::<R>(id, ¶ms);
|
||||
self.sender.as_ref()
|
||||
.unwrap()
|
||||
.send(RawMessage::Request(r));
|
||||
|
|
Loading…
Reference in a new issue