(s *formattingScanner)
| 222 | } |
| 223 | |
| 224 | func (w *formatSpanWorker) execute(s *formattingScanner) []core.TextChange { |
| 225 | w.formattingScanner = s |
| 226 | w.indentationOnLastIndentedLine = -1 |
| 227 | w.lastIndentedLine = -1 |
| 228 | opt := GetFormatCodeSettingsFromContext(w.ctx) |
| 229 | w.formattingContext = NewFormattingContext(w.sourceFile, w.requestKind, opt) |
| 230 | // formatting context is used by rules provider |
| 231 | w.visitor = ast.NewNodeVisitor(func(child *ast.Node) *ast.Node { |
| 232 | if child == nil { |
| 233 | return child |
| 234 | } |
| 235 | w.processChildNode(w.visitingNode, w.visitingIndenter, w.visitingNodeStartLine, w.visitingUndecoratedNodeStartLine, child, -1, w.visitingNode, w.visitingIndenter, w.visitingNodeStartLine, w.visitingUndecoratedNodeStartLine, false, false) |
| 236 | return child |
| 237 | }, &ast.NodeFactory{}, ast.NodeVisitorHooks{ |
| 238 | VisitNodes: func(nodes *ast.NodeList, v *ast.NodeVisitor) *ast.NodeList { |
| 239 | if nodes == nil { |
| 240 | return nodes |
| 241 | } |
| 242 | w.processChildNodes(w.visitingNode, w.visitingIndenter, w.visitingNodeStartLine, w.visitingUndecoratedNodeStartLine, nodes, w.visitingNode, w.visitingNodeStartLine, w.visitingIndenter) |
| 243 | return nodes |
| 244 | }, |
| 245 | }) |
| 246 | |
| 247 | w.formattingScanner.advance() |
| 248 | |
| 249 | if w.formattingScanner.isOnToken() { |
| 250 | startLine := scanner.GetECMALineOfPosition(w.sourceFile, withTokenStart(w.enclosingNode, w.sourceFile).Pos()) |
| 251 | undecoratedStartLine := startLine |
| 252 | if ast.HasDecorators(w.enclosingNode) { |
| 253 | undecoratedStartLine = scanner.GetECMALineOfPosition(w.sourceFile, getNonDecoratorTokenPosOfNode(w.enclosingNode, w.sourceFile)) |
| 254 | } |
| 255 | |
| 256 | w.processNode(w.enclosingNode, w.enclosingNode, startLine, undecoratedStartLine, w.initialIndentation, w.delta) |
| 257 | } |
| 258 | |
| 259 | // Leading trivia items get attached to and processed with the token that proceeds them. If the |
| 260 | // range ends in the middle of some leading trivia, the token that proceeds them won't be in the |
| 261 | // range and thus won't get processed. So we process those remaining trivia items here. |
| 262 | remainingTrivia := w.formattingScanner.getCurrentLeadingTrivia() |
| 263 | if len(remainingTrivia) > 0 { |
| 264 | indentation := w.initialIndentation |
| 265 | if NodeWillIndentChild(w.formattingContext.Options, w.enclosingNode, nil, w.sourceFile, false) { |
| 266 | indentation += opt.IndentSize // !!! TODO: nil check??? |
| 267 | } |
| 268 | |
| 269 | w.indentTriviaItems(remainingTrivia, indentation, true, func(item TextRangeWithKind) { |
| 270 | startLine, startChar := scanner.GetECMALineAndByteOffsetOfPosition(w.sourceFile, item.Loc.Pos()) |
| 271 | w.processRange(item, startLine, startChar, w.enclosingNode, w.enclosingNode, nil) |
| 272 | w.insertIndentation(item.Loc.Pos(), indentation, false) |
| 273 | }) |
| 274 | |
| 275 | if opt.TrimTrailingWhitespace.IsTrue() { |
| 276 | w.trimTrailingWhitespacesForRemainingRange(remainingTrivia) |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | if w.previousRange != NewTextRangeWithKind(0, 0, 0) && w.formattingScanner.getTokenFullStart() >= w.originalRange.End() { |
| 281 | // Formatting edits happen by looking at pairs of contiguous tokens (see `processPair`), |
no test coverage detected