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

Using EnvDTE and vsCMAccess to set an access modifier is causing code deletion #58315

Open
tinaschrepfer opened this issue Dec 14, 2021 · 4 comments

Comments

@tinaschrepfer
Copy link

Routed from microsoft/VSExtensibility#74

Within the Microsoft.VisualStudio.SDK package is the EnvDTE80 assembly. Inside it there are interfaces like CodeFunction2 that allow for an access modifier to be set (e.g. function.Access = vsCMAccess.Public). This used to work as expected for several years, but as I upgraded my extension CodeMaid to use v16.10.31321.278 of this package for VS2022 support it now has negative side effects to the code.

Here's an example:

namespace BugRepro
{
public class Class1
{
#if DEBUG
[Obsolete]
#endif
uint A(uint b) => b;
}
}
If you attempt to set the access modifier on the method A it will delete the #endif line of code. Originally reported here: codecadwallader/codemaid#879

There have been several other issues reported too that we've traced back to attempting to set the access modifiers. It is affecting methods, properties, structs, etc. I can provide more examples if it would be helpful.

Thanks for looking into it and please let me know if there's any way I can be of help!

@jasonmalinowski
Copy link
Member

@codecadwallader was the original bug filer here.

@CyrusNajmabadi
Copy link
Member

If this eventually bubbles down into syntaxgenerator, it's likely that something is forgeting to call 'Isolate' to ensure it's manipulating a node, independent of surrounding trivia.

@CyrusNajmabadi
Copy link
Member

@codecadwaller is there any chance you can move off of codemodel? it's effectively on life-support for us, with very iffy views on how it can even survive potential large scale future architectural changes. The information it provides is already available through the roslyn APIs (which can be used in a safe fashion in the BG as immutable snapshot). And it's much cleaner to try to mutate C#/VB directly using roslyn vs going through codemodel.

@jinujoseph jinujoseph added Concept-Continuous Improvement and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Dec 14, 2021
@jinujoseph jinujoseph added this to the 17.1 milestone Dec 14, 2021
@codecadwallader
Copy link

@CyrusNajmabadi I have investigated a rewrite of CodeMaid to Roslyn several times, but it is a very large under-taking without a clear migration path. I know Roslyn is a hands-down improvement and it's what I wished for back in 2007 when I started with the CodeModel APIs, but unfortunately we've got a lot of CodeModel and RegEx based logic. We also support C++ which isn't a part of Roslyn to my knowledge.

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

5 participants