Skip to content
Merged
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
8 changes: 8 additions & 0 deletions internal/checker/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@ func (c *Checker) GetBaseTypes(t *Type) []*Type {
return c.getBaseTypes(t)
}

func (c *Checker) GetApparentType(t *Type) *Type {
return c.getApparentType(t)
}

func (c *Checker) GetBaseConstructorTypeOfClass(t *Type) *Type {
return c.getBaseConstructorTypeOfClass(t)
}

func (c *Checker) GetRestTypeOfSignature(sig *Signature) *Type {
return c.getRestTypeOfSignature(sig)
}
Expand Down
38 changes: 38 additions & 0 deletions internal/fourslash/tests/hoverMixinOverrideDocumentation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package fourslash_test

import (
"testing"

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

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

const content = `
// @strict: true
// @filename: main.ts

declare class BaseClass {
/** some documentation */
static method(): number;
}

type AnyConstructor = abstract new (...args: any[]) => object

class MixinClass {}
declare function Mix<T extends AnyConstructor>(BaseClass: T): typeof MixinClass & T;

declare class Mixed extends Mix(BaseClass) {
static method(): number;
}

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

f.VerifyQuickInfoAt(t, "1", "(method) Mixed.method(): number", "some documentation")
}
21 changes: 15 additions & 6 deletions internal/ls/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,16 +563,25 @@ func getJSDocOrTag(c *checker.Checker, node *ast.Node) *ast.Node {
}
if ast.IsClassOrInterfaceLike(node.Parent) {
isStatic := ast.HasStaticModifier(node)
for _, baseType := range c.GetBaseTypes(c.GetDeclaredTypeOfSymbol(node.Parent.Symbol())) {
t := baseType
if isStatic && baseType.Symbol() != nil {
t = c.GetTypeOfSymbol(baseType.Symbol())
}
if prop := c.GetPropertyOfType(t, symbol.Name); prop != nil && prop.ValueDeclaration != nil {
classType := c.GetDeclaredTypeOfSymbol(node.Parent.Symbol())
if isStatic {
// For static members, use the checker's base constructor type resolution.
// This correctly handles intersection constructor types from mixins
// (e.g., typeof MixinClass & T) by preserving the full intersection.
staticBaseType := c.GetApparentType(c.GetBaseConstructorTypeOfClass(classType))
if prop := c.GetPropertyOfType(staticBaseType, symbol.Name); prop != nil && prop.ValueDeclaration != nil {
if jsDoc := getJSDocOrTag(c, prop.ValueDeclaration); jsDoc != nil {
return jsDoc
}
}
} else {
for _, baseType := range c.GetBaseTypes(classType) {
if prop := c.GetPropertyOfType(baseType, symbol.Name); prop != nil && prop.ValueDeclaration != nil {
if jsDoc := getJSDocOrTag(c, prop.ValueDeclaration); jsDoc != nil {
return jsDoc
}
}
}
}
}
}
Expand Down
Loading