Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package fourslash_test

import (
"testing"

"github.com/microsoft/typescript-go/internal/fourslash"
"github.com/microsoft/typescript-go/internal/testutil"
)

func TestHoverIntersectionPropertyDocumentation(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")

const content = `
interface A {
/** interface A */
prop: () => number;
}

interface B {
/** interface B */
prop: () => number;
}

type C = A & B;
declare const c: C;

c./*1*/prop;
`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()

f.VerifyQuickInfoAt(t, "1", "(property) prop: () => number", "interface A\ninterface B")
}
7 changes: 7 additions & 0 deletions internal/ls/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ func (l *LanguageService) getQuickInfoAndDocumentationForSymbol(c *checker.Check
if documentation != "" {
return quickInfo, documentation
}
// Synthetic union and intersection properties can have declarations without a value declaration.
if info.declaration == nil && symbol != nil {
documentation = l.getDocumentationFromDeclarations(c, symbol, symbol.Declarations, node, contentFormat, false /*commentOnly*/)
if documentation != "" {
return quickInfo, documentation
}
}

return quickInfo, l.documentationFromAlias(c, symbol, node, contentFormat)
}
Expand Down
13 changes: 11 additions & 2 deletions internal/ls/jsdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,25 @@ func (l *LanguageService) GetSymbolDocumentationComment(c *checker.Checker, symb
if symbol == nil {
return ""
}
return l.getDocumentationFromDeclarations(c, symbol, symbol.Declarations, nil, lsproto.MarkupKindPlainText, true /*commentOnly*/)
}

// getDocumentationFromDeclarations gathers and deduplicates documentation from a set of declarations.
func (l *LanguageService) getDocumentationFromDeclarations(c *checker.Checker, symbol *ast.Symbol, declarations []*ast.Node, location *ast.Node, contentFormat lsproto.MarkupKind, commentOnly bool) string {
var parts []string
var seen collections.Set[*ast.Node]
for _, decl := range symbol.Declarations {
for _, decl := range declarations {
if decl == nil {
continue
}
if !seen.AddIfAbsent(decl) {
continue
}
if doc := l.getDocumentationFromDeclaration(c, symbol, decl, decl, lsproto.MarkupKindPlainText, true /*commentOnly*/); doc != "" && !slices.Contains(parts, doc) {
documentationLocation := location
if documentationLocation == nil {
documentationLocation = decl
}
if doc := l.getDocumentationFromDeclaration(c, symbol, decl, documentationLocation, contentFormat, commentOnly); doc != "" && !slices.Contains(parts, doc) {
parts = append(parts, doc)
}
}
Expand Down