Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ test('extract source by ranges', () => {
const expectedLineNumbers = ['1', '2', '3', '...', '8', '9', '10', '11'];
expect(lineMappings.toStringArray('...')).toEqual(expectedLineNumbers);
expect(lineMappings.lineNumber(7)).toBe(5);
expect(lineMappings.lineNumber(0)).toBe(1);
});
8 changes: 6 additions & 2 deletions x-pack/plugins/code/server/utils/composite_source_merger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ export class LineMapping {
}

public lineNumber(originLineNumber: number, startAtLine: number = 1) {
const n = this.reverseMap.get(originLineNumber) || Number.NaN;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spacedragon this is a bug when this.reverseMap.get(originLineNumber) returns 0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

return n + startAtLine;
const n = this.reverseMap.get(originLineNumber);
if (n === undefined) {
return Number.NaN;
} else {
return n + startAtLine;
}
}

public hasLine(line: number) {
Expand Down