diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 36089f94f73..f59f6e56e91 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1330,23 +1330,39 @@ namespace ts { export function getSourceFileImportLocation(node: SourceFile) { // For a source file, it is possible there are detached comments we should not skip const text = node.text; + const textLength = text.length; let ranges = getLeadingCommentRanges(text, 0); if (!ranges) return 0; let position = 0; // However we should still skip a pinned comment at the top if (ranges.length && ranges[0].kind === SyntaxKind.MultiLineCommentTrivia && isPinnedComment(text, ranges[0])) { - position = ranges[0].end + 1; + position = ranges[0].end; + advancePastLineBreak(); ranges = ranges.slice(1); } // As well as any triple slash references for (const range of ranges) { if (range.kind === SyntaxKind.SingleLineCommentTrivia && isRecognizedTripleSlashComment(node.text, range.pos, range.end)) { - position = range.end + 1; + position = range.end; + advancePastLineBreak(); continue; } break; } return position; + + function advancePastLineBreak() { + if (position < textLength) { + const charCode = text.charCodeAt(position); + if (isLineBreak(charCode)) { + position++; + + if (position < textLength && charCode === CharacterCodes.carriageReturn && text.charCodeAt(position) === CharacterCodes.lineFeed) { + position++; + } + } + } + } } /**