MCPcopy Create free account
hub / github.com/compiler-explorer/compiler-explorer / parseRustOutput

Function parseRustOutput

lib/utils.ts:259–349  ·  view source on GitHub ↗
(lines: string, inputFilename?: string, pathPrefix?: string)

Source from the content-addressed store, hash-verified

257}
258
259export 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,

Callers 5

parseOutputMethod · 0.85
parseOutputMethod · 0.85
parseOutputMethod · 0.85

Calls 7

eachLineFunction · 0.85
_parseOutputLineFunction · 0.85
filterEscapeSequencesFunction · 0.85
parseSeverityFunction · 0.85
matchMethod · 0.80
pushMethod · 0.80
popMethod · 0.45

Tested by

no test coverage detected