(commentRange core.TextRange, indentation int, firstLineIsIndented bool, indentFinalLine bool)
| 925 | } |
| 926 | |
| 927 | func (w *formatSpanWorker) indentMultilineComment(commentRange core.TextRange, indentation int, firstLineIsIndented bool, indentFinalLine bool) { |
| 928 | // split comment in lines |
| 929 | startLine := scanner.GetECMALineOfPosition(w.sourceFile, commentRange.Pos()) |
| 930 | endLine := scanner.GetECMALineOfPosition(w.sourceFile, commentRange.End()) |
| 931 | |
| 932 | if startLine == endLine { |
| 933 | if !firstLineIsIndented { |
| 934 | // treat as single line comment |
| 935 | w.insertIndentation(commentRange.Pos(), indentation, false) |
| 936 | } |
| 937 | return |
| 938 | } |
| 939 | |
| 940 | parts := make([]core.TextRange, 0, strings.Count(w.sourceFile.Text()[commentRange.Pos():commentRange.End()], "\n")) |
| 941 | startPos := commentRange.Pos() |
| 942 | for line := startLine; line < endLine; line++ { |
| 943 | endOfLine := scanner.GetECMAEndLinePosition(w.sourceFile, line) |
| 944 | parts = append(parts, core.NewTextRange(startPos, endOfLine)) |
| 945 | startPos = int(scanner.GetECMALineStarts(w.sourceFile)[line+1]) |
| 946 | } |
| 947 | |
| 948 | if indentFinalLine { |
| 949 | parts = append(parts, core.NewTextRange(startPos, commentRange.End())) |
| 950 | } |
| 951 | |
| 952 | if len(parts) == 0 { |
| 953 | return |
| 954 | } |
| 955 | |
| 956 | startLinePos := int(scanner.GetECMALineStarts(w.sourceFile)[startLine]) |
| 957 | |
| 958 | nonWhitespaceInFirstPartCharacter, nonWhitespaceInFirstPartColumn := findFirstNonWhitespaceCharacterAndColumn(startLinePos, parts[0].Pos(), w.sourceFile, w.formattingContext.Options) |
| 959 | |
| 960 | startIndex := 0 |
| 961 | |
| 962 | if firstLineIsIndented { |
| 963 | startIndex = 1 |
| 964 | startLine++ |
| 965 | } |
| 966 | |
| 967 | // shift all parts on the delta size |
| 968 | delta := indentation - nonWhitespaceInFirstPartColumn |
| 969 | for i := startIndex; i < len(parts); i++ { |
| 970 | startLinePos := int(scanner.GetECMALineStarts(w.sourceFile)[startLine]) |
| 971 | nonWhitespaceCharacter := nonWhitespaceInFirstPartCharacter |
| 972 | nonWhitespaceColumn := nonWhitespaceInFirstPartColumn |
| 973 | if i != 0 { |
| 974 | nonWhitespaceCharacter, nonWhitespaceColumn = findFirstNonWhitespaceCharacterAndColumn(parts[i].Pos(), parts[i].End(), w.sourceFile, w.formattingContext.Options) |
| 975 | } |
| 976 | newIndentation := nonWhitespaceColumn + delta |
| 977 | if newIndentation > 0 { |
| 978 | indentationString := getIndentationString(newIndentation, w.formattingContext.Options) |
| 979 | w.recordReplace(startLinePos, nonWhitespaceCharacter, indentationString) |
| 980 | } else { |
| 981 | w.recordDelete(startLinePos, nonWhitespaceCharacter) |
| 982 | } |
| 983 | |
| 984 | startLine++ |
no test coverage detected