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

Function getBlockIndent

internal/format/indent.go:177–191  ·  view source on GitHub ↗
(sourceFile *ast.SourceFile, position int, options lsutil.FormatCodeSettings)

Source from the content-addressed store, hash-verified

175}
176
177func getBlockIndent(sourceFile *ast.SourceFile, position int, options lsutil.FormatCodeSettings) int {
178 // move backwards until we find a line with a non-whitespace character,
179 // then find the first non-whitespace character for that line.
180 current := position
181 for current > 0 {
182 ch, size := utf8.DecodeRuneInString(sourceFile.Text()[current:])
183 if !stringutil.IsWhiteSpaceLike(ch) {
184 break
185 }
186 current -= size
187 }
188
189 lineStart := GetLineStartPositionForPosition(current, sourceFile)
190 return FindFirstNonWhitespaceColumn(lineStart, current, sourceFile, options)
191}
192
193func getActualIndentationForListItemBeforeComma(commaToken *ast.Node, sourceFile *ast.SourceFile, options lsutil.FormatCodeSettings) int {
194 // previous token is comma that separates items in list - find the previous item and try to derive indentation from it

Callers 1

GetIndentationFunction · 0.85

Calls 4

IsWhiteSpaceLikeFunction · 0.92
TextMethod · 0.65

Tested by

no test coverage detected