@@ -18,9 +18,10 @@ use crate::{
18
18
/// editor pop-up. It is basically a POD with various properties. To construct a
19
19
/// [`CompletionItem`], use [`Builder::new`] method and the [`Builder`] struct.
20
20
#[ derive( Clone ) ]
21
+ #[ non_exhaustive]
21
22
pub struct CompletionItem {
22
23
/// Label in the completion pop up which identifies completion.
23
- label : SmolStr ,
24
+ pub label : SmolStr ,
24
25
/// Range of identifier that is being completed.
25
26
///
26
27
/// It should be used primarily for UI, but we also use this to convert
@@ -29,33 +30,33 @@ pub struct CompletionItem {
29
30
/// `source_range` must contain the completion offset. `text_edit` should
30
31
/// start with what `source_range` points to, or VSCode will filter out the
31
32
/// completion silently.
32
- source_range : TextRange ,
33
+ pub source_range : TextRange ,
33
34
/// What happens when user selects this item.
34
35
///
35
36
/// Typically, replaces `source_range` with new identifier.
36
- text_edit : TextEdit ,
37
- is_snippet : bool ,
37
+ pub text_edit : TextEdit ,
38
+ pub is_snippet : bool ,
38
39
39
40
/// What item (struct, function, etc) are we completing.
40
- kind : CompletionItemKind ,
41
+ pub kind : CompletionItemKind ,
41
42
42
43
/// Lookup is used to check if completion item indeed can complete current
43
44
/// ident.
44
45
///
45
46
/// That is, in `foo.bar$0` lookup of `abracadabra` will be accepted (it
46
47
/// contains `bar` sub sequence), and `quux` will rejected.
47
- lookup : Option < SmolStr > ,
48
+ pub lookup : Option < SmolStr > ,
48
49
49
50
/// Additional info to show in the UI pop up.
50
- detail : Option < String > ,
51
- documentation : Option < Documentation > ,
51
+ pub detail : Option < String > ,
52
+ pub documentation : Option < Documentation > ,
52
53
53
54
/// Whether this item is marked as deprecated
54
- deprecated : bool ,
55
+ pub deprecated : bool ,
55
56
56
57
/// If completing a function call, ask the editor to show parameter popup
57
58
/// after completion.
58
- trigger_call_info : bool ,
59
+ pub trigger_call_info : bool ,
59
60
60
61
/// We use this to sort completion. Relevance records facts like "do the
61
62
/// types align precisely?". We can't sort by relevances directly, they are
@@ -64,36 +65,39 @@ pub struct CompletionItem {
64
65
/// Note that Relevance ignores fuzzy match score. We compute Relevance for
65
66
/// all possible items, and then separately build an ordered completion list
66
67
/// based on relevance and fuzzy matching with the already typed identifier.
67
- relevance : CompletionRelevance ,
68
+ pub relevance : CompletionRelevance ,
68
69
69
70
/// Indicates that a reference or mutable reference to this variable is a
70
71
/// possible match.
71
- ref_match : Option < ( Mutability , TextSize ) > ,
72
+ // FIXME: We shouldn't expose Mutability here (that is HIR types at all), its fine for now though
73
+ // until we have more splitting completions in which case we should think about
74
+ // generalizing this. See https://github.com/rust-lang/rust-analyzer/issues/12571
75
+ pub ref_match : Option < ( Mutability , TextSize ) > ,
72
76
73
77
/// The import data to add to completion's edits.
74
- import_to_add : SmallVec < [ LocatedImport ; 1 ] > ,
78
+ pub import_to_add : SmallVec < [ LocatedImport ; 1 ] > ,
75
79
}
76
80
77
81
// We use custom debug for CompletionItem to make snapshot tests more readable.
78
82
impl fmt:: Debug for CompletionItem {
79
83
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
80
84
let mut s = f. debug_struct ( "CompletionItem" ) ;
81
- s. field ( "label" , & self . label ( ) ) . field ( "source_range" , & self . source_range ( ) ) ;
82
- if self . text_edit ( ) . len ( ) == 1 {
83
- let atom = & self . text_edit ( ) . iter ( ) . next ( ) . unwrap ( ) ;
85
+ s. field ( "label" , & self . label ) . field ( "source_range" , & self . source_range ) ;
86
+ if self . text_edit . len ( ) == 1 {
87
+ let atom = & self . text_edit . iter ( ) . next ( ) . unwrap ( ) ;
84
88
s. field ( "delete" , & atom. delete ) ;
85
89
s. field ( "insert" , & atom. insert ) ;
86
90
} else {
87
91
s. field ( "text_edit" , & self . text_edit ) ;
88
92
}
89
- s. field ( "kind" , & self . kind ( ) ) ;
90
- if self . lookup ( ) != self . label ( ) {
93
+ s. field ( "kind" , & self . kind ) ;
94
+ if self . lookup ( ) != self . label {
91
95
s. field ( "lookup" , & self . lookup ( ) ) ;
92
96
}
93
- if let Some ( detail) = self . detail ( ) {
97
+ if let Some ( detail) = & self . detail {
94
98
s. field ( "detail" , & detail) ;
95
99
}
96
- if let Some ( documentation) = self . documentation ( ) {
100
+ if let Some ( documentation) = & self . documentation {
97
101
s. field ( "documentation" , & documentation) ;
98
102
}
99
103
if self . deprecated {
@@ -351,51 +355,11 @@ impl CompletionItem {
351
355
}
352
356
}
353
357
354
- /// What user sees in pop-up in the UI.
355
- pub fn label ( & self ) -> & str {
356
- & self . label
357
- }
358
- pub fn source_range ( & self ) -> TextRange {
359
- self . source_range
360
- }
361
-
362
- pub fn text_edit ( & self ) -> & TextEdit {
363
- & self . text_edit
364
- }
365
- /// Whether `text_edit` is a snippet (contains `$0` markers).
366
- pub fn is_snippet ( & self ) -> bool {
367
- self . is_snippet
368
- }
369
-
370
- /// Short one-line additional information, like a type
371
- pub fn detail ( & self ) -> Option < & str > {
372
- self . detail . as_deref ( )
373
- }
374
- /// A doc-comment
375
- pub fn documentation ( & self ) -> Option < Documentation > {
376
- self . documentation . clone ( )
377
- }
378
358
/// What string is used for filtering.
379
359
pub fn lookup ( & self ) -> & str {
380
360
self . lookup . as_deref ( ) . unwrap_or ( & self . label )
381
361
}
382
362
383
- pub fn kind ( & self ) -> CompletionItemKind {
384
- self . kind
385
- }
386
-
387
- pub fn deprecated ( & self ) -> bool {
388
- self . deprecated
389
- }
390
-
391
- pub fn relevance ( & self ) -> CompletionRelevance {
392
- self . relevance
393
- }
394
-
395
- pub fn trigger_call_info ( & self ) -> bool {
396
- self . trigger_call_info
397
- }
398
-
399
363
pub fn ref_match ( & self ) -> Option < ( String , text_edit:: Indel , CompletionRelevance ) > {
400
364
// Relevance of the ref match should be the same as the original
401
365
// match, but with exact type match set because self.ref_match
@@ -405,16 +369,12 @@ impl CompletionItem {
405
369
406
370
self . ref_match . map ( |( mutability, offset) | {
407
371
(
408
- format ! ( "&{}{}" , mutability. as_keyword_for_ref( ) , self . label( ) ) ,
372
+ format ! ( "&{}{}" , mutability. as_keyword_for_ref( ) , self . label) ,
409
373
text_edit:: Indel :: insert ( offset, format ! ( "&{}" , mutability. as_keyword_for_ref( ) ) ) ,
410
374
relevance,
411
375
)
412
376
} )
413
377
}
414
-
415
- pub fn imports_to_add ( & self ) -> & [ LocatedImport ] {
416
- & self . import_to_add
417
- }
418
378
}
419
379
420
380
/// A helper to make `CompletionItem`s.
0 commit comments