5
5
6
6
declare const $ : any ;
7
7
8
- import { CSSProperties , useEffect , useRef } from "react" ;
8
+ import { Tag , Tooltip } from "antd" ;
9
+ import { CSSProperties , useEffect , useMemo , useRef } from "react" ;
9
10
import { Map } from "immutable" ;
10
11
import useNotebookFrameActions from "@cocalc/frontend/frame-editors/jupyter-editor/cell-notebook/hook" ;
11
12
@@ -14,7 +15,7 @@ export interface Actions {
14
15
select_complete : (
15
16
id : string ,
16
17
item : string ,
17
- complete ?: Map < string , any >
18
+ complete ?: Map < string , any > ,
18
19
) => void ;
19
20
complete_handle_key : ( _ : string , keyCode : number ) => void ;
20
21
clear_complete : ( ) => void ;
@@ -44,6 +45,25 @@ export function Complete({ actions, id, complete }: Props) {
44
45
frameActions . current ?. set_mode ( "edit" ) ;
45
46
} ;
46
47
} , [ ] ) ;
48
+ const typeInfo = useMemo ( ( ) => {
49
+ const types = complete ?. getIn ( [ "metadata" , "_jupyter_types_experimental" ] ) ;
50
+ if ( types == null ) {
51
+ return { } ;
52
+ }
53
+ const typeInfo : { [ text : string ] : { type : string ; signature : string } } =
54
+ { } ;
55
+ // @ts -ignore
56
+ for ( const info of types ) {
57
+ const text = info . get ( "text" ) ;
58
+ if ( typeInfo [ text ] == null ) {
59
+ typeInfo [ text ] = {
60
+ type : info . get ( "type" ) ,
61
+ signature : info . get ( "signature" ) ,
62
+ } ;
63
+ }
64
+ }
65
+ return typeInfo ;
66
+ } , [ complete ] ) ;
47
67
48
68
function select ( item : string ) : void {
49
69
// Save contents of editor to the store so that completion properly *places* the
@@ -57,8 +77,31 @@ export function Complete({ actions, id, complete }: Props) {
57
77
function renderItem ( item : string ) {
58
78
return (
59
79
< li key = { item } >
60
- < a role = "menuitem" tabIndex = { - 1 } onClick = { ( ) => select ( item ) } >
80
+ < a
81
+ role = "menuitem"
82
+ style = { { display : "flex" , fontSize : "13px" } }
83
+ tabIndex = { - 1 }
84
+ onClick = { ( ) => select ( item ) }
85
+ >
61
86
{ item }
87
+ { typeInfo [ item ] ?. type ? (
88
+ < Tooltip title = { `${ item } ${ typeInfo [ item ] . signature } ` } >
89
+ < div style = { { flex : 1 } } >
90
+ < div
91
+ style = { {
92
+ float : "right" ,
93
+ marginLeft : "30px" ,
94
+ color : "#0000008a" ,
95
+ fontFamily : "monospace" ,
96
+ } }
97
+ >
98
+ < Tag color = { typeToColor [ typeInfo [ item ] . type ] } >
99
+ { typeInfo [ item ] . type }
100
+ </ Tag >
101
+ </ div >
102
+ </ div >
103
+ </ Tooltip >
104
+ ) : null }
62
105
</ a >
63
106
</ li >
64
107
) ;
@@ -104,3 +147,16 @@ export function Complete({ actions, id, complete }: Props) {
104
147
</ div >
105
148
) ;
106
149
}
150
+
151
+ const typeToColor = {
152
+ function : "blue" ,
153
+ statement : "green" ,
154
+ module : "cyan" ,
155
+ class : "orange" ,
156
+ instance : "magenta" ,
157
+ "<unknown>" : "red" ,
158
+ path : "gold" ,
159
+ keyword : "purple" ,
160
+ magic : "geekblue" ,
161
+ param : "volcano" ,
162
+ } ;
0 commit comments