@@ -2,7 +2,7 @@ import * as proxy from './jediProxy';
22import { EOL } from 'os' ;
33import * as vscode from 'vscode' ;
44
5- export function extractSignatureAndDocumentation ( definition : proxy . IAutoCompleteItem ) : [ string , string ] {
5+ export function extractSignatureAndDocumentation ( definition : proxy . IAutoCompleteItem , highlightCode : boolean = false ) : [ string , string ] {
66 // Somtimes the signature of the function, class (whatever) is broken into multiple lines
77 // Here's an example
88 // ```python
@@ -17,7 +17,7 @@ export function extractSignatureAndDocumentation(definition: proxy.IAutoComplete
1717 const txt = definition . description || definition . text ;
1818 const rawDocString = typeof definition . raw_docstring === 'string' ? definition . raw_docstring . trim ( ) : '' ;
1919 const firstLineOfRawDocString = rawDocString . length > 0 ? rawDocString . split ( EOL ) [ 0 ] : '' ;
20- const lines = txt . split ( EOL ) ;
20+ let lines = txt . split ( EOL ) ;
2121 const startIndexOfDocString = firstLineOfRawDocString === '' ? - 1 : lines . findIndex ( line => line . indexOf ( firstLineOfRawDocString ) === 0 ) ;
2222
2323 let signatureLines = startIndexOfDocString === - 1 ? [ lines . shift ( ) ] : lines . splice ( 0 , startIndexOfDocString ) ;
@@ -35,11 +35,21 @@ export function extractSignatureAndDocumentation(definition: proxy.IAutoComplete
3535 break ;
3636 }
3737 }
38+
39+ // check if we have any sample code in the documentation
40+ if ( highlightCode ) {
41+ lines = lines . map ( line => {
42+ if ( line . trim ( ) . startsWith ( '>>> ' ) ) {
43+ return '```python\n' + line . substring ( 4 ) . trim ( ) + '\n```' ;
44+ }
45+ return line ;
46+ } ) ;
47+ }
3848 return [ signature , lines . join ( EOL ) . trim ( ) . replace ( / ^ \s + | \s + $ / g, '' ) . trim ( ) ] ;
3949}
4050
4151export function extractHoverInfo ( definition : proxy . IAutoCompleteItem ) : vscode . Hover {
42- const parts = extractSignatureAndDocumentation ( definition ) ;
52+ const parts = extractSignatureAndDocumentation ( definition , true ) ;
4353 const hoverInfo : vscode . MarkedString [ ] = parts [ 0 ] . length === 0 ? [ ] : [ { language : 'python' , value : parts [ 0 ] } ] ;
4454 if ( parts [ 1 ] . length > 0 ) {
4555 hoverInfo . push ( parts [ 1 ] ) ;
0 commit comments