Skip to content

Commit 0fb2c79

Browse files
committed
refactor
1 parent 9fd69fb commit 0fb2c79

File tree

2 files changed

+49
-49
lines changed

2 files changed

+49
-49
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66

77
## [1.x.y] - Unreleased
88

9-
- Added options for Icarus Verilog linting.
9+
- Added experimental options for Icarus Verilog linting.
1010
- `verilog.linting.iverilog.includePath` is to specify include directory.
1111
- `verilog.linting.iverilog.verilogHDL.standard` is to specify standard rules for Verilog-HDL files.
1212
- `verilog.linting.iverilog.systemVerilog.standard` is to specify standard rules for SystemVerilog files.

src/linter/IcarusLinter.ts

+48-48
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ let standardToArg: Map<string, string> = new Map<string, string>([
1313
]);
1414

1515
export default class IcarusLinter extends BaseLinter {
16-
private linterDir: string;
16+
private configuration: vscode.WorkspaceConfiguration;
17+
private linterInstalledPath: string;
1718
private arguments: string;
1819
private includePath: string[];
1920
private standards: Map<string, string>;
@@ -28,27 +29,18 @@ export default class IcarusLinter extends BaseLinter {
2829
}
2930

3031
private updateConfig() {
31-
this.linterDir = <string>vscode.workspace.getConfiguration().get('verilog.linting.path');
32-
this.arguments = <string>(
33-
vscode.workspace.getConfiguration().get('verilog.linting.iverilog.arguments')
34-
);
35-
let path = <string[]>(
36-
vscode.workspace.getConfiguration().get('verilog.linting.iverilog.includePath')
32+
this.linterInstalledPath = <string>(
33+
vscode.workspace.getConfiguration().get('verilog.linting.path')
3734
);
35+
this.configuration = vscode.workspace.getConfiguration('verilog.linting.iverilog');
36+
this.arguments = <string>this.configuration.get('arguments');
37+
let path = <string[]>this.configuration.get('includePath');
3838
this.includePath = path.map((includePath: string) => this.resolvePath(includePath));
3939
this.standards = new Map<string, string>([
40-
[
41-
'verilog',
42-
vscode.workspace.getConfiguration().get('verilog.linting.iverilog.verilogHDL.standard'),
43-
],
44-
[
45-
'systemverilog',
46-
vscode.workspace.getConfiguration().get('verilog.linting.iverilog.systemVerilog.standard'),
47-
],
40+
['verilog', this.configuration.get('verilogHDL.standard')],
41+
['systemverilog', this.configuration.get('systemVerilog.standard')],
4842
]);
49-
this.runAtFileLocation = <boolean>(
50-
vscode.workspace.getConfiguration().get('verilog.linting.iverilog.runAtFileLocation')
51-
);
43+
this.runAtFileLocation = <boolean>this.configuration.get('runAtFileLocation');
5244
}
5345

5446
// returns absolute path
@@ -60,7 +52,7 @@ export default class IcarusLinter extends BaseLinter {
6052
}
6153

6254
protected lint(doc: vscode.TextDocument) {
63-
this.logger.info('[iverilog-lint] iverilog lint requested');
55+
let binPath: string = path.join(this.linterInstalledPath, 'iverilog');
6456

6557
let args: string[] = [];
6658
args.push('-t null');
@@ -70,7 +62,7 @@ export default class IcarusLinter extends BaseLinter {
7062
args.push(this.arguments);
7163
args.push(doc.uri.fsPath);
7264

73-
let command: string = path.join(this.linterDir, 'iverilog') + ' ' + args.join(' ');
65+
let command: string = binPath + ' ' + args.join(' ');
7466

7567
let cwd: string = this.runAtFileLocation
7668
? path.dirname(doc.uri.fsPath)
@@ -85,41 +77,49 @@ export default class IcarusLinter extends BaseLinter {
8577
{ cwd: cwd },
8678
(_error: Error, _stdout: string, stderr: string) => {
8779
let diagnostics: vscode.Diagnostic[] = [];
88-
let lines = stderr.split(/\r?\n/g);
8980
// Parse output lines
90-
lines.forEach((line, _) => {
91-
if (line.startsWith(doc.fileName)) {
92-
line = line.replace(doc.fileName, '');
93-
let terms = line.split(':');
94-
let lineNum = parseInt(terms[1].trim()) - 1;
95-
if (terms.length == 3) {
96-
diagnostics.push({
97-
severity: vscode.DiagnosticSeverity.Error,
98-
range: new vscode.Range(lineNum, 0, lineNum, Number.MAX_VALUE),
99-
message: terms[2].trim(),
100-
code: 'iverilog',
101-
source: 'iverilog',
102-
});
103-
} else if (terms.length >= 4) {
104-
let sev: vscode.DiagnosticSeverity;
105-
if (terms[2].trim() == 'error') {
81+
// the message is something like this
82+
// /home/ubuntu/project1/module_1.sv:3: syntax error"
83+
// /home/ubuntu/project1/property_1.sv:3: error: Invalid module instantiation"
84+
stderr.split(/\r?\n/g).forEach((line, _) => {
85+
if (!line.startsWith(doc.fileName)) {
86+
return;
87+
}
88+
line = line.replace(doc.fileName, '');
89+
let terms = line.split(':');
90+
let lineNum = parseInt(terms[1].trim()) - 1;
91+
if (terms.length === 3) {
92+
diagnostics.push({
93+
severity: vscode.DiagnosticSeverity.Error,
94+
range: new vscode.Range(lineNum, 0, lineNum, Number.MAX_VALUE),
95+
message: terms[2].trim(),
96+
code: 'iverilog',
97+
source: 'iverilog',
98+
});
99+
} else if (terms.length >= 4) {
100+
let sev: vscode.DiagnosticSeverity;
101+
switch (terms[2].trim()) {
102+
case 'error':
106103
sev = vscode.DiagnosticSeverity.Error;
107-
} else if (terms[2].trim() == 'warning') {
104+
break;
105+
case 'warning':
108106
sev = vscode.DiagnosticSeverity.Warning;
109-
} else {
107+
break;
108+
default:
110109
sev = vscode.DiagnosticSeverity.Information;
111-
}
112-
diagnostics.push({
113-
severity: sev,
114-
range: new vscode.Range(lineNum, 0, lineNum, Number.MAX_VALUE),
115-
message: terms[3].trim(),
116-
code: 'iverilog',
117-
source: 'iverilog',
118-
});
119110
}
111+
diagnostics.push({
112+
severity: sev,
113+
range: new vscode.Range(lineNum, 0, lineNum, Number.MAX_VALUE),
114+
message: terms[3].trim(),
115+
code: 'iverilog',
116+
source: 'Icarus Verilog',
117+
});
120118
}
121119
});
122-
this.logger.info('[iverilog-lint] ' + diagnostics.length + ' errors/warnings returned');
120+
if (diagnostics.length > 0) {
121+
this.logger.info('[iverilog-lint] ' + diagnostics.length + ' errors/warnings returned');
122+
}
123123
this.diagnosticCollection.set(doc.uri, diagnostics);
124124
}
125125
);

0 commit comments

Comments
 (0)