Downgrade callable snippet items to plain-name insertions. When `(` already follows the cursor, snippets that insert their own parentheses would produce duplicates. This strips the snippet format and replaces the insert text with just the name from `filter_text`. Applies to methods, functions, and class names (for `new` / `throw new`).
(items: Vec<CompletionItem>)
| 99 | /// |
| 100 | /// Applies to methods, functions, and class names (for `new` / `throw new`). |
| 101 | fn strip_snippet_parens(items: Vec<CompletionItem>) -> Vec<CompletionItem> { |
| 102 | items |
| 103 | .into_iter() |
| 104 | .map(|mut item| { |
| 105 | if item.insert_text_format == Some(InsertTextFormat::SNIPPET) |
| 106 | && matches!( |
| 107 | item.kind, |
| 108 | Some(CompletionItemKind::METHOD) |
| 109 | | Some(CompletionItemKind::FUNCTION) |
| 110 | | Some(CompletionItemKind::CLASS) |
| 111 | ) |
| 112 | { |
| 113 | // Replace the snippet with just the name |
| 114 | // (the filter_text already holds it). |
| 115 | if let Some(ref name) = item.filter_text { |
| 116 | item.insert_text = Some(name.clone()); |
| 117 | } |
| 118 | // Also clear any text_edit that carries the snippet text. |
| 119 | if let Some(CompletionTextEdit::Edit(ref mut te)) = item.text_edit |
| 120 | && let Some(ref name) = item.filter_text |
| 121 | { |
| 122 | te.new_text = name.clone(); |
| 123 | } |
| 124 | item.insert_text_format = None; |
| 125 | } |
| 126 | item |
| 127 | }) |
| 128 | .collect() |
| 129 | } |
| 130 | |
| 131 | /// Filter out completion items for classes defined in the current file. |
| 132 | /// |
no test coverage detected