File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 33import * as vscode from 'vscode' ;
44import * as proxy from './jediProxy' ;
55import * as telemetryContracts from "../common/telemetryContracts" ;
6+ import { highlightCode } from './jediHelpers' ;
67
78export class PythonHoverProvider implements vscode . HoverProvider {
89 private jediProxyHandler : proxy . JediProxyHandler < proxy . IHoverResult > ;
@@ -26,9 +27,10 @@ export class PythonHoverProvider implements vscode.HoverProvider {
2627 break ;
2728 }
2829 }
29- results . push ( { language : 'python' , value : signature } ) ;
30+ results . push ( { language : 'python' , value : signature } ) ;
3031 if ( item . description ) {
31- results . push ( description ) ;
32+ var descriptionWithHighlightedCode = highlightCode ( item . description ) ;
33+ results . push ( descriptionWithHighlightedCode ) ;
3234 }
3335 } ) ;
3436 return new vscode . Hover ( results ) ;
Original file line number Diff line number Diff line change @@ -47,3 +47,15 @@ export function extractSignatureAndDocumentation(definition: proxy.IAutoComplete
4747 }
4848 return [ signature , lines . join ( EOL ) . trim ( ) . replace ( / ^ \s + | \s + $ / g, '' ) . trim ( ) ] ;
4949}
50+
51+ export function highlightCode ( documentation : string ) : string {
52+ let lines = documentation . split ( EOL ) ;
53+ lines = lines . map ( line => {
54+ if ( line . trim ( ) . startsWith ( '>>> ' ) ) {
55+ return '```python\n' + line . substring ( 4 ) . trim ( ) + '\n```' ;
56+ }
57+ return line ;
58+ } ) ;
59+
60+ return lines . join ( EOL ) . trim ( ) . replace ( / ^ \s + | \s + $ / g, '' ) . trim ( ) ;
61+ }
You can’t perform that action at this time.
0 commit comments