@@ -13,7 +13,8 @@ let standardToArg: Map<string, string> = new Map<string, string>([
13
13
] ) ;
14
14
15
15
export default class IcarusLinter extends BaseLinter {
16
- private linterDir : string ;
16
+ private configuration : vscode . WorkspaceConfiguration ;
17
+ private linterInstalledPath : string ;
17
18
private arguments : string ;
18
19
private includePath : string [ ] ;
19
20
private standards : Map < string , string > ;
@@ -28,27 +29,18 @@ export default class IcarusLinter extends BaseLinter {
28
29
}
29
30
30
31
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' )
37
34
) ;
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' ) ;
38
38
this . includePath = path . map ( ( includePath : string ) => this . resolvePath ( includePath ) ) ;
39
39
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' ) ] ,
48
42
] ) ;
49
- this . runAtFileLocation = < boolean > (
50
- vscode . workspace . getConfiguration ( ) . get ( 'verilog.linting.iverilog.runAtFileLocation' )
51
- ) ;
43
+ this . runAtFileLocation = < boolean > this . configuration . get ( 'runAtFileLocation' ) ;
52
44
}
53
45
54
46
// returns absolute path
@@ -60,7 +52,7 @@ export default class IcarusLinter extends BaseLinter {
60
52
}
61
53
62
54
protected lint ( doc : vscode . TextDocument ) {
63
- this . logger . info ( '[ iverilog-lint] iverilog lint requested ') ;
55
+ let binPath : string = path . join ( this . linterInstalledPath , ' iverilog') ;
64
56
65
57
let args : string [ ] = [ ] ;
66
58
args . push ( '-t null' ) ;
@@ -70,7 +62,7 @@ export default class IcarusLinter extends BaseLinter {
70
62
args . push ( this . arguments ) ;
71
63
args . push ( doc . uri . fsPath ) ;
72
64
73
- let command : string = path . join ( this . linterDir , 'iverilog' ) + ' ' + args . join ( ' ' ) ;
65
+ let command : string = binPath + ' ' + args . join ( ' ' ) ;
74
66
75
67
let cwd : string = this . runAtFileLocation
76
68
? path . dirname ( doc . uri . fsPath )
@@ -85,41 +77,49 @@ export default class IcarusLinter extends BaseLinter {
85
77
{ cwd : cwd } ,
86
78
( _error : Error , _stdout : string , stderr : string ) => {
87
79
let diagnostics : vscode . Diagnostic [ ] = [ ] ;
88
- let lines = stderr . split ( / \r ? \n / g) ;
89
80
// 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' :
106
103
sev = vscode . DiagnosticSeverity . Error ;
107
- } else if ( terms [ 2 ] . trim ( ) == 'warning' ) {
104
+ break ;
105
+ case 'warning' :
108
106
sev = vscode . DiagnosticSeverity . Warning ;
109
- } else {
107
+ break ;
108
+ default :
110
109
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
- } ) ;
119
110
}
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
+ } ) ;
120
118
}
121
119
} ) ;
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
+ }
123
123
this . diagnosticCollection . set ( doc . uri , diagnostics ) ;
124
124
}
125
125
) ;
0 commit comments