You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[severity:It's more difficult to complete my work]
There is inconsistency and, I would say, incorrectness in handling of generated code by Visual Studio.
I wrote an incremental source code generator using ForAttributeWithMetadataName and which generates code using IncrementalGeneratorInitializationContext.RegisterSourceOutput. I set <CompilerGeneratedFilesOutputPath> in my Directory.Build.props and the generated code is correctly saved in that location.
The source code generator produces partial classes corresponding to some of the partial source classes.
When I right-click on the name in the "class" declaration line for one of the source classes and use "Go To Implementation" or "Go To Definition", it shows the source and generated file names; when I select the generated file, the editor brings up the cached generated code. Good!
If I right-click and use "Peek Definition" then the peek editor shows the a split with the original source code on the left and again shows the same source and generated files on the right. But when I select the generated file, the editor on the left says "Cannot open file". This is wrong.
When I build the project then it is possible for a compile error to occur due to, for example, a property being defined both in the source partial class and the generated partial class. In this case:
(a) the Error List shows error CS0229 (ambiguity between the two properties), which is a correct message however it does not provide a way to access the generated code, only the original source; and
(b) the Output window shows error CS0102 (class already contains the definition), which is also a correct message however it refers to the copy of the generated code that was saved in the CompilerGeneratedFilesOutputPath so that when I double-click on the Output window message it takes me to the copy of the generated source code that was saved in the CompilerGeneratedFilesOutputPath directory. This is wrong because that code is not included in the compilation; it should take me to the same generated / cached source code as "Go To Implementation" does.
Net/net, the process by which Visual Studio selects and shows generated source code is incorrect for Peek Definition and for going from errors in the Output window to code. The source code accessed by these methods (2 and 3) is not consistent with the correct approach used by (1) above.
I can't really provide my source code to Microsoft but if you create a sample and have any trouble reproducing the above then just provide your sample and I will try to make any adjustments needed to reproduce the error.
Original Comments
Feedback Bot on 1/24/2025, 00:55 AM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Feedback Bot on 1/24/2025, 02:55 AM:
This issue is currently being investigated. Our team will get back to you if either more information is needed, a workaround is available, or the issue is resolved.
The text was updated successfully, but these errors were encountered:
Enable Peek Definition. Seems reasonable if low cost.
Map between compile time errors (And the files referenced there) and the in-memory files we use for SGs in teh IDE. Probably not trivial. If we can make it work, do it.
This issue has been moved from a ticket on Developer Community.
[severity:It's more difficult to complete my work]
There is inconsistency and, I would say, incorrectness in handling of generated code by Visual Studio.
I wrote an incremental source code generator using ForAttributeWithMetadataName and which generates code using IncrementalGeneratorInitializationContext.RegisterSourceOutput. I set <CompilerGeneratedFilesOutputPath> in my Directory.Build.props and the generated code is correctly saved in that location.
The source code generator produces partial classes corresponding to some of the partial source classes.
When I right-click on the name in the "class" declaration line for one of the source classes and use "Go To Implementation" or "Go To Definition", it shows the source and generated file names; when I select the generated file, the editor brings up the cached generated code. Good!
If I right-click and use "Peek Definition" then the peek editor shows the a split with the original source code on the left and again shows the same source and generated files on the right. But when I select the generated file, the editor on the left says "Cannot open file". This is wrong.
When I build the project then it is possible for a compile error to occur due to, for example, a property being defined both in the source partial class and the generated partial class. In this case:
Net/net, the process by which Visual Studio selects and shows generated source code is incorrect for Peek Definition and for going from errors in the Output window to code. The source code accessed by these methods (2 and 3) is not consistent with the correct approach used by (1) above.
I can't really provide my source code to Microsoft but if you create a sample and have any trouble reproducing the above then just provide your sample and I will try to make any adjustments needed to reproduce the error.
Original Comments
Feedback Bot on 1/24/2025, 00:55 AM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Feedback Bot on 1/24/2025, 02:55 AM:
This issue is currently being investigated. Our team will get back to you if either more information is needed, a workaround is available, or the issue is resolved.
The text was updated successfully, but these errors were encountered: