Skip to content

Commit

Permalink
Merge pull request #14 from visualfc/gop_cover
Browse files Browse the repository at this point in the history
support go+ cover; version go1.20 ~
  • Loading branch information
xushiwei authored Nov 3, 2023
2 parents b85228b + 671d708 commit 47d2dbf
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/goCover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,14 @@ export function applyCodeCoverageToAllEditors(coverProfilePath: string, dir?: st
// the source code file can be non-existent or wrong (go.dev/issues/41222).
// There is no perfect way to guess whether the line/col in coverage profile
// is bogus. At least, we know that 0 or negative values are not true line/col.

// goxls: shadow main startcol = 0
let col = parseInt(parse[3], 10);
if (col < 1 && !filename.endsWith('.go')) {
col = 1;
}
const startLine = parseInt(parse[2], 10);
const startCol = parseInt(parse[3], 10);
const startCol = col;
const endLine = parseInt(parse[4], 10);
const endCol = parseInt(parse[5], 10);
if (startLine < 1 || startCol < 1 || endLine < 1 || endCol < 1) {
Expand Down Expand Up @@ -372,7 +378,13 @@ function setCoverageDataByFilePath(filePath: string, data: CoverageData) {
* @param editor
*/
export function applyCodeCoverage(editor: vscode.TextEditor | undefined) {
if (!editor || editor.document.languageId !== 'go' || editor.document.fileName.endsWith('_test.go')) {
// goxls: check go and go+
if (
!editor ||
(editor.document.languageId !== 'go' && editor.document.languageId !== 'gop') ||
editor.document.fileName.endsWith('_test.go') ||
editor.document.fileName.endsWith('_test.gop')
) {
return;
}
let doc = editor.document.fileName;
Expand Down Expand Up @@ -463,7 +475,7 @@ function detailed(editor: vscode.TextEditor, h: Highlight, opts: vscode.Decorati
* @param e TextDocument
*/
export function removeCodeCoverageOnFileSave(e: vscode.TextDocument) {
if (e.languageId !== 'go' || !isCoverageApplied) {
if ((e.languageId !== 'go' && e.languageId !== 'gop') || !isCoverageApplied) {
return;
}

Expand All @@ -483,7 +495,11 @@ export function removeCodeCoverageOnFileSave(e: vscode.TextDocument) {
* @param e TextDocumentChangeEvent
*/
export function trackCodeCoverageRemovalOnFileChange(e: vscode.TextDocumentChangeEvent) {
if (e.document.languageId !== 'go' || !e.contentChanges.length || !isCoverageApplied) {
if (
(e.document.languageId !== 'go' && e.document.languageId !== 'gop') ||
!e.contentChanges.length ||
!isCoverageApplied
) {
return;
}

Expand Down

0 comments on commit 47d2dbf

Please sign in to comment.