@@ -18,9 +18,10 @@ use crate::{
1818/// editor pop-up. It is basically a POD with various properties. To construct a
1919/// [`CompletionItem`], use [`Builder::new`] method and the [`Builder`] struct.
2020#[ derive( Clone ) ]
21+ #[ non_exhaustive]
2122pub struct CompletionItem {
2223 /// Label in the completion pop up which identifies completion.
23- label : SmolStr ,
24+ pub label : SmolStr ,
2425 /// Range of identifier that is being completed.
2526 ///
2627 /// It should be used primarily for UI, but we also use this to convert
@@ -29,33 +30,33 @@ pub struct CompletionItem {
2930 /// `source_range` must contain the completion offset. `text_edit` should
3031 /// start with what `source_range` points to, or VSCode will filter out the
3132 /// completion silently.
32- source_range : TextRange ,
33+ pub source_range : TextRange ,
3334 /// What happens when user selects this item.
3435 ///
3536 /// 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 ,
3839
3940 /// What item (struct, function, etc) are we completing.
40- kind : CompletionItemKind ,
41+ pub kind : CompletionItemKind ,
4142
4243 /// Lookup is used to check if completion item indeed can complete current
4344 /// ident.
4445 ///
4546 /// That is, in `foo.bar$0` lookup of `abracadabra` will be accepted (it
4647 /// contains `bar` sub sequence), and `quux` will rejected.
47- lookup : Option < SmolStr > ,
48+ pub lookup : Option < SmolStr > ,
4849
4950 /// 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 > ,
5253
5354 /// Whether this item is marked as deprecated
54- deprecated : bool ,
55+ pub deprecated : bool ,
5556
5657 /// If completing a function call, ask the editor to show parameter popup
5758 /// after completion.
58- trigger_call_info : bool ,
59+ pub trigger_call_info : bool ,
5960
6061 /// We use this to sort completion. Relevance records facts like "do the
6162 /// types align precisely?". We can't sort by relevances directly, they are
@@ -64,36 +65,39 @@ pub struct CompletionItem {
6465 /// Note that Relevance ignores fuzzy match score. We compute Relevance for
6566 /// all possible items, and then separately build an ordered completion list
6667 /// based on relevance and fuzzy matching with the already typed identifier.
67- relevance : CompletionRelevance ,
68+ pub relevance : CompletionRelevance ,
6869
6970 /// Indicates that a reference or mutable reference to this variable is a
7071 /// 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 ) > ,
7276
7377 /// The import data to add to completion's edits.
74- import_to_add : SmallVec < [ LocatedImport ; 1 ] > ,
78+ pub import_to_add : SmallVec < [ LocatedImport ; 1 ] > ,
7579}
7680
7781// We use custom debug for CompletionItem to make snapshot tests more readable.
7882impl fmt:: Debug for CompletionItem {
7983 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
8084 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 ( ) ;
8488 s. field ( "delete" , & atom. delete ) ;
8589 s. field ( "insert" , & atom. insert ) ;
8690 } else {
8791 s. field ( "text_edit" , & self . text_edit ) ;
8892 }
89- s. field ( "kind" , & self . kind ( ) ) ;
90- if self . lookup ( ) != self . label ( ) {
93+ s. field ( "kind" , & self . kind ) ;
94+ if self . lookup ( ) != self . label {
9195 s. field ( "lookup" , & self . lookup ( ) ) ;
9296 }
93- if let Some ( detail) = self . detail ( ) {
97+ if let Some ( detail) = & self . detail {
9498 s. field ( "detail" , & detail) ;
9599 }
96- if let Some ( documentation) = self . documentation ( ) {
100+ if let Some ( documentation) = & self . documentation {
97101 s. field ( "documentation" , & documentation) ;
98102 }
99103 if self . deprecated {
@@ -351,51 +355,11 @@ impl CompletionItem {
351355 }
352356 }
353357
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- }
378358 /// What string is used for filtering.
379359 pub fn lookup ( & self ) -> & str {
380360 self . lookup . as_deref ( ) . unwrap_or ( & self . label )
381361 }
382362
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-
399363 pub fn ref_match ( & self ) -> Option < ( String , text_edit:: Indel , CompletionRelevance ) > {
400364 // Relevance of the ref match should be the same as the original
401365 // match, but with exact type match set because self.ref_match
@@ -405,16 +369,12 @@ impl CompletionItem {
405369
406370 self . ref_match . map ( |( mutability, offset) | {
407371 (
408- format ! ( "&{}{}" , mutability. as_keyword_for_ref( ) , self . label( ) ) ,
372+ format ! ( "&{}{}" , mutability. as_keyword_for_ref( ) , self . label) ,
409373 text_edit:: Indel :: insert ( offset, format ! ( "&{}" , mutability. as_keyword_for_ref( ) ) ) ,
410374 relevance,
411375 )
412376 } )
413377 }
414-
415- pub fn imports_to_add ( & self ) -> & [ LocatedImport ] {
416- & self . import_to_add
417- }
418378}
419379
420380/// A helper to make `CompletionItem`s.
0 commit comments