Skip to content

Commit e34615c

Browse files
authored
Port workspace symbols tests (#2146)
1 parent 746dcca commit e34615c

22 files changed

+1131
-49
lines changed

internal/ast/ast.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10983,7 +10983,7 @@ func (node *SourceFile) computeDeclarationMap() map[string][]*Node {
1098310983
result := make(map[string][]*Node)
1098410984

1098510985
addDeclaration := func(declaration *Node) {
10986-
name := getDeclarationName(declaration)
10986+
name := GetDeclarationName(declaration)
1098710987
if name != "" {
1098810988
result[name] = append(result[name], declaration)
1098910989
}
@@ -10993,7 +10993,7 @@ func (node *SourceFile) computeDeclarationMap() map[string][]*Node {
1099310993
visit = func(node *Node) bool {
1099410994
switch node.Kind {
1099510995
case KindFunctionDeclaration, KindFunctionExpression, KindMethodDeclaration, KindMethodSignature:
10996-
declarationName := getDeclarationName(node)
10996+
declarationName := GetDeclarationName(node)
1099710997
if declarationName != "" {
1099810998
declarations := result[declarationName]
1099910999
var lastDeclaration *Node
@@ -11025,7 +11025,7 @@ func (node *SourceFile) computeDeclarationMap() map[string][]*Node {
1102511025
break
1102611026
}
1102711027
fallthrough
11028-
case KindVariableDeclaration, KindBindingElement:
11028+
case KindVariableDeclaration, KindBindingElement, KindCommonJSExport:
1102911029
name := node.Name()
1103011030
if name != nil {
1103111031
if IsBindingPattern(name) {
@@ -11074,6 +11074,12 @@ func (node *SourceFile) computeDeclarationMap() map[string][]*Node {
1107411074
}
1107511075
}
1107611076
}
11077+
case KindBinaryExpression:
11078+
switch GetAssignmentDeclarationKind(node.AsBinaryExpression()) {
11079+
case JSDeclarationKindThisProperty, JSDeclarationKindProperty:
11080+
addDeclaration(node)
11081+
}
11082+
node.ForEachChild(visit)
1107711083
default:
1107811084
node.ForEachChild(visit)
1107911085
}
@@ -11083,7 +11089,7 @@ func (node *SourceFile) computeDeclarationMap() map[string][]*Node {
1108311089
return result
1108411090
}
1108511091

11086-
func getDeclarationName(declaration *Node) string {
11092+
func GetDeclarationName(declaration *Node) string {
1108711093
name := GetNonAssignedNameOfDeclaration(declaration)
1108811094
if name != nil {
1108911095
if IsComputedPropertyName(name) {

internal/compiler/program.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ type Program struct {
6868
// Cached unresolved imports for ATA
6969
unresolvedImportsOnce sync.Once
7070
unresolvedImports *collections.Set[string]
71+
72+
// Used by workspace/symbol
73+
hasTSFileOnce sync.Once
74+
hasTSFile bool
7175
}
7276

7377
// FileExists implements checker.Program.
@@ -1634,6 +1638,23 @@ func (p *Program) SourceFileMayBeEmitted(sourceFile *ast.SourceFile, forceDtsEmi
16341638
return sourceFileMayBeEmitted(sourceFile, p, forceDtsEmit)
16351639
}
16361640

1641+
func (p *Program) IsLibFile(sourceFile *ast.SourceFile) bool {
1642+
_, ok := p.libFiles[sourceFile.Path()]
1643+
return ok
1644+
}
1645+
1646+
func (p *Program) HasTSFile() bool {
1647+
p.hasTSFileOnce.Do(func() {
1648+
for _, file := range p.files {
1649+
if tspath.HasImplementationTSFileExtension(file.FileName()) {
1650+
p.hasTSFile = true
1651+
break
1652+
}
1653+
}
1654+
})
1655+
return p.hasTSFile
1656+
}
1657+
16371658
var plainJSErrors = collections.NewSetFromItems(
16381659
// binder errors
16391660
diagnostics.Cannot_redeclare_block_scoped_variable_0.Code(),

0 commit comments

Comments
 (0)