(lines: string, inputFilename?: string, pathPrefix?: string)
| 257 | } |
| 258 | |
| 259 | export function parseRustOutput(lines: string, inputFilename?: string, pathPrefix?: string) { |
| 260 | const inputBasename = inputFilename ? path.basename(inputFilename) : undefined; |
| 261 | const quickfixes: {re: RegExp; makeFix: (match: string[]) => Fix}[] = [ |
| 262 | { |
| 263 | re: / *help: add `#!\[feature\((.*?)\)]`/, |
| 264 | makeFix: ([_, featureName]) => ({ |
| 265 | title: `Add feature flag \`${featureName}\``, |
| 266 | edits: [ |
| 267 | { |
| 268 | line: 1, |
| 269 | column: 1, |
| 270 | endline: 1, |
| 271 | endcolumn: 1, |
| 272 | text: `#![feature(${featureName})]\n`, |
| 273 | }, |
| 274 | ], |
| 275 | }), |
| 276 | }, |
| 277 | { |
| 278 | re: / *(\d+) *\+ ( *)use (.*?);$/, |
| 279 | makeFix: ([_, line, indentation, path]) => ({ |
| 280 | title: `Add import for \`${path}\``, |
| 281 | edits: [ |
| 282 | { |
| 283 | line: Number.parseInt(line, 10), |
| 284 | column: 1, |
| 285 | endline: Number.parseInt(line, 10), |
| 286 | endcolumn: 1, |
| 287 | text: `${indentation}use ${path};\n`, |
| 288 | }, |
| 289 | ], |
| 290 | }), |
| 291 | }, |
| 292 | ]; |
| 293 | |
| 294 | const re = /^\s+-->\s+(?<filename>.*):(?<line>\d+):(?<column>\d+)/; |
| 295 | const result: ResultLine[] = []; |
| 296 | let currentDiagnostic: ResultLine | undefined; |
| 297 | eachLine(lines, line => { |
| 298 | line = _parseOutputLine(line, inputFilename, pathPrefix); |
| 299 | if (line !== null) { |
| 300 | const lineObj: ResultLine = {text: line}; |
| 301 | const filteredLine = filterEscapeSequences(line); |
| 302 | const match = filteredLine.match(re); |
| 303 | |
| 304 | if (match?.groups) { |
| 305 | const file = |
| 306 | match.groups.filename === '<source>' ? inputBasename : path.basename(match.groups.filename); |
| 307 | const line = Number.parseInt(match.groups.line, 10); |
| 308 | const column = Number.parseInt(match.groups.column, 10); |
| 309 | |
| 310 | currentDiagnostic = result.pop(); |
| 311 | if (currentDiagnostic !== undefined) { |
| 312 | const text = filterEscapeSequences(currentDiagnostic.text); |
| 313 | currentDiagnostic.tag = { |
| 314 | file, |
| 315 | line, |
| 316 | column, |
no test coverage detected