55
66declare const $ : any ;
77
8- import { CSSProperties , useEffect , useRef } from "react" ;
8+ import { Tag , Tooltip } from "antd" ;
9+ import { CSSProperties , useEffect , useMemo , useRef } from "react" ;
910import { Map } from "immutable" ;
1011import useNotebookFrameActions from "@cocalc/frontend/frame-editors/jupyter-editor/cell-notebook/hook" ;
1112
@@ -14,7 +15,7 @@ export interface Actions {
1415 select_complete : (
1516 id : string ,
1617 item : string ,
17- complete ?: Map < string , any >
18+ complete ?: Map < string , any > ,
1819 ) => void ;
1920 complete_handle_key : ( _ : string , keyCode : number ) => void ;
2021 clear_complete : ( ) => void ;
@@ -44,6 +45,25 @@ export function Complete({ actions, id, complete }: Props) {
4445 frameActions . current ?. set_mode ( "edit" ) ;
4546 } ;
4647 } , [ ] ) ;
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 ] ) ;
4767
4868 function select ( item : string ) : void {
4969 // Save contents of editor to the store so that completion properly *places* the
@@ -57,8 +77,31 @@ export function Complete({ actions, id, complete }: Props) {
5777 function renderItem ( item : string ) {
5878 return (
5979 < 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+ >
6186 { 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 }
62105 </ a >
63106 </ li >
64107 ) ;
@@ -104,3 +147,16 @@ export function Complete({ actions, id, complete }: Props) {
104147 </ div >
105148 ) ;
106149}
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