mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
Simplify
This commit is contained in:
parent
8dad14b5cd
commit
58c3370819
2 changed files with 18 additions and 23 deletions
|
@ -71,19 +71,6 @@ pub fn handle_request<R, F>(req: &mut Option<RawRequest>, f: F) -> Result<()>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expect_request<R: ClientRequest>(io: &mut Io, raw: RawRequest)
|
|
||||||
-> Result<Option<(R::Params, Responder<R>)>>
|
|
||||||
{
|
|
||||||
let ret = match parse_request_as::<R>(raw)? {
|
|
||||||
Ok(x) => Some(x),
|
|
||||||
Err(raw) => {
|
|
||||||
unknown_method(io, raw)?;
|
|
||||||
None
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Ok(ret)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_notification_as<N>(raw: RawNotification) -> Result<::std::result::Result<N::Params, RawNotification>>
|
fn parse_notification_as<N>(raw: RawNotification) -> Result<::std::result::Result<N::Params, RawNotification>>
|
||||||
where
|
where
|
||||||
N: Notification,
|
N: Notification,
|
||||||
|
|
|
@ -79,10 +79,15 @@ fn initialize(io: &mut Io) -> Result<()> {
|
||||||
loop {
|
loop {
|
||||||
match io.recv()? {
|
match io.recv()? {
|
||||||
RawMsg::Request(req) => {
|
RawMsg::Request(req) => {
|
||||||
if let Some((_params, resp)) = dispatch::expect_request::<req::Initialize>(io, req)? {
|
let mut req = Some(req);
|
||||||
|
dispatch::handle_request::<req::Initialize, _>(&mut req, |_params, resp| {
|
||||||
let res = req::InitializeResult { capabilities: caps::SERVER_CAPABILITIES };
|
let res = req::InitializeResult { capabilities: caps::SERVER_CAPABILITIES };
|
||||||
let resp = resp.into_response(Ok(res))?;
|
let resp = resp.into_response(Ok(res))?;
|
||||||
io.send(RawMsg::Response(resp));
|
io.send(RawMsg::Response(resp));
|
||||||
|
Ok(())
|
||||||
|
})?;
|
||||||
|
match req {
|
||||||
|
None => {
|
||||||
match io.recv()? {
|
match io.recv()? {
|
||||||
RawMsg::Notification(n) => {
|
RawMsg::Notification(n) => {
|
||||||
if n.method != "initialized" {
|
if n.method != "initialized" {
|
||||||
|
@ -95,6 +100,10 @@ fn initialize(io: &mut Io) -> Result<()> {
|
||||||
}
|
}
|
||||||
return initialized(io);
|
return initialized(io);
|
||||||
}
|
}
|
||||||
|
Some(req) => {
|
||||||
|
bail!("expected initialize request, got {:?}", req)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
RawMsg::Notification(n) => {
|
RawMsg::Notification(n) => {
|
||||||
bail!("expected initialize request, got {:?}", n)
|
bail!("expected initialize request, got {:?}", n)
|
||||||
|
@ -106,7 +115,6 @@ fn initialize(io: &mut Io) -> Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enum Task {
|
enum Task {
|
||||||
Respond(RawResponse),
|
Respond(RawResponse),
|
||||||
Notify(RawNotification),
|
Notify(RawNotification),
|
||||||
|
@ -301,7 +309,7 @@ fn update_file_notifications_on_threadpool(
|
||||||
}
|
}
|
||||||
match publish_decorations(world, uri) {
|
match publish_decorations(world, uri) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("failed to compute decortions: {:?}", e)
|
error!("failed to compute decorations: {:?}", e)
|
||||||
}
|
}
|
||||||
Ok(params) => {
|
Ok(params) => {
|
||||||
let not = dispatch::send_notification::<req::PublishDecorations>(params);
|
let not = dispatch::send_notification::<req::PublishDecorations>(params);
|
||||||
|
|
Loading…
Reference in a new issue