Skip to content

Commit 27ad132

Browse files
Fix hover text for ambient modules to display "module" instead of "namespace" (#2668)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
1 parent 909769d commit 27ad132

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/testutil"
8+
)
9+
10+
func TestQuickInfoAmbientModule(t *testing.T) {
11+
t.Parallel()
12+
13+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
14+
const content = `declare module "*.css"/*1*/;`
15+
16+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
17+
defer done()
18+
f.VerifyQuickInfoAt(t, "1", `module "*.css"`, "")
19+
}

internal/ls/hover.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ func getQuickInfoAndDeclarationAtLocation(c *checker.Checker, symbol *ast.Symbol
365365
}
366366
if flags&ast.SymbolFlagsModule != 0 {
367367
writeNewLine()
368-
b.WriteString(core.IfElse(symbol.ValueDeclaration != nil && ast.IsSourceFile(symbol.ValueDeclaration), "module ", "namespace "))
368+
isModule := symbol.ValueDeclaration != nil && (ast.IsSourceFile(symbol.ValueDeclaration) || ast.IsAmbientModule(symbol.ValueDeclaration))
369+
b.WriteString(core.IfElse(isModule, "module ", "namespace "))
369370
b.WriteString(c.SymbolToStringEx(symbol, container, ast.SymbolFlagsNone, symbolFormatFlags))
370371
setDeclaration(core.Find(symbol.Declarations, ast.IsModuleDeclaration))
371372
}

0 commit comments

Comments
 (0)