summaryrefslogtreecommitdiffstats
path: root/src/tools/rust-analyzer/lib
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
commita4b7ed7a42c716ab9f05e351f003d589124fd55d (patch)
treeb620cd3f223850b28716e474e80c58059dca5dd4 /src/tools/rust-analyzer/lib
parentAdding upstream version 1.67.1+dfsg1. (diff)
downloadrustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.tar.xz
rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.zip
Adding upstream version 1.68.2+dfsg1.upstream/1.68.2+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/rust-analyzer/lib')
-rw-r--r--src/tools/rust-analyzer/lib/la-arena/src/map.rs8
-rw-r--r--src/tools/rust-analyzer/lib/lsp-server/examples/goto_def.rs12
-rw-r--r--src/tools/rust-analyzer/lib/lsp-server/src/lib.rs40
3 files changed, 25 insertions, 35 deletions
diff --git a/src/tools/rust-analyzer/lib/la-arena/src/map.rs b/src/tools/rust-analyzer/lib/la-arena/src/map.rs
index 5f347e274..b9d491da3 100644
--- a/src/tools/rust-analyzer/lib/la-arena/src/map.rs
+++ b/src/tools/rust-analyzer/lib/la-arena/src/map.rs
@@ -86,6 +86,14 @@ impl<T, V> ArenaMap<Idx<T>, V> {
self.v.iter().enumerate().filter_map(|(idx, o)| Some((Self::from_idx(idx), o.as_ref()?)))
}
+ /// Returns an iterator over the arena indexes and values in the map.
+ pub fn iter_mut(&mut self) -> impl Iterator<Item = (Idx<T>, &mut V)> {
+ self.v
+ .iter_mut()
+ .enumerate()
+ .filter_map(|(idx, o)| Some((Self::from_idx(idx), o.as_mut()?)))
+ }
+
/// Gets the given key's corresponding entry in the map for in-place manipulation.
pub fn entry(&mut self, idx: Idx<T>) -> Entry<'_, Idx<T>, V> {
let idx = Self::to_idx(idx);
diff --git a/src/tools/rust-analyzer/lib/lsp-server/examples/goto_def.rs b/src/tools/rust-analyzer/lib/lsp-server/examples/goto_def.rs
index ca7ad0b53..2f270afbb 100644
--- a/src/tools/rust-analyzer/lib/lsp-server/examples/goto_def.rs
+++ b/src/tools/rust-analyzer/lib/lsp-server/examples/goto_def.rs
@@ -80,32 +80,32 @@ fn main_loop(
let _params: InitializeParams = serde_json::from_value(params).unwrap();
eprintln!("starting example main loop");
for msg in &connection.receiver {
- eprintln!("got msg: {:?}", msg);
+ eprintln!("got msg: {msg:?}");
match msg {
Message::Request(req) => {
if connection.handle_shutdown(&req)? {
return Ok(());
}
- eprintln!("got request: {:?}", req);
+ eprintln!("got request: {req:?}");
match cast::<GotoDefinition>(req) {
Ok((id, params)) => {
- eprintln!("got gotoDefinition request #{}: {:?}", id, params);
+ eprintln!("got gotoDefinition request #{id}: {params:?}");
let result = Some(GotoDefinitionResponse::Array(Vec::new()));
let result = serde_json::to_value(&result).unwrap();
let resp = Response { id, result: Some(result), error: None };
connection.sender.send(Message::Response(resp))?;
continue;
}
- Err(err @ ExtractError::JsonError { .. }) => panic!("{:?}", err),
+ Err(err @ ExtractError::JsonError { .. }) => panic!("{err:?}"),
Err(ExtractError::MethodMismatch(req)) => req,
};
// ...
}
Message::Response(resp) => {
- eprintln!("got response: {:?}", resp);
+ eprintln!("got response: {resp:?}");
}
Message::Notification(not) => {
- eprintln!("got notification: {:?}", not);
+ eprintln!("got notification: {not:?}");
}
}
}
diff --git a/src/tools/rust-analyzer/lib/lsp-server/src/lib.rs b/src/tools/rust-analyzer/lib/lsp-server/src/lib.rs
index d567077d4..beccde40a 100644
--- a/src/tools/rust-analyzer/lib/lsp-server/src/lib.rs
+++ b/src/tools/rust-analyzer/lib/lsp-server/src/lib.rs
@@ -114,30 +114,21 @@ impl Connection {
/// ```
pub fn initialize_start(&self) -> Result<(RequestId, serde_json::Value), ProtocolError> {
loop {
- match self.receiver.recv() {
- Ok(Message::Request(req)) if req.is_initialize() => {
- return Ok((req.id, req.params))
- }
+ break match self.receiver.recv() {
+ Ok(Message::Request(req)) if req.is_initialize() => Ok((req.id, req.params)),
// Respond to non-initialize requests with ServerNotInitialized
Ok(Message::Request(req)) => {
let resp = Response::new_err(
req.id.clone(),
ErrorCode::ServerNotInitialized as i32,
- format!("expected initialize request, got {:?}", req),
+ format!("expected initialize request, got {req:?}"),
);
self.sender.send(resp.into()).unwrap();
+ continue;
}
- Ok(msg) => {
- return Err(ProtocolError(format!(
- "expected initialize request, got {:?}",
- msg
- )))
- }
+ Ok(msg) => Err(ProtocolError(format!("expected initialize request, got {msg:?}"))),
Err(e) => {
- return Err(ProtocolError(format!(
- "expected initialize request, got error: {}",
- e
- )))
+ Err(ProtocolError(format!("expected initialize request, got error: {e}")))
}
};
}
@@ -152,21 +143,14 @@ impl Connection {
let resp = Response::new_ok(initialize_id, initialize_result);
self.sender.send(resp.into()).unwrap();
match &self.receiver.recv() {
- Ok(Message::Notification(n)) if n.is_initialized() => (),
+ Ok(Message::Notification(n)) if n.is_initialized() => Ok(()),
Ok(msg) => {
- return Err(ProtocolError(format!(
- "expected Message::Notification, got: {:?}",
- msg,
- )))
+ Err(ProtocolError(format!(r#"expected initialized notification, got: {msg:?}"#)))
}
Err(e) => {
- return Err(ProtocolError(format!(
- "expected initialized notification, got error: {}",
- e,
- )))
+ Err(ProtocolError(format!("expected initialized notification, got error: {e}",)))
}
}
- Ok(())
}
/// Initialize the connection. Sends the server capabilities
@@ -221,11 +205,9 @@ impl Connection {
match &self.receiver.recv_timeout(std::time::Duration::from_secs(30)) {
Ok(Message::Notification(n)) if n.is_exit() => (),
Ok(msg) => {
- return Err(ProtocolError(format!("unexpected message during shutdown: {:?}", msg)))
- }
- Err(e) => {
- return Err(ProtocolError(format!("unexpected error during shutdown: {}", e)))
+ return Err(ProtocolError(format!("unexpected message during shutdown: {msg:?}")))
}
+ Err(e) => return Err(ProtocolError(format!("unexpected error during shutdown: {e}"))),
}
Ok(true)
}