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

No ability to disable fading for unused private methods analyzer #76396

Closed
timheuer opened this issue Dec 12, 2024 · 21 comments · Fixed by #76520
Closed

No ability to disable fading for unused private methods analyzer #76396

timheuer opened this issue Dec 12, 2024 · 21 comments · Fixed by #76520
Labels
Area-IDE Feature Request help wanted The issue is "up for grabs" - add a comment if you are interested in working on it

Comments

@timheuer
Copy link
Member

Summary

IDE00051 basically grays out unused private methods. Customers are not liking this but also don't want to disable the analyzer all together. It's the visual representation that is annoying. There are also areas where methods are used dynamically that analyzers don't know about.

Background and Motivation

We have other analyzers that 'fade' views, but we enable a toggle to disable the fade.
Image

Proposed Feature

Add the ability to disable the fade with this analyzer

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Dec 12, 2024
@raffaeler
Copy link
Contributor

I started suppressing the IDE0051 with a GlobalSuppression.cs in my project but it’s time expensive and I don’t find this to be appropriate for some reasons:

  1. This is my own choice. Other users may find the fade-out code useful. The GlobalSuppression.cs does not respect users’ choices
  2. The Analyzer finds an “issue” but the way the IDE “notifies” this issue to the user should be left to the IDE and configured by the users (in Tools-Options)
  3. There are several good reasons to keep away the fade-out from some methods as the are used dynamically or via interop. In this specific case, there is probably the need to pair this analyzer with an attribute informing the analyzer to ignore them.

Said that, I don’t like the current behavior at all.

@CyrusNajmabadi
Copy link
Member

Seems reasonable to have an option here.

@raffaeler
Copy link
Contributor

BTW, I hope we don't end up in only having to use an attribute to suppress it.
During the development, it's quite common to start writing code that isn't called yet. In this case you are still modifying the code which is grayed and very hard to read.
Before suppressing the IDE0051 in the file, I used to close VS and continue coding with VSCode, which is really a defeat for VS.

@CyrusNajmabadi
Copy link
Member

BTW, I hope we don't end up in only having to use an attribute to suppress it.

As mentioned, it seems reasonable for there to be an option controlling this.

@sharwell
Copy link
Member

@CyrusNajmabadi What about making the current "Fade out unreachable code" option apply to this as well?

@CyrusNajmabadi
Copy link
Member

@sharwell i'm not opposed to that. both are conceptually 'unreachable' either because flow analysis says we can't reach a particular statement, or because there's no reference to some private member.

@CyrusNajmabadi CyrusNajmabadi added the help wanted The issue is "up for grabs" - add a comment if you are interested in working on it label Dec 12, 2024
@github-project-automation github-project-automation bot moved this to InQueue in Small Fixes Dec 12, 2024
@CyrusNajmabadi
Copy link
Member

We would take an appropriately sized community pr here.

@ddobric
Copy link

ddobric commented Dec 16, 2024

The current fade-out behaviour is disruptive. When writing new private methods, they are not immediately used, and I do not want them to be greyed out. However, the concept of fading out unused methods is excellent.

My recommendation is to include a menu item (possibly in the code analyzer) that allows developers to manually check for unused methods in the code. This approach aligns better with the typical development process.

@Dreamescaper
Copy link
Contributor

Would it be possible to disable fading when the cursor or caret is on that code block?
I'm fine with fading unused code, but not when I'm actually writing it.

@andypoly
Copy link

Summary

IDE00051 basically grays out unused private methods. Customers are not liking this but also don't want to disable the analyzer all together. It's the visual representation that is annoying. There are also areas where methods are used dynamically that analyzers don't know about.

Perfect summary! - it seems an introduced 'feature' which should have therefore been 'opt-in' or easily disabled by a menu option. Personally I really dislike it!

@raffaeler
Copy link
Contributor

How does the analyzer read the VS checkboxes values?
Is there a doc describing this mechanism?

@github-project-automation github-project-automation bot moved this from InQueue to Completed in Small Fixes Dec 19, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged Issues and PRs which have not yet been triaged by a lead label Dec 19, 2024
@janseris
Copy link

janseris commented Feb 22, 2025

