MCPcopy Create free account
hub / github.com/Effect-TS/tsgo / ParseDataForExtendsClassCompletion

Function ParseDataForExtendsClassCompletion

internal/completion/position.go:90–126  ·  view source on GitHub ↗

ParseDataForExtendsClassCompletion parses position context for a completion in the extends clause of a class declaration. It calls ParseAccessedExpressionForCompletion and then walks up the AST to find the enclosing ClassDeclaration.

(sf *ast.SourceFile, position int)

Source from the content-addressed store, hash-verified

88// extends clause of a class declaration. It calls ParseAccessedExpressionForCompletion
89// and then walks up the AST to find the enclosing ClassDeclaration.
90func ParseDataForExtendsClassCompletion(sf *ast.SourceFile, position int) *ExtendsClassCompletionData {
91 result := ParseAccessedExpressionForCompletion(sf, position)
92 if result == nil {
93 return nil
94 }
95
96 if !ast.IsIdentifier(result.AccessedObject) {
97 return nil
98 }
99
100 // Walk up from OuterNode.parent through ExpressionWithTypeArguments and HeritageClause
101 classDecl := result.OuterNode.Parent
102 for classDecl != nil &&
103 (ast.IsExpressionWithTypeArguments(classDecl) || ast.IsHeritageClause(classDecl)) {
104 if classDecl.Parent == nil {
105 break
106 }
107 classDecl = classDecl.Parent
108 }
109
110 if classDecl == nil || !ast.IsClassDeclaration(classDecl) {
111 return nil
112 }
113
114 className := classDecl.Name()
115 if className == nil {
116 return nil
117 }
118
119 return &ExtendsClassCompletionData{
120 AccessedObject: result.AccessedObject,
121 ClassDeclaration: classDecl,
122 ClassName: className,
123 ReplacementStart: result.ReplacementStart,
124 ReplacementLength: result.ReplacementLength,
125 }
126}
127
128// AccessedObjectText returns the text of the accessed object node.
129func (d *ExtendsClassCompletionData) AccessedObjectText() string {