Skip to content

fix: When running a linter through WSL, the file where the error occu… #531

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

## [Unreleased]

### Changed

- Fix When running a linter through WSL, the file where the error occurred cannot be correctly indicated [#530](https://github.com/mshr-h/vscode-verilog-hdl-support/issues/530)

## [1.16.0] - 2025-01-23

### Added
Expand Down
18 changes: 16 additions & 2 deletions src/linter/VerilatorLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export default class VerilatorLinter extends BaseLinter {
return child.execSync(cmd, {}).toString().replace(/\r?\n/g, '');
}

private convertFromWslPath(inputPath: string): string {
let cmd: string = `wsl wslpath -w '${inputPath}'`;
return child.execSync(cmd, {}).toString().replace(/\r?\n/g, '');
Copy link
Preview

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

The function does not handle potential errors from execSync. If the wslpath command fails, this will throw an exception without a clear error message indicating the WSL path conversion failed.

Suggested change
return child.execSync(cmd, {}).toString().replace(/\r?\n/g, '');
try {
return child.execSync(cmd, {}).toString().replace(/\r?\n/g, '');
} catch (error) {
this.logger.error(`Failed to convert WSL path: ${inputPath}. Error: ${error.message}`);
return inputPath; // Fallback to the original path
}

Copilot uses AI. Check for mistakes.

}

protected lint(doc: vscode.TextDocument) {
let docUri: string = isWindows
? this.useWSL
Expand Down Expand Up @@ -137,6 +142,11 @@ export default class VerilatorLinter extends BaseLinter {
}
}

// Remove superfluous NUL from line head
while (line.startsWith('\0')) {
line = line.slice(1);
}

// first line would be normal stderr output like "directory name is invalid"
// others are verilator sort of "highlighting" the issue, the block with "^~~~~"
// this can actually be used for better error/warning highlighting
Expand Down Expand Up @@ -204,9 +214,13 @@ export default class VerilatorLinter extends BaseLinter {
}

// replacing "\\" and "\" with "/" for consistency
if (isWindows)
{
if (isWindows) {
rex.groups["filePath"] = rex.groups["filePath"].replace(/(\\\\)|(\\)/g, "/");

// if WSL is used, convert the path to Windows format
if (this.useWSL) {
rex.groups["filePath"] = this.convertFromWslPath(rex.groups["filePath"]);
}
}

// if there isn't a list of errors for this file already, it
Expand Down