diff --git a/CHANGELOG.md b/CHANGELOG.md index 21d79f3db..eeaa11262 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Fix `Swift: Reset Package Dependencies` command on Windows ([#1614](https://github.com/swiftlang/vscode-swift/pull/1614)) - Activate extension when a .swift source file exists in a subfolder ([#1635](https://github.com/swiftlang/vscode-swift/pull/1635)) - Resolve Swiftly toolchain path ([#1632](https://github.com/swiftlang/vscode-swift/pull/1632)) +- Fix diagnostic parsing when the file has a space in it ([#1633](https://github.com/swiftlang/vscode-swift/pull/1633)) - Hide files excluded with files.exclude from Project Panel ([#1626](https://github.com/swiftlang/vscode-swift/pull/1626)) ## 2.4.0 - 2025-06-11 diff --git a/assets/test/defaultPackage/.vscode/launch copy.json b/assets/test/defaultPackage/.vscode/launch copy.json deleted file mode 100644 index 95580ae16..000000000 --- a/assets/test/defaultPackage/.vscode/launch copy.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "configurations": [ - { - "type": "swift", - "request": "launch", - "name": "Attach to Swift Executable", - "program": "${workspaceFolder}/.build/aarch64-unknown-linux-gnu/debug/PackageExe", - // "attachCommands": [ - // // "gdb-remote 1234", - // // "process launch" - // "platform select remote-linux", - // "platform connect connect://127.0.0.1:1234" - // ], - // "initCommands": [ - // "target create .build/aarch64-unknown-linux-gnu/debug/PackageExe", - // "b main.swift:7", - // ] - "initCommands": [ - "platform select remote-linux", - // "platform connect connect://127.0.0.1:1234", - "gdb-remote 1234", - "settings set target.inherit-env false" - ] - }, - { - "type": "swift", - "request": "launch", - "name": "Debug package1", - "program": "${workspaceFolder:defaultPackage}/.build/debug/package1", - "args": [], - "cwd": "${workspaceFolder:defaultPackage}", - "preLaunchTask": "swift: Build Debug package1" - }, - { - "type": "swift", - "request": "launch", - "name": "Release package1", - "program": "${workspaceFolder:defaultPackage}/.build/release/package1", - "args": [], - "cwd": "${workspaceFolder:defaultPackage}", - "preLaunchTask": "swift: Build Release package1" - }, - { - "type": "swift", - "request": "launch", - "args": [], - "cwd": "${workspaceFolder:defaultPackage}", - "name": "Debug PackageExe", - "program": "${workspaceFolder:defaultPackage}/.build/debug/PackageExe", - "preLaunchTask": "swift: Build Debug PackageExe" - }, - { - "type": "swift", - "request": "launch", - "args": [], - "cwd": "${workspaceFolder:defaultPackage}", - "name": "Release PackageExe", - "program": "${workspaceFolder:defaultPackage}/.build/release/PackageExe", - "preLaunchTask": "swift: Build Release PackageExe" - } - ] -} diff --git a/assets/test/diagnostics/Sources/func.swift b/assets/test/diagnostics/Sources/func in here.swift similarity index 100% rename from assets/test/diagnostics/Sources/func.swift rename to assets/test/diagnostics/Sources/func in here.swift diff --git a/package.json b/package.json index 54448424d..87739a6c0 100644 --- a/package.json +++ b/package.json @@ -426,7 +426,7 @@ }, "swift.diagnosticsStyle": { "type": "string", - "default": "llvm", + "default": "default", "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.", "enum": [ "default", diff --git a/src/DiagnosticsManager.ts b/src/DiagnosticsManager.ts index 2c69a852e..b1ccdc343 100644 --- a/src/DiagnosticsManager.ts +++ b/src/DiagnosticsManager.ts @@ -391,7 +391,7 @@ export class DiagnosticsManager implements vscode.Disposable { line: string ): ParsedDiagnostic | vscode.DiagnosticRelatedInformation | undefined { const diagnosticRegex = - /^(?:\S+\s+)?(.*?):(\d+)(?::(\d+))?:\s+(warning|error|note):\s+(.*)$/g; + /^(?:[`-\s]*)(.*?):(\d+)(?::(\d+))?:\s+(warning|error|note):\s+(.*)$/g; const switfcExtraWarningsRegex = /\[(-W|#).*?\]/g; const match = diagnosticRegex.exec(line); if (!match) { diff --git a/src/configuration.ts b/src/configuration.ts index aba27f81e..7a9739b6e 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -383,7 +383,7 @@ const configuration = { get diagnosticsStyle(): DiagnosticStyle { return vscode.workspace .getConfiguration("swift") - .get("diagnosticsStyle", "llvm"); + .get("diagnosticsStyle", "default"); }, /** where to show the build progress for the running task */ get showBuildStatus(): ShowBuildStatusOptions { diff --git a/test/integration-tests/DiagnosticsManager.test.ts b/test/integration-tests/DiagnosticsManager.test.ts index 473b6802c..9ab4667f3 100644 --- a/test/integration-tests/DiagnosticsManager.test.ts +++ b/test/integration-tests/DiagnosticsManager.test.ts @@ -134,7 +134,7 @@ suite("DiagnosticsManager Test Suite", function () { cFolderContext = await folderInRootWorkspace("diagnosticsC", workspaceContext); cppFolderContext = await folderInRootWorkspace("diagnosticsCpp", workspaceContext); mainUri = testAssetUri("diagnostics/Sources/main.swift"); - funcUri = testAssetUri("diagnostics/Sources/func.swift"); + funcUri = testAssetUri("diagnostics/Sources/func in here.swift"); // Want spaces in name to watch https://github.com/swiftlang/vscode-swift/issues/1630 cUri = testAssetUri("diagnosticsC/Sources/MyPoint/MyPoint.c"); cppUri = testAssetUri("diagnosticsCpp/Sources/MyPoint/MyPoint.cpp"); cppHeaderUri = testAssetUri("diagnosticsCpp/Sources/MyPoint/include/MyPoint.h"); @@ -271,19 +271,50 @@ suite("DiagnosticsManager Test Suite", function () { }); } - runTestDiagnosticStyle("default", () => ({ - [mainUri.fsPath]: [ - expectedWarningDiagnostic, - expectedMainErrorDiagnostic, - expectedMainDictErrorDiagnostic, - ...(workspaceContext.globalToolchainSwiftVersion.isGreaterThanOrEqual( - new Version(6, 0, 0) - ) - ? [expectedMacroDiagnostic] - : []), - ], // Should have parsed correct severity - [funcUri.fsPath]: [expectedFuncErrorDiagnostic], // Check parsed for other file - })); + runTestDiagnosticStyle( + "default", + () => ({ + [mainUri.fsPath]: [ + expectedWarningDiagnostic, + expectedMainErrorDiagnostic, + expectedMainDictErrorDiagnostic, + ...(workspaceContext.globalToolchainSwiftVersion.isGreaterThanOrEqual( + new Version(6, 0, 0) + ) + ? [expectedMacroDiagnostic] + : []), + ], // Should have parsed correct severity + [funcUri.fsPath]: [expectedFuncErrorDiagnostic], // Check parsed for other file + }), + () => { + test("Parses related information", async function () { + if ( + workspaceContext.globalToolchainSwiftVersion.isLessThan( + new Version(6, 1, 0) + ) + ) { + this.skip(); + } + const diagnostic = assertHasDiagnostic(mainUri, expectedMacroDiagnostic); + // Should have parsed related note + assert.equal(diagnostic.relatedInformation?.length, 1); + assert.equal( + diagnostic.relatedInformation![0].message, + "Expanded code originates here" + ); + assert.equal( + diagnostic.relatedInformation![0].location.uri.fsPath, + mainUri.fsPath + ); + assert.equal( + diagnostic.relatedInformation![0].location.range.isEqual( + expectedMacroDiagnostic.range + ), + true + ); + }); + } + ); runTestDiagnosticStyle("swift", () => ({ [mainUri.fsPath]: [ diff --git a/test/integration-tests/WorkspaceContext.test.ts b/test/integration-tests/WorkspaceContext.test.ts index ab96f3582..686c5ba96 100644 --- a/test/integration-tests/WorkspaceContext.test.ts +++ b/test/integration-tests/WorkspaceContext.test.ts @@ -123,8 +123,6 @@ suite("WorkspaceContext Test Suite", () => { assert.strictEqual(buildAllTask.name, "Build All (defaultPackage)"); assertContainsArg(execution, "build"); assertContainsArg(execution, "--build-tests"); - assertContainsArg(execution, "-Xswiftc"); - assertContainsArg(execution, "-diagnostic-style=llvm"); assert.strictEqual(buildAllTask.scope, resolveScope(folder.workspaceFolder)); }); diff --git a/test/integration-tests/tasks/SwiftTaskProvider.test.ts b/test/integration-tests/tasks/SwiftTaskProvider.test.ts index c3001564a..3ef51882c 100644 --- a/test/integration-tests/tasks/SwiftTaskProvider.test.ts +++ b/test/integration-tests/tasks/SwiftTaskProvider.test.ts @@ -101,9 +101,7 @@ suite("SwiftTaskProvider Test Suite", () => { }); test("provided", async () => { - expect(task?.detail) - .to.include("swift build --build-tests") - .and.to.include("-Xswiftc -diagnostic-style=llvm"); + expect(task?.detail).to.include("swift build --build-tests"); }); test("executes @slow", async () => { @@ -144,9 +142,7 @@ suite("SwiftTaskProvider Test Suite", () => { test("includes product debug task", async () => { const tasks = await vscode.tasks.fetchTasks({ type: "swift" }); const task = tasks.find(t => t.name === "Build Debug PackageExe (defaultPackage)"); - expect(task?.detail) - .to.include("swift build --product PackageExe") - .and.to.include("-Xswiftc -diagnostic-style=llvm"); + expect(task?.detail).to.include("swift build --product PackageExe"); }); test("includes product release task", async () => {