@@ -71,39 +71,36 @@ func (l *LanguageService) getQuickInfoAndDocumentationForSymbol(c *checker.Check
7171}
7272
7373func (l * LanguageService ) getDocumentationFromDeclaration (c * checker.Checker , symbol * ast.Symbol , declaration * ast.Node , location * ast.Node , contentFormat lsproto.MarkupKind ) string {
74- // Handle binding elements specially (variables created from destructuring) - we need to get the documentation from the property type
75- // The declaration passed in might be the binding element itself, but we need the interface property declaration
76- // Check all declarations to see if any is a binding element
77- if symbol != nil && ast .IsIdentifier (location ) {
78- for _ , decl := range symbol .Declarations {
79- if decl != nil && ast .IsBindingElement (decl ) {
80- bindingElement := decl
81- parent := bindingElement .Parent
82- name := bindingElement .PropertyName ()
83- if name == nil {
84- name = bindingElement .Name ()
85- }
86- if ast .IsIdentifier (name ) && ast .IsObjectBindingPattern (parent ) {
87- propertyName := name .Text ()
88- objectType := c .GetTypeAtLocation (parent )
89- if objectType != nil {
90- propertySymbol := findPropertyInType (c , objectType , propertyName )
91- if propertySymbol != nil && propertySymbol .ValueDeclaration != nil {
92- declaration = propertySymbol .ValueDeclaration
93- break
94- }
95- }
96- }
97- }
98- }
99- }
100-
10174 if declaration == nil {
10275 return ""
10376 }
77+
10478 isMarkdown := contentFormat == lsproto .MarkupKindMarkdown
10579 var b strings.Builder
106- if jsdoc := getJSDocOrTag (c , declaration ); jsdoc != nil && ! containsTypedefTag (jsdoc ) {
80+ jsdoc := getJSDocOrTag (c , declaration )
81+
82+ // Handle binding elements specially (variables created from destructuring) - we need to get the documentation from the property type
83+ // If the binding element doesn't have its own JSDoc, fall back to the property's JSDoc
84+ if jsdoc == nil && symbol != nil && symbol .ValueDeclaration != nil && ast .IsBindingElement (symbol .ValueDeclaration ) && ast .IsIdentifier (location ) {
85+ bindingElement := symbol .ValueDeclaration
86+ parent := bindingElement .Parent
87+ name := bindingElement .PropertyName ()
88+ if name == nil {
89+ name = bindingElement .Name ()
90+ }
91+ if ast .IsIdentifier (name ) && ast .IsObjectBindingPattern (parent ) {
92+ propertyName := name .Text ()
93+ objectType := c .GetTypeAtLocation (parent )
94+ if objectType != nil {
95+ propertySymbol := findPropertyInType (c , objectType , propertyName )
96+ if propertySymbol != nil && propertySymbol .ValueDeclaration != nil {
97+ jsdoc = getJSDocOrTag (c , propertySymbol .ValueDeclaration )
98+ }
99+ }
100+ }
101+ }
102+
103+ if jsdoc != nil && ! containsTypedefTag (jsdoc ) {
107104 l .writeComments (& b , c , jsdoc .Comments (), isMarkdown )
108105 if jsdoc .Kind == ast .KindJSDoc {
109106 if tags := jsdoc .AsJSDoc ().Tags ; tags != nil {
0 commit comments