From 90fc32937785b3f17899f14d8cb2f7b3738a9850 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 3 May 2021 19:35:44 +0300 Subject: Index retrieval fix --- crates/ide_assists/src/lib.rs | 2 +- crates/rust-analyzer/src/handlers.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ide_assists/src/lib.rs b/crates/ide_assists/src/lib.rs index 723531078..2e0c58504 100644 --- a/crates/ide_assists/src/lib.rs +++ b/crates/ide_assists/src/lib.rs @@ -102,7 +102,7 @@ pub enum AssistResolveStrategy { None, /// All assists should be resolved. All, - /// Only a certain assists should be resolved. + /// Only a certain assist should be resolved. Single(SingleResolve), } diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 77faf7579..0fd03bbaa 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -1076,7 +1076,17 @@ pub(crate) fn handle_code_action_resolve( frange, )?; - let assist = &assists[params.index]; + let assist = match assists.get(params.index) { + Some(assist) => assist, + None => return Err(LspError::new( + ErrorCode::InvalidParams as i32, + format!( + "Failed to find the assist for index {} provided by the resolve request. Expected assist id: {:?}", + params.index, params.id, + ), + ) + .into()) + }; if assist.id.0 != params.id || assist.id.1 != assist_kind { return Err(LspError::new( ErrorCode::InvalidParams as i32, -- cgit v1.2.3