MCPcopy Create free account
hub / github.com/microsoft/typescript-go / getNodesToSearchForModifier

Function getNodesToSearchForModifier

internal/ls/documenthighlights.go:694–743  ·  view source on GitHub ↗
(declaration *ast.Node, modifierFlag ast.ModifierFlags)

Source from the content-addressed store, hash-verified

692}
693
694func getNodesToSearchForModifier(declaration *ast.Node, modifierFlag ast.ModifierFlags) []*ast.Node {
695 var result []*ast.Node
696
697 container := declaration.Parent
698 if container == nil {
699 return nil
700 }
701
702 // Types of node whose children might have modifiers.
703 switch container.Kind {
704 case ast.KindModuleBlock, ast.KindSourceFile, ast.KindBlock, ast.KindCaseClause, ast.KindDefaultClause:
705 // Container is either a class declaration or the declaration is a classDeclaration
706 if (modifierFlag&ast.ModifierFlagsAbstract) != 0 && ast.IsClassDeclaration(declaration) {
707 return append(append(result, declaration.Members()...), declaration)
708 } else {
709 return append(result, container.Statements()...)
710 }
711 case ast.KindConstructor, ast.KindMethodDeclaration, ast.KindFunctionDeclaration:
712 // Parameters and, if inside a class, also class members
713 result = append(result, container.Parameters()...)
714 if ast.IsClassLike(container.Parent) {
715 result = append(result, container.Parent.Members()...)
716 }
717 return result
718 case ast.KindClassDeclaration, ast.KindClassExpression, ast.KindInterfaceDeclaration, ast.KindTypeLiteral:
719 nodes := container.Members()
720 result = append(result, nodes...)
721 // If we're an accessibility modifier, we're in an instance member and should search
722 // the constructor's parameter list for instance members as well.
723 if (modifierFlag & (ast.ModifierFlagsAccessibilityModifier | ast.ModifierFlagsReadonly)) != 0 {
724 var constructor *ast.Node
725
726 for _, member := range nodes {
727 if ast.IsConstructorDeclaration(member) {
728 constructor = member
729 break
730 }
731 }
732 if constructor != nil {
733 result = append(result, constructor.Parameters()...)
734 }
735 } else if (modifierFlag & ast.ModifierFlagsAbstract) != 0 {
736 result = append(result, container)
737 }
738 return result
739 default:
740 // Syntactically invalid positions or unsupported containers
741 return nil
742 }
743}
744
745func findModifier(node *ast.Node, kind ast.Kind) *ast.Node {
746 for _, modifier := range node.ModifierNodes() {

Callers 1

getModifierOccurrencesFunction · 0.85

Calls 7

ParametersMethod · 0.95
IsClassDeclarationFunction · 0.92
IsClassLikeFunction · 0.92
IsConstructorDeclarationFunction · 0.92
MembersMethod · 0.80
StatementsMethod · 0.80
appendFunction · 0.50

Tested by

no test coverage detected