Skip to content

Commit 46e2fe4

Browse files
Ievgenii.MykhalevskyiIevgenii.Mykhalevskyi
Ievgenii.Mykhalevskyi
authored and
Ievgenii.Mykhalevskyi
committed
added tests for problem parser resolver
fixed infinity loop with building command
1 parent e8a260a commit 46e2fe4

13 files changed

+3475
-117
lines changed

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
"testConfiguration": "${workspaceFolder}/.vscode-test.mjs",
2626
"args": [
2727
"--extensionDevelopmentPath=${workspaceFolder}",
28-
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
28+
"--extensionTestsPath=${workspaceFolder}/out/test/"
2929
],
3030
"outFiles": [
3131
"${workspaceFolder}/out/test/**/*.js"
3232
],
33-
"preLaunchTask": "${defaultBuildTask}"
33+
"preLaunchTask": "npm: pretest"
3434
},
3535
{
3636
"name": "Show IOS",

.vscode/tasks.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@
1717
"isDefault": true
1818
}
1919
},
20+
{
21+
"type": "npm",
22+
"script": "pretest",
23+
"group": "build",
24+
"problemMatcher": "$esbuild-watch",
25+
"isBackground": true,
26+
"label": "npm: pretest",
27+
"dependsOn": [
28+
"npm: watch:tsc",
29+
"npm: watch:esbuild"
30+
],
31+
"presentation": {
32+
"group": "watch",
33+
"reveal": "never"
34+
}
35+
},
2036
{
2137
"type": "npm",
2238
"script": "watch:esbuild",

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## 0.5.9 - 2024-11-20
4+
5+
### Fixed
6+
7+
- Build was looped at error
8+
39
## 0.5.8 - 2024-11-20
410

511
### Fixed

make.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ npm run test
1717

1818
vsce package
1919

20-
code --install-extension vscode-ios-0.5.8.vsix
20+
code --install-extension vscode-ios-0.5.9.vsix

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"recommendation": [
4646
"connor4312.esbuild-problem-matchers"
4747
],
48-
"version": "0.5.8",
48+
"version": "0.5.9",
4949
"os": [
5050
"darwin"
5151
],

src/ProblemDiagnosticResolver.ts

Lines changed: 115 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class RawBuildParser {
1818
}
1919

2020
export class ProblemDiagnosticResolver implements HandleProblemDiagnosticResolver {
21-
private static xcodebuild = "xcodebuild";
21+
static xcodebuild = "xcodebuild";
2222
static isSourcekit: SourcePredicate = source => this.xcodebuild !== source;
2323
static isXcodebuild: SourcePredicate = source => this.xcodebuild === source;
2424

@@ -205,7 +205,7 @@ export class ProblemDiagnosticResolver implements HandleProblemDiagnosticResolve
205205
}
206206
if (lastErrorIndex !== -1) {
207207
rawParser.triggerCharacter = "^";
208-
const problems = this.parseBuildLog(
208+
const problems = parseBuildLog(
209209
rawParser.buildLogFile,
210210
rawParser.stdout.substring(0, lastErrorIndex + 1),
211211
rawParser.numberOfLines
@@ -238,134 +238,138 @@ export class ProblemDiagnosticResolver implements HandleProblemDiagnosticResolve
238238
this.buildErrors.clear();
239239
}
240240
}
241+
}
241242

242-
private problemPattern = /^(.*?):(\d+)(?::(\d+))?:\s+(warning|error|note):\s+(.*)$/gm;
243-
private problemLinkerPattern = /^(clang):\s+(error):\s+(.*)$/gm;
244-
private frameworkErrorPattern = /^(error: )(.*?)$/gm;
243+
const problemPattern = /^(.*?):(\d+)(?::(\d+))?:\s+(warning|error|note):\s+(.*)$/gm;
244+
const problemLinkerPattern = /^(clang):\s+(error):\s+(.*)$/gm;
245+
const frameworkErrorPattern = /^(error: )(.*?)$/gm;
245246

246-
private column(output: string, messageEnd: number) {
247-
let newLineCounter = 0;
248-
let str = "";
249-
let shouldBreak = false;
250-
for (let i = messageEnd; i < output.length; ++i) {
251-
if (output[i] === "\n") {
252-
if (shouldBreak) {
253-
break;
254-
}
255-
str = "";
256-
newLineCounter += 1;
257-
} else {
258-
str += output[i];
259-
}
260-
if (output[i] === "^") {
261-
shouldBreak = true;
262-
}
263-
if (newLineCounter >= 3) {
247+
function column(output: string, messageEnd: number) {
248+
let newLineCounter = 0;
249+
let str = "";
250+
let shouldBreak = false;
251+
for (let i = messageEnd; i < output.length; ++i) {
252+
if (output[i] === "\n") {
253+
if (shouldBreak) {
264254
break;
265255
}
256+
str = "";
257+
newLineCounter += 1;
258+
} else {
259+
str += output[i];
266260
}
267-
let start = str.length,
268-
end = 0;
269-
for (let i = 0; i < str.length; ++i) {
270-
if (str[i] !== " ") {
271-
start = Math.min(i, start);
272-
end = Math.max(end, i);
273-
}
261+
if (output[i] === "^") {
262+
shouldBreak = true;
274263
}
275-
if (start > end) {
276-
return [0, 10000];
264+
if (newLineCounter >= 3) {
265+
break;
277266
}
278-
return [start, end];
279267
}
268+
let start = str.length,
269+
end = 0;
270+
for (let i = 0; i < str.length; ++i) {
271+
if (str[i] !== " ") {
272+
start = Math.min(i, start);
273+
end = Math.max(end, i);
274+
}
275+
}
276+
if (start > end) {
277+
return [0, 10000];
278+
}
279+
return [start, end];
280+
}
280281

281-
private parseBuildLog(buildLogFile: string, output: string, numberOfLines: number) {
282-
const files: { [key: string]: vscode.Diagnostic[] } = {};
283-
try {
284-
let matches = [...output.matchAll(this.problemPattern)];
285-
for (const match of matches) {
286-
const file = match[1];
287-
const line = Number(match[2]) - 1;
288-
const column = this.column(output, (match?.index || 0) + match[0].length);
289-
290-
const severity = match[4];
291-
const message = match[5];
292-
let errorSeverity = vscode.DiagnosticSeverity.Error;
282+
function parseBuildLog(buildLogFile: string, output: string, numberOfLines: number) {
283+
const files: { [key: string]: vscode.Diagnostic[] } = {};
284+
try {
285+
let matches = [...output.matchAll(problemPattern)];
286+
for (const match of matches) {
287+
const file = match[1];
288+
const line = Number(match[2]) - 1;
289+
const localColumn = column(output, (match?.index || 0) + match[0].length);
293290

294-
switch (severity) {
295-
case "warning":
296-
errorSeverity = vscode.DiagnosticSeverity.Warning;
297-
break;
298-
case "note":
299-
errorSeverity = vscode.DiagnosticSeverity.Information;
300-
break;
301-
default:
302-
break;
303-
}
291+
const severity = match[4];
292+
const message = match[5];
293+
let errorSeverity = vscode.DiagnosticSeverity.Error;
304294

305-
const diagnostic = new vscode.Diagnostic(
306-
new vscode.Range(
307-
new vscode.Position(line, column[0]),
308-
new vscode.Position(line, column[1])
309-
),
310-
message,
311-
errorSeverity
312-
);
313-
diagnostic.source = ProblemDiagnosticResolver.xcodebuild;
314-
const value = files[file] || [];
315-
value.push(diagnostic);
316-
if (fs.existsSync(file)) {
317-
files[file] = value;
318-
}
295+
switch (severity) {
296+
case "warning":
297+
errorSeverity = vscode.DiagnosticSeverity.Warning;
298+
break;
299+
case "note":
300+
errorSeverity = vscode.DiagnosticSeverity.Information;
301+
break;
302+
default:
303+
break;
319304
}
320-
// parsing linker errors
321-
matches = [...output.matchAll(this.problemLinkerPattern)];
322-
for (const match of matches) {
323-
const file = buildLogFile;
324-
325-
let line = numberOfLines;
326-
for (let i = 0; i < (match.index || 0); ++i) {
327-
line += output[i] === "\n" ? 1 : 0;
328-
}
329-
330-
const message = match[3];
331-
const errorSeverity = vscode.DiagnosticSeverity.Error;
332305

333-
const diagnostic = new vscode.Diagnostic(
334-
new vscode.Range(new vscode.Position(line, 0), new vscode.Position(line, 0)),
335-
message,
336-
errorSeverity
337-
);
338-
diagnostic.source = ProblemDiagnosticResolver.xcodebuild;
339-
const value = files[file] || [];
340-
value.push(diagnostic);
306+
const diagnostic = new vscode.Diagnostic(
307+
new vscode.Range(
308+
new vscode.Position(line, localColumn[0]),
309+
new vscode.Position(line, localColumn[1])
310+
),
311+
message,
312+
errorSeverity
313+
);
314+
diagnostic.source = ProblemDiagnosticResolver.xcodebuild;
315+
const value = files[file] || [];
316+
value.push(diagnostic);
317+
if (fs.existsSync(file)) {
341318
files[file] = value;
342319
}
343-
// parsing framework errors
344-
matches = [...output.matchAll(this.frameworkErrorPattern)];
345-
for (const match of matches) {
346-
const file = buildLogFile;
320+
}
321+
// parsing linker errors
322+
matches = [...output.matchAll(problemLinkerPattern)];
323+
for (const match of matches) {
324+
const file = buildLogFile;
347325

348-
let line = numberOfLines;
349-
for (let i = 0; i < (match.index || 0); ++i) {
350-
line += output[i] === "\n" ? 1 : 0;
351-
}
326+
let line = numberOfLines;
327+
for (let i = 0; i < (match.index || 0); ++i) {
328+
line += output[i] === "\n" ? 1 : 0;
329+
}
352330

353-
const message = match[2];
354-
const errorSeverity = vscode.DiagnosticSeverity.Error;
331+
const message = match[3];
332+
const errorSeverity = vscode.DiagnosticSeverity.Error;
355333

356-
const diagnostic = new vscode.Diagnostic(
357-
new vscode.Range(new vscode.Position(line, 0), new vscode.Position(line, 0)),
358-
message,
359-
errorSeverity
360-
);
361-
diagnostic.source = ProblemDiagnosticResolver.xcodebuild;
362-
const value = files[file] || [];
363-
value.push(diagnostic);
364-
files[file] = value;
334+
const diagnostic = new vscode.Diagnostic(
335+
new vscode.Range(new vscode.Position(line, 0), new vscode.Position(line, 0)),
336+
message,
337+
errorSeverity
338+
);
339+
diagnostic.source = ProblemDiagnosticResolver.xcodebuild;
340+
const value = files[file] || [];
341+
value.push(diagnostic);
342+
files[file] = value;
343+
}
344+
// parsing framework errors
345+
matches = [...output.matchAll(frameworkErrorPattern)];
346+
for (const match of matches) {
347+
const file = buildLogFile;
348+
349+
let line = numberOfLines;
350+
for (let i = 0; i < (match.index || 0); ++i) {
351+
line += output[i] === "\n" ? 1 : 0;
365352
}
366-
} catch (err) {
367-
console.log(`Error parsing build logs: ${err}`);
353+
354+
const message = match[2];
355+
const errorSeverity = vscode.DiagnosticSeverity.Error;
356+
357+
const diagnostic = new vscode.Diagnostic(
358+
new vscode.Range(new vscode.Position(line, 0), new vscode.Position(line, 0)),
359+
message,
360+
errorSeverity
361+
);
362+
diagnostic.source = ProblemDiagnosticResolver.xcodebuild;
363+
const value = files[file] || [];
364+
value.push(diagnostic);
365+
files[file] = value;
368366
}
369-
return files;
367+
} catch (err) {
368+
console.log(`Error parsing build logs: ${err}`);
370369
}
370+
return files;
371371
}
372+
373+
export const _private = {
374+
parseBuildLog,
375+
};

src/extension.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,17 @@ export async function handleValidationErrors<T>(
479479
if (typeof error === "object" && error !== null && "code" in error) {
480480
switch (error.code) {
481481
case 65: // scheme is not valid
482-
await commandContext.projectEnv.setProjectScheme("");
483-
return await repeatOnChange();
482+
if ("stderr" in error) {
483+
const stderr = error.stderr as string;
484+
const searchPattern = `does not contain a scheme named "${await commandContext.projectEnv.projectScheme}"`;
485+
486+
if (stderr.indexOf(searchPattern) !== -1) {
487+
await commandContext.projectEnv.setProjectScheme("");
488+
return await repeatOnChange();
489+
}
490+
}
491+
break;
492+
484493
case 70: // device destination is not valid
485494
await commandContext.projectEnv.setDebugDeviceID(null);
486495
return await repeatOnChange();

0 commit comments

Comments
 (0)