-
Notifications
You must be signed in to change notification settings - Fork 11
support calculate function coverage rate #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: FANG.Ge <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch. I added a couple of comments inline.
decorations.calledLineDecorations.push(createCalledLineDecoration(range, totalCalls, lineDataArray)); | ||
/* First line of function will be appended with coverage rate. */ | ||
const isFuncStart = isFirstLineOfFunction(funcsDataOfFile, funcName, lineNumber); | ||
const coverageRate = isFuncStart ? Number(funcCoverages.get(funcName)) : NaN; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer using undefined
instead of NaN
here. NaN
should really be avoided in general.
function createCalledLineDecoration(range: vscode.Range, totalCalls: number, lineDataArray: GcovLineData[], coverageRate: number) { | ||
const lineDataByFunction = groupData(lineDataArray, x => x.function_name); | ||
let tooltip = createTooltipForCalledLine(lineDataByFunction); | ||
let displayText = isNaN(coverageRate) ? ` ${totalCalls.toLocaleString()}x` : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
(the tooltip as well actually), but that can be changed separately
} | ||
|
||
function createCalledLineDecoration(range: vscode.Range, totalCalls: number, lineDataArray: GcovLineData[]) { | ||
function createCalledLineDecoration(range: vscode.Range, totalCalls: number, lineDataArray: GcovLineData[], coverageRate: number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
functionCoverageRate
|
||
function createDecorationsForFile(linesDataOfFile: GcovLineData[]): LineDecorationsGroup { | ||
const decorations = new LineDecorationsGroup(); | ||
function calculateCoverageRate(linesDataOfFile: GcovLineData[]): Map<string, number> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calculateFunctionCoverageRate
totalLineNum++; | ||
calledLineNum += (lineData.count > 0 ? 1 : 0); | ||
} | ||
funcCoverages.set(funcName, 100 * calledLineNum / totalLineNum); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep values between 0 and 1 in general, only multiply with 100 right before drawing.
} | ||
|
||
function isFirstLineOfFunction(funcsDataOfFile: GcovFunctionData[], funcName: string, lineNumber: number): boolean { | ||
const funcData = funcsDataOfFile.find(x => x.name == funcName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has quadratic runtime complexity afaik, because you are iterating over all function names for every line. This can be quite bad in large files (as the ones I'm working with quite often). Better create a map from function name to line number and do lookups in this map.
@xiaoyun94 Is there any chance for you to work on the requested changes? |
@JacquesLucke Isn't that feature included in version 0.5.0 (the one still missing on open-vsx ;-) ? In this case the issue could be closed. |
It will display as format
Signed-off-by: FANG.Ge [email protected]