This behavior is now even worse in 17.13.
Now also currently written method is dark.
I have always been a very big fan of Visual Studio but what's happening in VS 2022 is terrible.
Change in plus/minus signs for expanding sections in code, broken Blazor C# code editor for many years since its launch in winter 2021, slower and buggy syntax and code coloring and now this?
You are really trying my patience to switch to JetBrains Rider and believe me I am no fan of JetBrains and Java stuff!

Untitled.mp4

@CyrusNajmabadi
Copy link
Member

Roslyn does not control how fading looks. For that, please file an issue with visual studio (that is not us)

If you want to disable fading for this, you can do so @janseris

@CyrusNajmabadi
Copy link
Member

@janseris

Change in plus/minus signs for expanding sections in code,

That is not Roslyn. Please file reports with visual studio.

broken Blazor C# code editor for many years since its launch in winter 2021,

That is not Roslyn. Please let razor or visual studio know.

slower and buggy syntax and code coloring

I'm unaware of any slowdowns here (no customer telemetry indicates any issues there). If you are having issues with these, please file issues. It may be something specific to your configuration.

@janseris
Copy link

janseris commented Feb 23, 2025

@janseris

Change in plus/minus signs for expanding sections in code,

That is not Roslyn. Please file reports with visual studio.

broken Blazor C# code editor for many years since its launch in winter 2021,

That is not Roslyn. Please let razor or visual studio know.

slower and buggy syntax and code coloring

I'm unaware of any slowdowns here (no customer telemetry indicates any issues there). If you are having issues with these, please file issues. It may be something specific to your configuration.

Thank you for clarification.

I have been filing issues like crazy in Visual Studio Feedback since launch of Visual Studio 2022 in winter 2021 but nothing changed. I give up. GitHub issues are at least tracked by people who understand it. Visual Studio Feedback has some tech support people who usually do not understand the issue at all because they seem to be not coding in Visual Studio or C# at all. I have had very hard times explaining.

What is exactly Roslyn? That will help me distinguish where to write the issue.

If you want to disable fading for this, you can do so

How can I disable the fading completely like it was in 17.10 or 17.11 and older (or just reverting to 17.10 would be enough! but I can't do it, I can just revert to previous Visual Studio version which is some kind of 17.12 patch which already has all the issues).

I'm unaware of any slowdowns here (no customer telemetry indicates any issues there). If you are having issues with these, please file issues. It may be something specific to your configuration.

I have no specific configuration but I have large solutions (50 to 90 projects).

Thank you

@CyrusNajmabadi
Copy link
Member

I have been filing issues like crazy in Visual Studio Feedback since launch of Visual Studio 2022 in winter 2021 but nothing changed.

Sorry about that. We can't help with that. It's up to individual vs teams to prioritize issues. If they get very low volumes of feedback, they will often not view a change a worth making (same with us)

What is exactly Roslyn? That will help me distinguish where to write the issue.

We provide c# and VB language analysis support. That then plugs into tools like VS/VSCode/other-tools to give rich language understanding.

How can I disable the fading completely like it was in 17.10 or 17.11 and older (or just reverting to 17.10 would be enough! but I can't do it, I can just revert to previous Visual Studio version which is some kind of 17.12 patch which already has all the issues).

There is an option under tools|options|languages|c#|advanced controlling fading. I'm not in front of a computer, so I can't provide a screen shot right now.

It will be something like: fade unused members.

@raffaeler
Copy link
Contributor

I just discovered this by reading this last comment.
It is definitely hard to discover the fixes. I hope this setting is saved in the roaming profile data.

Here is the screenshot:
Image

@raffaeler
Copy link
Contributor

FYI: I just found a bug.
If you turn the fading option off, the unused code is still faded out.
I must close the file and re-open to see the unused code unfaded.

@CyrusNajmabadi is this a Roslyn or a VS bug? (Where should I open the issue?)

@CyrusNajmabadi
Copy link
Member

That's a Roslyn bug.

@raffaeler
Copy link
Contributor

@CyrusNajmabadi do you want me to open a new issue or you keep this one as the reference for this bug?

@CyrusNajmabadi
Copy link
Member

Make a new issue. This issue is closed as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Feature Request help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

8 participants