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

Function FormatOnOpeningCurly

internal/format/api.go:119–140  ·  view source on GitHub ↗
(ctx context.Context, sourceFile *ast.SourceFile, position int)

Source from the content-addressed store, hash-verified

117}
118
119func FormatOnOpeningCurly(ctx context.Context, sourceFile *ast.SourceFile, position int) []core.TextChange {
120 openingCurly := findImmediatelyPrecedingTokenOfKind(position, ast.KindOpenBraceToken, sourceFile)
121 if openingCurly == nil {
122 return nil
123 }
124 curlyBraceRange := openingCurly.Parent
125 outermostNode := findOutermostNodeWithinListLevel(curlyBraceRange)
126 /**
127 * We limit the span to end at the opening curly to handle the case where
128 * the brace matched to that just typed will be incorrect after further edits.
129 * For example, we could type the opening curly for the following method
130 * body without brace-matching activated:
131 * ```
132 * class C {
133 * foo()
134 * }
135 * ```
136 * and we wouldn't want to move the closing brace.
137 */
138 textRange := core.NewTextRange(GetLineStartPositionForPosition(scanner.GetTokenPosOfNode(outermostNode, sourceFile, false), sourceFile), position)
139 return FormatSpan(ctx, textRange, sourceFile, FormatRequestKindFormatOnOpeningCurlyBrace)
140}
141
142func FormatOnClosingCurly(ctx context.Context, sourceFile *ast.SourceFile, position int) []core.TextChange {
143 precedingToken := findImmediatelyPrecedingTokenOfKind(position, ast.KindCloseBraceToken, sourceFile)

Callers 1

Calls 6

NewTextRangeFunction · 0.92
GetTokenPosOfNodeFunction · 0.92
FormatSpanFunction · 0.85

Tested by

no test coverage detected