swift-syntax icon indicating copy to clipboard operation
swift-syntax copied to clipboard

Sometimes a diagnostic warning appears only in the `Issue Navigator`, not in the `Editor` itself.

Open RoBo-Inc opened this issue 7 months ago • 1 comments

Description

Please, refer to this minimal reproducible project.

Steps to Reproduce

In the minimal reproducible project the issue is reproduced already 🙂

RoBo-Inc avatar Jun 06 '25 07:06 RoBo-Inc

Thank you for the super simple reproducer + clear comments @RoBo-Inc!

The issue here is that your .filter and as ... is actually creating a new syntax tree, so the node being passed to the diagnostic constructor has a different root to the original tree and we then can't map it back to the original location. That then causes your diagnostic to be output without a location (and thus not seen in the editor) vs with a location (now seen).

You can see this in the build logs:

<unknown>:0: warning: Type should be defined explicitly. (from macro 'DiagnosticBug')

vs

.../DiagnosticBug/Sources/DiagnosticBugClient/main.swift:5:9: warning: Type should be defined explicitly. (from macro 'DiagnosticBug')

The workaround is to make sure to use the nodes from the original tree when diagnosing. This is a fairly common issue though and one we started looking at in https://github.com/swiftlang/swift-syntax/pull/2118. We really need to finish that off and get it in 😅

bnbarham avatar Jun 14 '25 05:06 bnbarham