@@ -23,7 +23,7 @@ namespace Microsoft.Python.LanguageServer.Sources {
23
23
internal sealed class MarkdownDocumentationSource : DocumentationSource , IDocumentationSource {
24
24
public InsertTextFormat DocumentationFormat => InsertTextFormat . PlainText ;
25
25
26
- public MarkupContent GetHover ( string name , IMember member , IPythonType self ) {
26
+ public MarkupContent GetHover ( string name , IMember member , IPythonType self , bool includeClassInit = false ) {
27
27
// We need to tell between instance and type.
28
28
var type = member . GetPythonType ( ) ;
29
29
if ( type . IsUnknown ( ) ) {
@@ -41,16 +41,30 @@ public MarkupContent GetHover(string name, IMember member, IPythonType self) {
41
41
var typeDoc = ! string . IsNullOrEmpty ( type . Documentation ) ? $ "\n ---\n { type . MarkdownDoc ( ) } " : string . Empty ;
42
42
switch ( type ) {
43
43
case IPythonPropertyType prop :
44
- text = GetPropertyHoverString ( prop ) ;
44
+ text = GetPropertyString ( prop ) ;
45
45
break ;
46
46
47
47
case IPythonFunctionType ft :
48
- text = GetFunctionHoverString ( ft , self ) ;
48
+ text = GetFunctionString ( ft , self ) ;
49
49
break ;
50
50
51
51
case IPythonClassType cls :
52
52
var clsDoc = ! string . IsNullOrEmpty ( cls . Documentation ) ? $ "\n ---\n { cls . MarkdownDoc ( ) } " : string . Empty ;
53
- text = $ "```\n class { cls . Name } \n ```{ clsDoc } ";
53
+
54
+ string className ;
55
+ var sig = string . Empty ;
56
+
57
+ if ( includeClassInit ) {
58
+ className = cls . Name ;
59
+ var init = cls . GetMember < IPythonFunctionType > ( "__init__" ) ;
60
+ if ( init != null ) {
61
+ sig = GetSignatureString ( init , null , out var _ , 0 , "" , true ) ;
62
+ }
63
+ } else {
64
+ className = "class " + cls . Name ;
65
+ }
66
+
67
+ text = $ "```\n { className } { sig } \n ```{ clsDoc } ";
54
68
break ;
55
69
56
70
case IPythonModule mod :
@@ -67,7 +81,7 @@ public MarkupContent GetHover(string name, IMember member, IPythonType self) {
67
81
} ;
68
82
}
69
83
70
- public MarkupContent FormatDocumentation ( string documentation )
84
+ public MarkupContent FormatDocumentation ( string documentation )
71
85
=> new MarkupContent { kind = MarkupKind . Markdown , value = DocstringConverter . ToMarkdown ( documentation ) } ;
72
86
73
87
public MarkupContent FormatParameterDocumentation ( IParameterInfo parameter ) {
@@ -79,13 +93,13 @@ public MarkupContent FormatParameterDocumentation(IParameterInfo parameter) {
79
93
return new MarkupContent { kind = MarkupKind . Markdown , value = text } ;
80
94
}
81
95
82
- private string GetPropertyHoverString ( IPythonPropertyType prop , int overloadIndex = 0 ) {
96
+ private string GetPropertyString ( IPythonPropertyType prop ) {
83
97
var decTypeString = prop . DeclaringType != null ? $ "{ prop . DeclaringType . Name } ." : string . Empty ;
84
98
var propDoc = ! string . IsNullOrEmpty ( prop . Documentation ) ? $ "\n ---\n { prop . MarkdownDoc ( ) } " : string . Empty ;
85
99
return $ "```\n { decTypeString } \n ```{ propDoc } ";
86
100
}
87
101
88
- private string GetFunctionHoverString ( IPythonFunctionType ft , IPythonType self , int overloadIndex = 0 ) {
102
+ private string GetFunctionString ( IPythonFunctionType ft , IPythonType self , int overloadIndex = 0 ) {
89
103
var sigString = GetSignatureString ( ft , self , out _ , overloadIndex ) ;
90
104
var decTypeString = ft . DeclaringType != null ? $ "{ ft . DeclaringType . Name } ." : string . Empty ;
91
105
var funcDoc = ! string . IsNullOrEmpty ( ft . Documentation ) ? $ "\n ---\n { ft . MarkdownDoc ( ) } " : string . Empty ;
0 commit comments