Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion internal/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -2353,6 +2353,9 @@ func IsArrayLiteralOrObjectLiteralDestructuringPattern(node *Node) bool {

func accessKind(node *Node) AccessKind {
parent := node.Parent
if parent == nil {
return AccessKindRead
}
Comment on lines 2355 to +2358
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, Strada said:

function accessKind(node: Node): AccessKind {
    const { parent } = node;

    switch (parent?.kind) {

Love the ol "parent is never undefined except when it totally is"

switch parent.Kind {
case KindParenthesizedExpression:
return accessKind(parent)
Expand Down Expand Up @@ -2404,8 +2407,9 @@ func accessKind(node *Node) AccessKind {
return AccessKindWrite
}
return AccessKindRead
default:
return AccessKindRead
}
return AccessKindRead
}

func reverseAccessKind(a AccessKind) AccessKind {
Expand Down
9 changes: 4 additions & 5 deletions internal/ls/documenthighlights.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ func (l *LanguageService) getSemanticDocumentHighlights(ctx context.Context, pos
if referenceEntries == nil {
return nil
}

var highlights []*lsproto.DocumentHighlight
for _, entry := range referenceEntries {
for _, ref := range entry.references {
if ref.node != nil {
fileName, highlight := l.toDocumentHighlight(ref)
if fileName == sourceFile.FileName() {
highlights = append(highlights, highlight)
}
fileName, highlight := l.toDocumentHighlight(ref)
if fileName == sourceFile.FileName() {
highlights = append(highlights, highlight)
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions internal/ls/findallreferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ func (l *LanguageService) getReferencedSymbolsForNode(ctx context.Context, posit
}

if moduleSymbol := checker.GetMergedSymbol(resolvedRef.file.Symbol); moduleSymbol != nil {
return getReferencedSymbolsForModule(ctx, program, moduleSymbol /*excludeImportTypeOfExportEquals*/, false, sourceFiles, sourceFilesSet)
return l.getReferencedSymbolsForModule(ctx, program, moduleSymbol /*excludeImportTypeOfExportEquals*/, false, sourceFiles, sourceFilesSet)
}

// !!! not implemented
Expand Down Expand Up @@ -673,7 +673,7 @@ func (l *LanguageService) getReferencedSymbolsForNode(ctx context.Context, posit
}

if symbol.Name == ast.InternalSymbolNameExportEquals {
return getReferencedSymbolsForModule(ctx, program, symbol.Parent, false /*excludeImportTypeOfExportEquals*/, sourceFiles, sourceFilesSet)
return l.getReferencedSymbolsForModule(ctx, program, symbol.Parent, false /*excludeImportTypeOfExportEquals*/, sourceFiles, sourceFilesSet)
}

moduleReferences := l.getReferencedSymbolsForModuleIfDeclaredBySourceFile(ctx, symbol, program, sourceFiles, checker, options, sourceFilesSet) // !!! cancellationToken
Expand All @@ -700,7 +700,7 @@ func (l *LanguageService) getReferencedSymbolsForModuleIfDeclaredBySourceFile(ct
}
exportEquals := symbol.Exports[ast.InternalSymbolNameExportEquals]
// If exportEquals != nil, we're about to add references to `import("mod")` anyway, so don't double-count them.
moduleReferences := getReferencedSymbolsForModule(ctx, program, symbol, exportEquals != nil, sourceFiles, sourceFilesSet)
moduleReferences := l.getReferencedSymbolsForModule(ctx, program, symbol, exportEquals != nil, sourceFiles, sourceFilesSet)
if exportEquals == nil || !sourceFilesSet.Has(moduleSourceFileName) {
return moduleReferences
}
Expand Down Expand Up @@ -1021,7 +1021,7 @@ func getMergedAliasedSymbolOfNamespaceExportDeclaration(node *ast.Node, symbol *
return nil
}

func getReferencedSymbolsForModule(ctx context.Context, program *compiler.Program, symbol *ast.Symbol, excludeImportTypeOfExportEquals bool, sourceFiles []*ast.SourceFile, sourceFilesSet *collections.Set[string]) []*SymbolAndEntries {
func (l *LanguageService) getReferencedSymbolsForModule(ctx context.Context, program *compiler.Program, symbol *ast.Symbol, excludeImportTypeOfExportEquals bool, sourceFiles []*ast.SourceFile, sourceFilesSet *collections.Set[string]) []*SymbolAndEntries {
debug.Assert(symbol.ValueDeclaration != nil)

checker, done := program.GetTypeChecker(ctx)
Expand Down Expand Up @@ -1065,7 +1065,11 @@ func getReferencedSymbolsForModule(ctx context.Context, program *compiler.Progra
// <reference path> or <reference types>
// We can't easily create a proper range entry here without access to LanguageService,
// but we can create a node-based entry pointing to the source file which will be resolved later
return newNodeEntry(reference.referencingFile.AsNode())
return &referenceEntry{
kind: entryKindRange,
fileName: reference.referencingFile.FileName(),
textRange: l.createLspRangeFromBounds(reference.ref.Pos(), reference.ref.End(), reference.referencingFile),
}
}
return nil
})
Expand Down