Skip to content
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

Visual Studio handling of generated code #76915

Open
vsfeedback opened this issue Jan 24, 2025 · 3 comments
Open

Visual Studio handling of generated code #76915

vsfeedback opened this issue Jan 24, 2025 · 3 comments
Milestone

Comments

@vsfeedback
Copy link

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.

  1. 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!

  2. 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.

  3. 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.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Jan 24, 2025
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

1 similar comment
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@CyrusNajmabadi
Copy link
Member

A bunch of requests here.

  1. Enable Peek Definition. Seems reasonable if low cost.
  2. 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.

@CyrusNajmabadi CyrusNajmabadi added Area-IDE Feature - Source Generators Source Generators and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 24, 2025
@CyrusNajmabadi CyrusNajmabadi added this to the Backlog milestone Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants