33import * as vscode from 'vscode' ;
44import * as proxy from './jediProxy' ;
55import * as telemetryContracts from "../common/telemetryContracts" ;
6- import { EOL } from 'os ' ;
6+ import { extractHoverInfo } from './jediHelpers ' ;
77
88export class PythonHoverProvider implements vscode . HoverProvider {
99 private jediProxyHandler : proxy . JediProxyHandler < proxy . ICompletionResult , vscode . Hover > ;
@@ -59,43 +59,3 @@ export class PythonHoverProvider implements vscode.HoverProvider {
5959 } ) ;
6060 }
6161}
62-
63- function extractHoverInfo ( definition : proxy . IAutoCompleteItem ) : vscode . Hover {
64- // Somtimes the signature of the function, class (whatever) is broken into multiple lines
65- // Here's an example
66- // ```python
67- // def __init__(self, group=None, name=None,
68- // args=(), kwargs=None, verbose=None):
69- // """This constructor should always be called with keyword arguments. Arguments are:
70-
71- // *group* should be None; reserved for future extension when a ThreadGroup
72- // class is implemented.
73- /// """
74- /// ```
75- const txt = definition . description || definition . text ;
76- const rawDocString = typeof definition . raw_docstring === 'string' ? definition . raw_docstring . trim ( ) : '' ;
77- const firstLineOfRawDocString = rawDocString . length > 0 ? rawDocString . split ( EOL ) [ 0 ] : '' ;
78- const lines = txt . split ( EOL ) ;
79- const startIndexOfDocString = firstLineOfRawDocString === '' ? - 1 : lines . findIndex ( line => line . indexOf ( firstLineOfRawDocString ) === 0 ) ;
80-
81- let signatureLines = startIndexOfDocString === - 1 ? [ lines . shift ( ) ] : lines . splice ( 0 , startIndexOfDocString ) ;
82- let signature = signatureLines . filter ( line => line . trim ( ) . length > 0 ) . join ( EOL ) ;
83-
84- switch ( definition . type ) {
85- case vscode . CompletionItemKind . Constructor :
86- case vscode . CompletionItemKind . Function :
87- case vscode . CompletionItemKind . Method : {
88- signature = 'def ' + signature ;
89- break ;
90- }
91- case vscode . CompletionItemKind . Class : {
92- signature = 'class ' + signature ;
93- break ;
94- }
95- }
96- const hoverInfo : vscode . MarkedString [ ] = [ { language : 'python' , value : signature } ] ;
97- if ( lines . some ( line => line . trim ( ) . length > 0 ) ) {
98- hoverInfo . push ( lines . join ( EOL ) . trim ( ) . replace ( / ^ \s + | \s + $ / g, '' ) . trim ( ) ) ;
99- }
100- return new vscode . Hover ( hoverInfo ) ;
101- }
0 commit comments