@@ -10,7 +10,6 @@ mod document;
10
10
mod keyword;
11
11
pub ( crate ) mod pipe;
12
12
mod search_path;
13
- mod snippets;
14
13
mod subset;
15
14
mod workspace;
16
15
@@ -27,6 +26,23 @@ use crate::lsp::completions::sources::CompletionSource;
27
26
use crate :: treesitter:: NodeType ;
28
27
use crate :: treesitter:: NodeTypeExt ;
29
28
29
+ #[ derive( Clone , Hash , PartialEq , Eq ) ]
30
+ struct CompletionItemKey {
31
+ label : String ,
32
+ kind_str : String ,
33
+ }
34
+
35
+ impl CompletionItemKey {
36
+ fn new ( item : & CompletionItem ) -> Self {
37
+ Self {
38
+ label : item. label . clone ( ) ,
39
+ kind_str : item
40
+ . kind
41
+ . map_or_else ( || "Text" . to_string ( ) , |k| format ! ( "{:?}" , k) ) ,
42
+ }
43
+ }
44
+ }
45
+
30
46
// Locally useful data structure for tracking completions and their source
31
47
#[ derive( Clone , Default ) ]
32
48
struct CompletionItemWithSource {
@@ -60,12 +76,6 @@ pub(crate) fn get_completions(
60
76
if is_identifier_like ( completion_context. document_context . node ) {
61
77
push_completions ( keyword:: KeywordSource , completion_context, & mut completions) ?;
62
78
63
- push_completions (
64
- snippets:: SnippetSource ,
65
- completion_context,
66
- & mut completions,
67
- ) ?;
68
-
69
79
push_completions (
70
80
search_path:: SearchPathSource ,
71
81
completion_context,
@@ -94,7 +104,7 @@ pub(crate) fn get_completions(
94
104
fn push_completions < S > (
95
105
source : S ,
96
106
completion_context : & CompletionContext ,
97
- completions : & mut HashMap < String , CompletionItemWithSource > ,
107
+ completions : & mut HashMap < CompletionItemKey , CompletionItemWithSource > ,
98
108
) -> anyhow:: Result < ( ) >
99
109
where
100
110
S : CompletionSource ,
@@ -103,15 +113,17 @@ where
103
113
104
114
if let Some ( source_completions) = collect_completions ( source, completion_context) ? {
105
115
for item in source_completions {
106
- if let Some ( existing) = completions. get ( & item. label ) {
116
+ let key = CompletionItemKey :: new ( & item) ;
117
+ if let Some ( existing) = completions. get ( & key) {
107
118
log:: trace!(
108
- "Completion with label '{}' already exists (first contributed by source: {}, now also from: {})" ,
109
- item. label,
119
+ "Completion with label '{}' and kind '{:?}' already exists (first contributed by source: {}, now also from: {})" ,
120
+ key. label,
121
+ key. kind_str,
110
122
existing. source,
111
123
source_name
112
124
) ;
113
125
} else {
114
- completions. insert ( item . label . clone ( ) , CompletionItemWithSource {
126
+ completions. insert ( key , CompletionItemWithSource {
115
127
item,
116
128
source : source_name. to_string ( ) ,
117
129
} ) ;
@@ -124,7 +136,7 @@ where
124
136
125
137
/// Produce plain old CompletionItems and sort them
126
138
fn finalize_completions (
127
- completions : HashMap < String , CompletionItemWithSource > ,
139
+ completions : HashMap < CompletionItemKey , CompletionItemWithSource > ,
128
140
) -> Vec < CompletionItem > {
129
141
let mut items: Vec < CompletionItem > = completions
130
142
. into_values ( )
@@ -183,8 +195,7 @@ fn is_identifier_like(x: Node) -> bool {
183
195
// non-`identifier` kinds. However, we do still want to provide completions
184
196
// here, especially in two cases:
185
197
// - `for<tab>` should provide completions for things like `forcats`
186
- // - `for<tab>` should provide snippet completions for the `for` snippet
187
- // The keywords here come from matching snippets in `r.code-snippets`.
198
+ // - completions of certain reserved words from the keyword source
188
199
if matches ! ( x. node_type( ) , NodeType :: Anonymous ( kind) if matches!( kind. as_str( ) , "if" | "for" | "while" ) )
189
200
{
190
201
return true ;
@@ -208,7 +219,7 @@ mod tests {
208
219
fn test_completions_on_anonymous_node_keywords ( ) {
209
220
r_task ( || {
210
221
// `if`, `for`, and `while` in particular are both tree-sitter
211
- // anonymous nodes and snippet keywords, so they need to look like
222
+ // anonymous nodes and keywords, so they need to look like
212
223
// identifiers that we provide completions for
213
224
for keyword in [ "if" , "for" , "while" ] {
214
225
let point = Point { row : 0 , column : 0 } ;
0 commit comments