ryanluker / vscode-coverage-gutters

Display test coverage generated by lcov and xml - works with many languages
https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters
MIT License
460 stars 88 forks source link

remotePathResolve not working for every path #366

Open der-schick96 opened 2 years ago

der-schick96 commented 2 years ago

Describe the bug The resolveRemotePaths cannot resolve every path correctly.

To Reproduce Steps to reproduce the behaviour:

Expected behaviour The coverage is rendered.

Outcome The extensions fails to resolve any path, but does not give a warning or error.

I actually found the cause of the bug. The path is resolved with the following function:

sectionfinder.ts:81

private resolveFileName(fileName: string): string {
        let potentialFileName = fileName;
        const remoteLocalPaths = this.configStore.remotePathResolve;
        if (remoteLocalPaths) {
            const remoteFragment = remoteLocalPaths[0];
            const localFragment = remoteLocalPaths[1];
            const paths = fileName.split(remoteFragment);

            // If we have a length of two we have a match and can swap the paths
            // Note: this is because split will give us an array of two with the first element
            // being an empty string and the second being the project path.
            if (paths.length === 2) {
                potentialFileName = localFragment + paths[1];
            }
        }
        return potentialFileName;
    }

In my case, i had a path /app/src/app/my_module.py which should be resolved to src/app/my_module.py. With remotePathResolve set to ['/app', ''], the '/app' substring is matched two times by .split, causing the file name resolution to fail. I could fix the issue by changing the setting to ' ['/app'/src, 'src']', but i had to go through the source code to figure this one out.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

ryanluker commented 2 years ago

@der-schick96 Thanks for the ticket and the investigation! Very interesting bug, I agree with your thinking around the issue living in the resolveFileName as well. I will try to put in some time to make a failing test for this function, that uses the scenario you mentioned above, but in the meantime you can use the workaround you found.