@@ -8,9 +8,11 @@ use ruff_text_size::{Ranged, TextRange, TextSize};
8
8
use ty_python_semantic:: { Completion , NameKind , SemanticModel } ;
9
9
10
10
use crate :: Db ;
11
+ use crate :: docstring:: Docstring ;
11
12
use crate :: find_node:: covering_node;
13
+ use crate :: goto:: DefinitionsOrTargets ;
12
14
13
- pub fn completion ( db : & dyn Db , file : File , offset : TextSize ) -> Vec < Completion < ' _ > > {
15
+ pub fn completion ( db : & dyn Db , file : File , offset : TextSize ) -> Vec < DetailedCompletion < ' _ > > {
14
16
let parsed = parsed_module ( db, file) . load ( db) ;
15
17
16
18
let Some ( target_token) = CompletionTargetTokens :: find ( & parsed, offset) else {
@@ -40,6 +42,27 @@ pub fn completion(db: &dyn Db, file: File, offset: TextSize) -> Vec<Completion<'
40
42
completions. sort_by ( compare_suggestions) ;
41
43
completions. dedup_by ( |c1, c2| c1. name == c2. name ) ;
42
44
completions
45
+ . into_iter ( )
46
+ . map ( |completion| {
47
+ let definition = DefinitionsOrTargets :: from_ty ( db, completion. ty ) ;
48
+ let documentation = definition. and_then ( |def| def. docstring ( db) ) ;
49
+ DetailedCompletion {
50
+ inner : completion,
51
+ documentation,
52
+ }
53
+ } )
54
+ . collect ( )
55
+ }
56
+
57
+ pub struct DetailedCompletion < ' db > {
58
+ pub inner : Completion < ' db > ,
59
+ pub documentation : Option < Docstring > ,
60
+ }
61
+ impl < ' db > std:: ops:: Deref for DetailedCompletion < ' db > {
62
+ type Target = Completion < ' db > ;
63
+ fn deref ( & self ) -> & Self :: Target {
64
+ & self . inner
65
+ }
43
66
}
44
67
45
68
/// The kind of tokens identified under the cursor.
@@ -478,9 +501,8 @@ fn compare_suggestions(c1: &Completion, c2: &Completion) -> Ordering {
478
501
mod tests {
479
502
use insta:: assert_snapshot;
480
503
use ruff_python_parser:: { Mode , ParseOptions , TokenKind , Tokens } ;
481
- use ty_python_semantic:: Completion ;
482
504
483
- use crate :: completion;
505
+ use crate :: completion:: { DetailedCompletion , completion } ;
484
506
use crate :: tests:: { CursorTest , cursor_test} ;
485
507
486
508
use super :: token_suffix_by_kinds;
@@ -3022,14 +3044,14 @@ from os.<CURSOR>
3022
3044
)
3023
3045
}
3024
3046
3025
- fn completions_if ( & self , predicate : impl Fn ( & Completion ) -> bool ) -> String {
3047
+ fn completions_if ( & self , predicate : impl Fn ( & DetailedCompletion ) -> bool ) -> String {
3026
3048
self . completions_if_snapshot ( predicate, |c| c. name . as_str ( ) . to_string ( ) )
3027
3049
}
3028
3050
3029
3051
fn completions_if_snapshot (
3030
3052
& self ,
3031
- predicate : impl Fn ( & Completion ) -> bool ,
3032
- snapshot : impl Fn ( & Completion ) -> String ,
3053
+ predicate : impl Fn ( & DetailedCompletion ) -> bool ,
3054
+ snapshot : impl Fn ( & DetailedCompletion ) -> String ,
3033
3055
) -> String {
3034
3056
let completions = completion ( & self . db , self . cursor . file , self . cursor . offset ) ;
3035
3057
if completions. is_empty ( ) {
0 commit comments