From 3a1f8e897bc2af56cd7a6c08bad1bf88cc97b257 Mon Sep 17 00:00:00 2001 From: Nick Spain Date: Fri, 1 Jan 2021 17:30:13 +1100 Subject: Remove source_old from adding const and function impls --- crates/completion/src/completions/trait_impl.rs | 49 +++++++++++++------------ 1 file changed, 26 insertions(+), 23 deletions(-) (limited to 'crates/completion/src/completions') diff --git a/crates/completion/src/completions/trait_impl.rs b/crates/completion/src/completions/trait_impl.rs index 43b3d939f..54bb897e9 100644 --- a/crates/completion/src/completions/trait_impl.rs +++ b/crates/completion/src/completions/trait_impl.rs @@ -156,20 +156,21 @@ fn add_function_impl( }; let range = TextRange::new(fn_def_node.text_range().start(), ctx.source_range().end()); - #[allow(deprecated)] - let function_decl = function_declaration(&func.source_old(ctx.db).value); - match ctx.config.snippet_cap { - Some(cap) => { - let snippet = format!("{} {{\n $0\n}}", function_decl); - builder.snippet_edit(cap, TextEdit::replace(range, snippet)) - } - None => { - let header = format!("{} {{", function_decl); - builder.text_edit(TextEdit::replace(range, header)) + if let Some(src) = func.source(ctx.db) { + let function_decl = function_declaration(&src.value); + match ctx.config.snippet_cap { + Some(cap) => { + let snippet = format!("{} {{\n $0\n}}", function_decl); + builder.snippet_edit(cap, TextEdit::replace(range, snippet)) + } + None => { + let header = format!("{} {{", function_decl); + builder.text_edit(TextEdit::replace(range, header)) + } } + .kind(completion_kind) + .add_to(acc); } - .kind(completion_kind) - .add_to(acc); } fn add_type_alias_impl( @@ -201,17 +202,19 @@ fn add_const_impl( let const_name = const_.name(ctx.db).map(|n| n.to_string()); if let Some(const_name) = const_name { - #[allow(deprecated)] - let snippet = make_const_compl_syntax(&const_.source_old(ctx.db).value); - - let range = TextRange::new(const_def_node.text_range().start(), ctx.source_range().end()); - - CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone()) - .text_edit(TextEdit::replace(range, snippet)) - .lookup_by(const_name) - .kind(CompletionItemKind::Const) - .set_documentation(const_.docs(ctx.db)) - .add_to(acc); + if let Some(source) = const_.source(ctx.db) { + let snippet = make_const_compl_syntax(&source.value); + + let range = + TextRange::new(const_def_node.text_range().start(), ctx.source_range().end()); + + CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone()) + .text_edit(TextEdit::replace(range, snippet)) + .lookup_by(const_name) + .kind(CompletionItemKind::Const) + .set_documentation(const_.docs(ctx.db)) + .add_to(acc); + } } } -- cgit v1.2.3