-
Notifications
You must be signed in to change notification settings - Fork 647
Code coverage removal fix for single line comments #1996
Changes from 5 commits
25a311e
ead2ec5
7898714
11a49c5
5283575
19e22b3
1381a4b
5543a04
a21aa23
ffc5f94
5d7b25f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,12 +257,16 @@ export function applyCodeCoverage(editor: vscode.TextEditor) { | |
* @param e TextDocumentChangeEvent | ||
*/ | ||
export function removeCodeCoverageOnFileChange(e: vscode.TextDocumentChangeEvent) { | ||
if (e.document.languageId !== 'go') { | ||
if (e.document.languageId !== 'go' || e.contentChanges.length < 1) { | ||
return; | ||
} | ||
if (isPartOfComment(e)) { | ||
return; | ||
} | ||
if (vscode.window.visibleTextEditors.every(editor => editor.document !== e.document)) { | ||
return; | ||
} | ||
|
||
clearCoverage(); | ||
} | ||
|
||
|
@@ -305,3 +309,20 @@ export function toggleCoverageCurrentPackage() { | |
}); | ||
}); | ||
} | ||
|
||
export function isPartOfComment(e: vscode.TextDocumentChangeEvent): boolean { | ||
let result = false; | ||
e.contentChanges.every(function (change, index) { | ||
let line = e.document.lineAt(change.range.start); | ||
let text = e.document.getText(line.range); | ||
let idx = text.search('//'); | ||
let changeIdx = change.range.start.character; | ||
if (idx === -1 || idx > changeIdx || !change.range.isSingleLine || change.text.includes('\n')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add some tests to cover these cases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! Could you please point me to the tests currently present for unit test coverage? I am assuming that I would have to add some test fixtures here and then perform some assertions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please give me some pointers on how to write tests. I ran the tests and seems like currently there are no tests for code coverage. I am assuming these would be the steps I would have to follow :
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, there are no tests for code coverage right now :( For this PR, testing just the
|
||
result = false; | ||
return false; | ||
} else { | ||
result = true; | ||
} | ||
}); | ||
return result; | ||
} |
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.
A
return
statement in the callback passed to the.every
doesnt cause a return fromisPartOfComment
.A
return true
statement in the callback passed to the.every
cause the iteration to continue;A
return false
statement in the callback passed to the.every
cause the iteration to stop;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.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every
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 detailed explanation.