@@ -75,58 +75,87 @@ func (l *LanguageService) getDocumentationFromDeclaration(c *checker.Checker, de
7575 return ""
7676 }
7777 isMarkdown := contentFormat == lsproto .MarkupKindMarkdown
78+
79+ jsdoc := getJSDocOrTag (c , declaration )
80+ if jsdoc == nil {
81+ return l .getDocumentation (c , getInheritedJSDocOrTag (c , declaration ), isMarkdown )
82+ }
83+ if containsTypedefTag (jsdoc ) {
84+ return ""
85+ }
86+
7887 var b strings.Builder
79- if jsdoc := getJSDocOrTag (c , declaration ); jsdoc != nil && ! containsTypedefTag (jsdoc ) {
80- l .writeComments (& b , c , jsdoc .Comments (), isMarkdown )
81- if jsdoc .Kind == ast .KindJSDoc {
82- if tags := jsdoc .AsJSDoc ().Tags ; tags != nil {
83- for _ , tag := range tags .Nodes {
84- if tag .Kind == ast .KindJSDocTypeTag {
85- continue
86- }
87- b .WriteString ("\n \n " )
88- if isMarkdown {
89- b .WriteString ("*@" )
90- b .WriteString (tag .TagName ().Text ())
91- b .WriteString ("*" )
92- } else {
93- b .WriteString ("@" )
94- b .WriteString (tag .TagName ().Text ())
95- }
96- switch tag .Kind {
97- case ast .KindJSDocParameterTag , ast .KindJSDocPropertyTag :
98- writeOptionalEntityName (& b , tag .Name ())
99- case ast .KindJSDocAugmentsTag :
100- writeOptionalEntityName (& b , tag .ClassName ())
101- case ast .KindJSDocSeeTag :
102- writeOptionalEntityName (& b , tag .AsJSDocSeeTag ().NameExpression )
103- case ast .KindJSDocTemplateTag :
104- for i , tp := range tag .TypeParameters () {
105- if i != 0 {
106- b .WriteString ("," )
107- }
108- writeOptionalEntityName (& b , tp .Name ())
88+
89+ if jsdoc .Kind == ast .KindJSDoc {
90+ tags := jsdoc .AsJSDoc ().Tags
91+ if len (jsdoc .AsJSDoc ().Comments ()) == 0 || tags == nil || len (tags .Nodes ) == 0 || core .Some (tags .Nodes , isInheritDocTag ) {
92+ b .WriteString (l .getDocumentation (c , getInheritedJSDocOrTag (c , declaration ), isMarkdown ))
93+ }
94+ }
95+
96+ b .WriteString (l .getDocumentation (c , jsdoc , isMarkdown ))
97+ return b .String ()
98+ }
99+
100+ func (l * LanguageService ) getDocumentation (c * checker.Checker , jsdoc * ast.Node , isMarkdown bool ) string {
101+ if jsdoc == nil {
102+ return ""
103+ }
104+
105+ var b strings.Builder
106+ l .writeComments (& b , c , jsdoc .Comments (), isMarkdown )
107+ if jsdoc .Kind == ast .KindJSDoc {
108+ if tags := jsdoc .AsJSDoc ().Tags ; tags != nil {
109+ for _ , tag := range tags .Nodes {
110+ if tag .Kind == ast .KindJSDocTypeTag {
111+ continue
112+ }
113+ b .WriteString ("\n \n " )
114+ if isMarkdown {
115+ b .WriteString ("*@" )
116+ b .WriteString (tag .TagName ().Text ())
117+ b .WriteString ("*" )
118+ } else {
119+ b .WriteString ("@" )
120+ b .WriteString (tag .TagName ().Text ())
121+ }
122+ switch tag .Kind {
123+ case ast .KindJSDocParameterTag , ast .KindJSDocPropertyTag :
124+ writeOptionalEntityName (& b , tag .Name ())
125+ case ast .KindJSDocAugmentsTag :
126+ writeOptionalEntityName (& b , tag .ClassName ())
127+ case ast .KindJSDocSeeTag :
128+ writeOptionalEntityName (& b , tag .AsJSDocSeeTag ().NameExpression )
129+ case ast .KindJSDocTemplateTag :
130+ for i , tp := range tag .TypeParameters () {
131+ if i != 0 {
132+ b .WriteString ("," )
109133 }
134+ writeOptionalEntityName (& b , tp .Name ())
110135 }
111- comments := tag . Comments ()
112- if len ( comments ) != 0 {
113- if commentHasPrefix (comments , "```" ) {
114- b . WriteString ( " \n " )
115- } else {
116- b . WriteString ( " " )
117- if ! commentHasPrefix ( comments , "-" ) {
118- b . WriteString ( "— " )
119- }
136+ }
137+ comments := tag . Comments ()
138+ if len (comments ) != 0 {
139+ if commentHasPrefix ( comments , "```" ) {
140+ b . WriteString ( " \n " )
141+ } else {
142+ b . WriteString ( " " )
143+ if ! commentHasPrefix ( comments , "-" ) {
144+ b . WriteString ( "— " )
120145 }
121- l .writeComments (& b , c , comments , isMarkdown )
122146 }
147+ l .writeComments (& b , c , comments , isMarkdown )
123148 }
124149 }
125150 }
126151 }
127152 return b .String ()
128153}
129154
155+ func isInheritDocTag (tag * ast.JSDocTag ) bool {
156+ return tag .TagName ().Text () == "inheritDoc" || tag .TagName ().Text () == "inheritdoc"
157+ }
158+
130159func formatQuickInfo (quickInfo string ) string {
131160 var b strings.Builder
132161 b .Grow (32 )
@@ -425,17 +454,33 @@ func getJSDocOrTag(c *checker.Checker, node *ast.Node) *ast.Node {
425454 (ast .IsVariableDeclaration (node .Parent ) || ast .IsPropertyDeclaration (node .Parent ) || ast .IsPropertyAssignment (node .Parent )) && node .Parent .Initializer () == node :
426455 return getJSDocOrTag (c , node .Parent )
427456 }
457+ return nil
458+ }
459+
460+ func getInheritedJSDocOrTag (c * checker.Checker , node * ast.Node ) * ast.Node {
461+ if ast .IsGetAccessorDeclaration (node ) || ast .IsSetAccessorDeclaration (node ) {
462+ return nil
463+ }
428464 if symbol := node .Symbol (); symbol != nil && node .Parent != nil && ast .IsClassOrInterfaceLike (node .Parent ) {
429465 isStatic := ast .HasStaticModifier (node )
430466 for _ , baseType := range c .GetBaseTypes (c .GetDeclaredTypeOfSymbol (node .Parent .Symbol ())) {
431467 t := baseType
432- if isStatic {
468+ if isStatic && baseType . Symbol () != nil {
433469 t = c .GetTypeOfSymbol (baseType .Symbol ())
434470 }
435471 if prop := c .GetPropertyOfType (t , symbol .Name ); prop != nil && prop .ValueDeclaration != nil {
436- if jsDoc := getJSDocOrTag (c , prop .ValueDeclaration ); jsDoc != nil {
437- return jsDoc
472+ jsdoc := getJSDocOrTag (c , prop .ValueDeclaration )
473+ if jsdoc == nil {
474+ return getInheritedJSDocOrTag (c , prop .ValueDeclaration )
475+ }
476+ tags := jsdoc .AsJSDoc ().Tags
477+ if tags == nil {
478+ return jsdoc
479+ }
480+ if containsTypedefTag (jsdoc ) {
481+ return nil
438482 }
483+ return jsdoc
439484 }
440485 }
441486 }
0 commit comments