Skip to content

Commit f6b3006

Browse files
Address review: check all declarations for binding elements, update test with renamed destructuring
Co-authored-by: DanielRosenwasser <[email protected]>
1 parent f0f9fef commit f6b3006

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

internal/fourslash/tests/destructuredInterfaceJSDoc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ interface FooBar {
2222
2323
declare const fubar: FooBar;
2424
25-
const {/*1*/foo, /*2*/bar, /*3*/baz} = fubar;
25+
const {/*1*/foo, /*2*/bar, baz: /*3*/biz} = fubar;
2626
`
2727
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
2828
defer done()
2929
f.VerifyQuickInfoAt(t, "1", "const foo: number", "foo comment")
3030
f.VerifyQuickInfoAt(t, "2", "const bar: string", "bar comment")
31-
f.VerifyQuickInfoAt(t, "3", "const baz: string", "baz comment")
31+
f.VerifyQuickInfoAt(t, "3", "const biz: string", "baz comment")
3232
}
3333

3434
func TestDestructuredInterfaceJSDocWithRename(t *testing.T) {

internal/ls/hover.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,26 @@ func (l *LanguageService) getQuickInfoAndDocumentationForSymbol(c *checker.Check
7373
func (l *LanguageService) getDocumentationFromDeclaration(c *checker.Checker, symbol *ast.Symbol, declaration *ast.Node, location *ast.Node, contentFormat lsproto.MarkupKind) string {
7474
// Handle binding elements specially (variables created from destructuring) - we need to get the documentation from the property type
7575
// The declaration passed in might be the binding element itself, but we need the interface property declaration
76-
if symbol != nil && symbol.ValueDeclaration != nil && ast.IsBindingElement(symbol.ValueDeclaration) && ast.IsIdentifier(location) {
77-
bindingElement := symbol.ValueDeclaration
78-
parent := bindingElement.Parent
79-
name := bindingElement.PropertyName()
80-
if name == nil {
81-
name = bindingElement.Name()
82-
}
83-
if ast.IsIdentifier(name) && ast.IsObjectBindingPattern(parent) {
84-
propertyName := name.Text()
85-
objectType := c.GetTypeAtLocation(parent)
86-
if objectType != nil {
87-
propertySymbol := findPropertyInType(c, objectType, propertyName)
88-
if propertySymbol != nil && propertySymbol.ValueDeclaration != nil {
89-
declaration = propertySymbol.ValueDeclaration
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+
}
9096
}
9197
}
9298
}

0 commit comments

Comments
 (0)