From 8a04372fec5f26a0650395a1e420fea062b3a7ab Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 20 Apr 2020 16:34:01 +0200 Subject: Fix panic in split_imports assist The fix is admittedly quit literally just papering over. Long-term, I see two more principled approaches: * we switch to a fully tree-based impl, without parse . to_string step; with this approach, there shouldn't be any panics. The results might be nonsensical, but so was the original input. * we preserve the invariant that re-parsing constructed node is an identity, and make all the `make_xxx` method return an `Option`. closes #4044 --- crates/ra_assists/src/handlers/split_import.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/handlers/split_import.rs b/crates/ra_assists/src/handlers/split_import.rs index d9244f22d..f25826796 100644 --- a/crates/ra_assists/src/handlers/split_import.rs +++ b/crates/ra_assists/src/handlers/split_import.rs @@ -37,7 +37,7 @@ pub(crate) fn split_import(ctx: AssistCtx) -> Option { #[cfg(test)] mod tests { - use crate::helpers::{check_assist, check_assist_target}; + use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; use super::*; @@ -63,4 +63,9 @@ mod tests { fn split_import_target() { check_assist_target(split_import, "use crate::<|>db::{RootDatabase, FileSymbol}", "::"); } + + #[test] + fn issue4044() { + check_assist_not_applicable(split_import, "use crate::<|>:::self;") + } } -- cgit v1.2.3