From 2cf161266941eac300ae66a633ead26f5109ea16 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Fri, 5 Feb 2021 16:32:34 +0100 Subject: Add `find_or_create_impl_block` to assist utils --- crates/assists/src/utils.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'crates/assists/src/utils.rs') diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index 3842558d8..8045aac40 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs @@ -274,10 +274,11 @@ pub(crate) fn does_pat_match_variant(pat: &ast::Pat, var: &ast::Pat) -> bool { // Uses a syntax-driven approach to find any impl blocks for the struct that // exist within the module/file // -// Returns `None` if we've found an existing `new` fn +// Returns `None` if we've found an existing fn // // FIXME: change the new fn checking to a more semantic approach when that's more // viable (e.g. we process proc macros, etc) +// FIXME: this partially overlaps with `find_impl_block` pub(crate) fn find_struct_impl( ctx: &AssistContext, strukt: &ast::AdtDef, @@ -338,3 +339,18 @@ fn has_fn(imp: &ast::Impl, rhs_name: &str) -> bool { false } + +/// Find the start of the `impl` block for the given `ast::Impl`. +// +// FIXME: add a way to find the end of the `impl` block. +// FIXME: this partially overlaps with `find_struct_impl` +pub(crate) fn find_impl_block(impl_def: ast::Impl, buf: &mut String) -> Option { + buf.push('\n'); + let start = impl_def + .syntax() + .descendants_with_tokens() + .find(|t| t.kind() == T!['{'])? + .text_range() + .end(); + Some(start) +} -- cgit v1.2.3