diff --git a/CHANGELOG.md b/CHANGELOG.md index 268080d4..c11b77d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/linter/VerilatorLinter.ts b/src/linter/VerilatorLinter.ts index d393730d..4960d8bc 100644 --- a/src/linter/VerilatorLinter.ts +++ b/src/linter/VerilatorLinter.ts @@ -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, ''); + } + protected lint(doc: vscode.TextDocument) { let docUri: string = isWindows ? this.useWSL @@ -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 @@ -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