MCPcopy Index your code
hub / github.com/microsoft/typescript-go / emitTrailingCommentsOfPosition

Method emitTrailingCommentsOfPosition

internal/printer/printer.go:5590–5633  ·  view source on GitHub ↗
(pos int, prefixSpace bool, forceNoNewline bool)

Source from the content-addressed store, hash-verified

5588}
5589
5590func (p *Printer) emitTrailingCommentsOfPosition(pos int, prefixSpace bool, forceNoNewline bool) {
5591 if p.commentsDisabled || p.currentSourceFile == nil {
5592 return
5593 }
5594 if p.containerEnd != -1 && (pos == p.containerEnd || pos == p.declarationListContainerEnd) {
5595 return
5596 }
5597
5598 var comments []ast.CommentRange
5599 for comment := range scanner.GetTrailingCommentRanges(p.emitContext.Factory.AsNodeFactory(), p.currentSourceFile.Text(), pos) {
5600 comments = append(comments, comment)
5601 }
5602 if len(comments) == 0 {
5603 return
5604 }
5605
5606 for _, comment := range comments {
5607 if prefixSpace {
5608 if !p.shouldWriteComment(comment) {
5609 continue
5610 }
5611 if !p.writer.IsAtStartOfLine() {
5612 p.writeSpace()
5613 }
5614 p.emitComment(comment)
5615 if comment.HasTrailingNewLine {
5616 p.writeLine()
5617 }
5618 continue
5619 }
5620
5621 p.emitComment(comment)
5622 switch {
5623 case forceNoNewline:
5624 if comment.Kind == ast.KindSingleLineCommentTrivia {
5625 p.writeLine()
5626 }
5627 case comment.HasTrailingNewLine:
5628 p.writeLine()
5629 default:
5630 p.writeSpace()
5631 }
5632 }
5633}
5634
5635func (p *Printer) emitDetachedCommentsAndUpdateCommentsInfo(textRange core.TextRange) {
5636 if p.currentSourceFile == nil {

Callers 2

emitListItemsMethod · 0.95

Calls 10

shouldWriteCommentMethod · 0.95
writeSpaceMethod · 0.95
emitCommentMethod · 0.95
writeLineMethod · 0.95
GetTrailingCommentRangesFunction · 0.92
lenFunction · 0.85
AsNodeFactoryMethod · 0.65
TextMethod · 0.65
IsAtStartOfLineMethod · 0.65
appendFunction · 0.50

Tested by

no test coverage detected