@@ -107,42 +107,78 @@ export default class VerilatorLinter extends BaseLinter {
107
107
command ,
108
108
{ cwd : cwd } ,
109
109
( _error : Error , _stdout : string , stderr : string ) => {
110
- let diagnostics : vscode . Diagnostic [ ] = [ ] ;
110
+ //let diagnostics: vscode.Diagnostic[] = [];
111
+
112
+ // basically DiagnosticsCollection but with ability to append diag lists
113
+ let filesDiag = { } ;
114
+ let error_warning_counter = 0 ;
111
115
stderr . split ( / \r ? \n / g) . forEach ( ( line , _ ) => {
112
- if ( line . search ( "No such file or directory" ) >= 0 || line . search ( "Not a directory" ) >= 0 || line . search ( "command not found" ) >= 0 ) {
113
- this . logger . error ( `Could not execute command: ${ command } ` ) ;
114
- return ;
115
- }
116
116
117
- if ( ! line . startsWith ( '%' ) || line . indexOf ( docUri ) <= 0 ) {
117
+ if ( ! line . startsWith ( '%' ) ) {
118
+ this . logger . error ( line ) ;
118
119
return ;
119
120
}
120
121
122
+ // for this regex, match sections are:
123
+ // 1 - severity (warning/error)
124
+ // 3 - error/warning code (EOFNEWLINE, ...),
125
+ // 5 - file path
126
+ // 9 - line number
127
+ // 11 - column number
128
+ // 12 - message
129
+
121
130
let rex = line . match (
122
- / % ( \w + ) ( - [ A - Z 0 - 9 _ ] + ) ? : \s * ( \w + : ) ? (?: [ ^ : ] + ) : \s * ( \d + ) : (?: \s * ( \d + ) : ) ? \s * ( \s * . + ) /
131
+ / ( \w + ) ( - ( [ A - Z 0 - 9 ] + ) ) ? : ( ( \S + ( ( \. s v ) | ( \. v ) ) ) : ( \d + ) : ( ( \d + ) : ) ? ) ? ( . * ) /
123
132
) ;
124
133
134
+ // vscode problems are tied to files, so if there is no file name, no point adding
135
+ if ( ! rex [ 5 ] ) { return ; }
136
+
137
+ // replacing "\\" and "\" with "/" for consistency
138
+ if ( isWindows )
139
+ {
140
+ rex [ 5 ] = rex [ 5 ] . replace ( / ( \\ \\ ) | ( \\ ) / , "/" ) ;
141
+ }
142
+
143
+ // if no errors for this file, new list needs to be created
144
+ if ( ! ( rex [ 5 ] in Object . keys ( filesDiag ) ) )
145
+ {
146
+ filesDiag [ rex [ 5 ] ] = [ ] ;
147
+ }
148
+
149
+
125
150
if ( rex && rex [ 0 ] . length > 0 ) {
126
- let lineNum = Number ( rex [ 4 ] ) - 1 ;
127
- let colNum = Number ( rex [ 5 ] ) - 1 ;
151
+ let lineNum = Number ( rex [ 9 ] ) - 1 ;
152
+ let colNum = Number ( rex [ 11 ] ) - 1 ;
128
153
// Type of warning is in rex[2]
129
154
colNum = isNaN ( colNum ) ? 0 : colNum ; // for older Verilator versions (< 4.030 ~ish)
130
155
131
156
if ( ! isNaN ( lineNum ) ) {
132
- diagnostics . push ( {
157
+ filesDiag [ rex [ 5 ] ] . push ( {
133
158
severity : this . convertToSeverity ( rex [ 1 ] ) ,
134
159
range : new vscode . Range ( lineNum , colNum , lineNum , Number . MAX_VALUE ) ,
135
- message : rex [ 6 ] ,
136
- code : 'verilator' ,
160
+ message : rex [ 12 ] ,
161
+ code : rex [ 3 ] ,
137
162
source : 'verilator' ,
138
163
} ) ;
164
+
165
+ error_warning_counter ++ ;
139
166
}
140
167
return ;
141
168
}
142
169
this . logger . warn ( '[verilator] failed to parse error: ' + line ) ;
143
170
} ) ;
144
- this . logger . info ( `[verilator] ${ diagnostics . length } errors/warnings returned` ) ;
145
- this . diagnosticCollection . set ( doc . uri , diagnostics ) ;
171
+ this . logger . info ( `[verilator] ${ error_warning_counter } errors/warnings returned` ) ;
172
+ this . diagnosticCollection . clear ( )
173
+ for ( let fileName in filesDiag )
174
+ {
175
+ let fileURI = vscode . Uri . file ( fileName ) ;
176
+ // adding diag info for each file
177
+ this . diagnosticCollection . set (
178
+ fileURI ,
179
+ filesDiag [ fileName ]
180
+ ) ;
181
+ }
146
182
}
147
183
) ;
148
184
}
0 commit comments