-
Notifications
You must be signed in to change notification settings - Fork 161
Add support for emitting serialized diagnostics (.dia) files #1628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
@davbeck Do these files contain absolute paths or something user / host specific? |
|
They are relative to the project root. My understanding is that swift uses the path from the file map and since rules_swift uses paths relative to the project, the diagnostic files contain relative paths. Here's an example: [Target].output_file_map.json: "Apps/Dasher/Layers/Foundation/Core/Sources/Retry/RetryAsync.swift": {
"ast-dump": "bazel-out/darwin_arm64-fastbuild/bin/Apps/Dasher/Layers/Foundation/Core/Core_objs/Sources/Retry/RetryAsync.swift.ast",
"const-values": "bazel-out/darwin_arm64-fastbuild/bin/Apps/Dasher/Layers/Foundation/Core/Core_objs/Sources/Retry/RetryAsync.swift.swiftconstvalues",
"diagnostics": "bazel-out/darwin_arm64-fastbuild/bin/Apps/Dasher/Layers/Foundation/Core/Core_objs/Sources/Retry/RetryAsync.swift.dia",
"object": "bazel-out/darwin_arm64-fastbuild/bin/Apps/Dasher/Layers/Foundation/Core/Core_objs/Sources/Retry/RetryAsync.swift.o"
},Will produce a diagnostic file like this: This is different from the files that swift package manager creates because it uses absolute paths in it output file map. |
This PR adds a new feature swift.emit_diagnostics that enables the Swift compiler to output serialized diagnostics files (.dia). These machine-readable files can be consumed by IDEs, migration tools, and other static analysis utilities.
What I'm using this for at the moment is to replicate the behavior of
swift package migrate(see https://github.com/swiftlang/swift-package-manager/blob/main/Sources/Commands/PackageCommands/Migrate.swift). The .dia files contain fixits and categories so you can use them to automatically apply fixits for a specific category of warnings.I think these files have the potential to be useful in other ways too. For instance these could be connected to Xcode (or another IDE), which was mentioned in #304. Or they could be used to give AI better context similar to what is discussed in https://tuist.dev/blog/2025/11/27/teaching-ai-to-read-xcode-builds.
Full disclosure: most of these changes were made using Cursor and only verified on 1 project. I pieced together the input for the compiler based on source code in the swift package manager.