|
1 | 1 | //! Renderer for function calls.
|
2 | 2 |
|
3 |
| -use std::ops::ControlFlow; |
4 |
| - |
5 | 3 | use hir::{db::HirDatabase, AsAssocItem, HirDisplay};
|
6 | 4 | use ide_db::{SnippetCap, SymbolKind};
|
7 | 5 | use itertools::Itertools;
|
8 | 6 | use stdx::{format_to, to_lower_snake_case};
|
9 |
| -use syntax::{ast, format_smolstr, match_ast, AstNode, Edition, SmolStr, SyntaxKind, ToSmolStr, T}; |
| 7 | +use syntax::{format_smolstr, AstNode, Edition, SmolStr, ToSmolStr}; |
10 | 8 |
|
11 | 9 | use crate::{
|
12 |
| - context::{CompletionContext, DotAccess, DotAccessKind, PathCompletionCtx, PathKind}, |
| 10 | + context::{ |
| 11 | + CompleteSemicolon, CompletionContext, DotAccess, DotAccessKind, PathCompletionCtx, PathKind, |
| 12 | + }, |
13 | 13 | item::{
|
14 | 14 | Builder, CompletionItem, CompletionItemKind, CompletionRelevance, CompletionRelevanceFn,
|
15 | 15 | CompletionRelevanceReturnType, CompletionRelevanceTraitInfo,
|
@@ -277,40 +277,16 @@ pub(super) fn add_call_parens<'b>(
|
277 | 277 |
|
278 | 278 | (snippet, "(…)")
|
279 | 279 | };
|
280 |
| - if ret_type.is_unit() && ctx.config.add_semicolon_to_unit { |
281 |
| - let inside_closure_ret = ctx.token.parent_ancestors().try_for_each(|ancestor| { |
282 |
| - match_ast! { |
283 |
| - match ancestor { |
284 |
| - ast::BlockExpr(_) => ControlFlow::Break(false), |
285 |
| - ast::ClosureExpr(_) => ControlFlow::Break(true), |
286 |
| - _ => ControlFlow::Continue(()) |
287 |
| - } |
288 |
| - } |
289 |
| - }); |
290 |
| - |
291 |
| - if inside_closure_ret != ControlFlow::Break(true) { |
292 |
| - let next_non_trivia_token = |
293 |
| - std::iter::successors(ctx.token.next_token(), |it| it.next_token()) |
294 |
| - .find(|it| !it.kind().is_trivia()); |
295 |
| - let in_match_arm = ctx.token.parent_ancestors().try_for_each(|ancestor| { |
296 |
| - if ast::MatchArm::can_cast(ancestor.kind()) { |
297 |
| - ControlFlow::Break(true) |
298 |
| - } else if matches!(ancestor.kind(), SyntaxKind::EXPR_STMT | SyntaxKind::BLOCK_EXPR) |
299 |
| - { |
300 |
| - ControlFlow::Break(false) |
301 |
| - } else { |
302 |
| - ControlFlow::Continue(()) |
303 |
| - } |
304 |
| - }); |
305 |
| - // FIXME: This will assume expr macros are not inside match, we need to somehow go to the "parent" of the root node. |
306 |
| - let in_match_arm = match in_match_arm { |
307 |
| - ControlFlow::Continue(()) => false, |
308 |
| - ControlFlow::Break(it) => it, |
309 |
| - }; |
310 |
| - let complete_token = if in_match_arm { T![,] } else { T![;] }; |
311 |
| - if next_non_trivia_token.map(|it| it.kind()) != Some(complete_token) { |
| 280 | + if ret_type.is_unit() { |
| 281 | + match ctx.complete_semicolon { |
| 282 | + CompleteSemicolon::DoNotComplete => {} |
| 283 | + CompleteSemicolon::CompleteSemi | CompleteSemicolon::CompleteComma => { |
312 | 284 | cov_mark::hit!(complete_semicolon);
|
313 |
| - let ch = if in_match_arm { ',' } else { ';' }; |
| 285 | + let ch = if matches!(ctx.complete_semicolon, CompleteSemicolon::CompleteComma) { |
| 286 | + ',' |
| 287 | + } else { |
| 288 | + ';' |
| 289 | + }; |
314 | 290 | if snippet.ends_with("$0") {
|
315 | 291 | snippet.insert(snippet.len() - "$0".len(), ch);
|
316 | 292 | } else {
|
|
0 commit comments