Skip to content

Commit 977699c

Browse files
fix: When running a linter through WSL, the file where the error occurred cannot be correctly indicated (#531)
1 parent 73625d7 commit 977699c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

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

7+
## [Unreleased]
8+
9+
### Changed
10+
11+
- 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)
12+
713
## [1.16.0] - 2025-01-23
814

915
### Added

src/linter/VerilatorLinter.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ export default class VerilatorLinter extends BaseLinter {
6565
return child.execSync(cmd, {}).toString().replace(/\r?\n/g, '');
6666
}
6767

68+
private convertFromWslPath(inputPath: string): string {
69+
let cmd: string = `wsl wslpath -w '${inputPath}'`;
70+
return child.execSync(cmd, {}).toString().replace(/\r?\n/g, '');
71+
}
72+
6873
protected lint(doc: vscode.TextDocument) {
6974
let docUri: string = isWindows
7075
? this.useWSL
@@ -137,6 +142,11 @@ export default class VerilatorLinter extends BaseLinter {
137142
}
138143
}
139144

145+
// Remove superfluous NUL from line head
146+
while (line.startsWith('\0')) {
147+
line = line.slice(1);
148+
}
149+
140150
// first line would be normal stderr output like "directory name is invalid"
141151
// others are verilator sort of "highlighting" the issue, the block with "^~~~~"
142152
// this can actually be used for better error/warning highlighting
@@ -204,9 +214,13 @@ export default class VerilatorLinter extends BaseLinter {
204214
}
205215

206216
// replacing "\\" and "\" with "/" for consistency
207-
if (isWindows)
208-
{
217+
if (isWindows) {
209218
rex.groups["filePath"] = rex.groups["filePath"].replace(/(\\\\)|(\\)/g, "/");
219+
220+
// if WSL is used, convert the path to Windows format
221+
if (this.useWSL) {
222+
rex.groups["filePath"] = this.convertFromWslPath(rex.groups["filePath"]);
223+
}
210224
}
211225

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

0 commit comments

Comments
 (0)