Skip to content

Commit 7d54def

Browse files
authored
Fix diagnostic parsing when spaces in file name (#1633)
* Fix diagnostic parsing when spaces in file name Also found way to parse out *some* of the "swift" diagnostic style notes. With that in mind, don't make "llvm" the default diagnostic style since it causes friction when switching between building on the command line and in vscode. Issue: #1350 #1630 * Fix formatting issue * Add changelog entry * Ignore macro related information prior to 6.1 * Remove .only
1 parent f354258 commit 7d54def

File tree

9 files changed

+51
-87
lines changed

9 files changed

+51
-87
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- Fix `Swift: Reset Package Dependencies` command on Windows ([#1614](https://github.com/swiftlang/vscode-swift/pull/1614))
1515
- Activate extension when a .swift source file exists in a subfolder ([#1635](https://github.com/swiftlang/vscode-swift/pull/1635))
1616
- Resolve Swiftly toolchain path ([#1632](https://github.com/swiftlang/vscode-swift/pull/1632))
17+
- Fix diagnostic parsing when the file has a space in it ([#1633](https://github.com/swiftlang/vscode-swift/pull/1633))
1718
- Hide files excluded with files.exclude from Project Panel ([#1626](https://github.com/swiftlang/vscode-swift/pull/1626))
1819

1920
## 2.4.0 - 2025-06-11

assets/test/defaultPackage/.vscode/launch copy.json

Lines changed: 0 additions & 62 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@
426426
},
427427
"swift.diagnosticsStyle": {
428428
"type": "string",
429-
"default": "llvm",
429+
"default": "default",
430430
"markdownDescription": "The formatting style used when printing diagnostics in the Problems panel. Corresponds to the `-diagnostic-style` option to pass to `swiftc` when running `swift` tasks.",
431431
"enum": [
432432
"default",

src/DiagnosticsManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ export class DiagnosticsManager implements vscode.Disposable {
391391
line: string
392392
): ParsedDiagnostic | vscode.DiagnosticRelatedInformation | undefined {
393393
const diagnosticRegex =
394-
/^(?:\S+\s+)?(.*?):(\d+)(?::(\d+))?:\s+(warning|error|note):\s+(.*)$/g;
394+
/^(?:[`-\s]*)(.*?):(\d+)(?::(\d+))?:\s+(warning|error|note):\s+(.*)$/g;
395395
const switfcExtraWarningsRegex = /\[(-W|#).*?\]/g;
396396
const match = diagnosticRegex.exec(line);
397397
if (!match) {

src/configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ const configuration = {
383383
get diagnosticsStyle(): DiagnosticStyle {
384384
return vscode.workspace
385385
.getConfiguration("swift")
386-
.get<DiagnosticStyle>("diagnosticsStyle", "llvm");
386+
.get<DiagnosticStyle>("diagnosticsStyle", "default");
387387
},
388388
/** where to show the build progress for the running task */
389389
get showBuildStatus(): ShowBuildStatusOptions {

test/integration-tests/DiagnosticsManager.test.ts

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ suite("DiagnosticsManager Test Suite", function () {
134134
cFolderContext = await folderInRootWorkspace("diagnosticsC", workspaceContext);
135135
cppFolderContext = await folderInRootWorkspace("diagnosticsCpp", workspaceContext);
136136
mainUri = testAssetUri("diagnostics/Sources/main.swift");
137-
funcUri = testAssetUri("diagnostics/Sources/func.swift");
137+
funcUri = testAssetUri("diagnostics/Sources/func in here.swift"); // Want spaces in name to watch https://github.com/swiftlang/vscode-swift/issues/1630
138138
cUri = testAssetUri("diagnosticsC/Sources/MyPoint/MyPoint.c");
139139
cppUri = testAssetUri("diagnosticsCpp/Sources/MyPoint/MyPoint.cpp");
140140
cppHeaderUri = testAssetUri("diagnosticsCpp/Sources/MyPoint/include/MyPoint.h");
@@ -271,19 +271,50 @@ suite("DiagnosticsManager Test Suite", function () {
271271
});
272272
}
273273

274-
runTestDiagnosticStyle("default", () => ({
275-
[mainUri.fsPath]: [
276-
expectedWarningDiagnostic,
277-
expectedMainErrorDiagnostic,
278-
expectedMainDictErrorDiagnostic,
279-
...(workspaceContext.globalToolchainSwiftVersion.isGreaterThanOrEqual(
280-
new Version(6, 0, 0)
281-
)
282-
? [expectedMacroDiagnostic]
283-
: []),
284-
], // Should have parsed correct severity
285-
[funcUri.fsPath]: [expectedFuncErrorDiagnostic], // Check parsed for other file
286-
}));
274+
runTestDiagnosticStyle(
275+
"default",
276+
() => ({
277+
[mainUri.fsPath]: [
278+
expectedWarningDiagnostic,
279+
expectedMainErrorDiagnostic,
280+
expectedMainDictErrorDiagnostic,
281+
...(workspaceContext.globalToolchainSwiftVersion.isGreaterThanOrEqual(
282+
new Version(6, 0, 0)
283+
)
284+
? [expectedMacroDiagnostic]
285+
: []),
286+
], // Should have parsed correct severity
287+
[funcUri.fsPath]: [expectedFuncErrorDiagnostic], // Check parsed for other file
288+
}),
289+
() => {
290+
test("Parses related information", async function () {
291+
if (
292+
workspaceContext.globalToolchainSwiftVersion.isLessThan(
293+
new Version(6, 1, 0)
294+
)
295+
) {
296+
this.skip();
297+
}
298+
const diagnostic = assertHasDiagnostic(mainUri, expectedMacroDiagnostic);
299+
// Should have parsed related note
300+
assert.equal(diagnostic.relatedInformation?.length, 1);
301+
assert.equal(
302+
diagnostic.relatedInformation![0].message,
303+
"Expanded code originates here"
304+
);
305+
assert.equal(
306+
diagnostic.relatedInformation![0].location.uri.fsPath,
307+
mainUri.fsPath
308+
);
309+
assert.equal(
310+
diagnostic.relatedInformation![0].location.range.isEqual(
311+
expectedMacroDiagnostic.range
312+
),
313+
true
314+
);
315+
});
316+
}
317+
);
287318

288319
runTestDiagnosticStyle("swift", () => ({
289320
[mainUri.fsPath]: [

test/integration-tests/WorkspaceContext.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ suite("WorkspaceContext Test Suite", () => {
123123
assert.strictEqual(buildAllTask.name, "Build All (defaultPackage)");
124124
assertContainsArg(execution, "build");
125125
assertContainsArg(execution, "--build-tests");
126-
assertContainsArg(execution, "-Xswiftc");
127-
assertContainsArg(execution, "-diagnostic-style=llvm");
128126
assert.strictEqual(buildAllTask.scope, resolveScope(folder.workspaceFolder));
129127
});
130128

test/integration-tests/tasks/SwiftTaskProvider.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ suite("SwiftTaskProvider Test Suite", () => {
101101
});
102102

103103
test("provided", async () => {
104-
expect(task?.detail)
105-
.to.include("swift build --build-tests")
106-
.and.to.include("-Xswiftc -diagnostic-style=llvm");
104+
expect(task?.detail).to.include("swift build --build-tests");
107105
});
108106

109107
test("executes @slow", async () => {
@@ -144,9 +142,7 @@ suite("SwiftTaskProvider Test Suite", () => {
144142
test("includes product debug task", async () => {
145143
const tasks = await vscode.tasks.fetchTasks({ type: "swift" });
146144
const task = tasks.find(t => t.name === "Build Debug PackageExe (defaultPackage)");
147-
expect(task?.detail)
148-
.to.include("swift build --product PackageExe")
149-
.and.to.include("-Xswiftc -diagnostic-style=llvm");
145+
expect(task?.detail).to.include("swift build --product PackageExe");
150146
});
151147

152148
test("includes product release task", async () => {

0 commit comments

Comments
 (0)