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

Method insertIndentation

internal/format/span.go:868–881  ·  view source on GitHub ↗
(pos int, indentation int, lineAdded bool)

Source from the content-addressed store, hash-verified

866}
867
868func (w *formatSpanWorker) insertIndentation(pos int, indentation int, lineAdded bool) {
869 indentationString := getIndentationString(indentation, w.formattingContext.Options)
870 if lineAdded {
871 // new line is added before the token by the formatting rules
872 // insert indentation string at the very beginning of the token
873 w.recordReplace(pos, 0, indentationString)
874 } else {
875 tokenStartLine, tokenStartCharacter := scanner.GetECMALineAndByteOffsetOfPosition(w.sourceFile, pos)
876 startLinePosition := int(scanner.GetECMALineStarts(w.sourceFile)[tokenStartLine])
877 if indentation != w.characterToColumn(startLinePosition, tokenStartCharacter) || w.indentationIsDifferent(indentationString, startLinePosition) {
878 w.recordReplace(startLinePosition, tokenStartCharacter, indentationString)
879 }
880 }
881}
882
883func (w *formatSpanWorker) characterToColumn(startLinePosition int, characterInLine int) int {
884 column := 0

Callers 3

executeMethod · 0.95

Calls 7

recordReplaceMethod · 0.95
characterToColumnMethod · 0.95
GetECMALineStartsFunction · 0.92
getIndentationStringFunction · 0.85
intInterface · 0.50

Tested by

no test coverage detected