-
Notifications
You must be signed in to change notification settings - Fork 679
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
Remove unused usings on format #5261
Comments
I wonder if there's any documentation on what fixes are considered in formatting and what are not? |
Add this to your settings.json and it should do it.
|
Not working for me. Unused usings still exists after save. Any other solutions or plans to implement this feature in to omnisharp? |
For this to work, I read somewhere that you need to turn on XML comments (sorry, I don't remember where): So, in my project (in my <PropertyGroup>
<!-- Needed to help with 'usings' removal, as some are not removed in case they are in XML comments -->
<GenerateDocumentationFiles>true</GenerateDocumentationFiles>
</PropertyGroup> Then I needed to have an # unused directives
dotnet_diagnostic.IDE0005.severity = none
dotnet_diagnostic.CS8019.severity = silent
# Disable: Missing XML comment for publicly visible type or member
# We only turned on XML comments to help with detecting unused usings
dotnet_diagnostic.CS1591.severity = none A few other relevant but not necessary # File-scoped namespace declarations
dotnet_diagnostic.IDE0161.severity = refactoring
csharp_style_namespace_declarations = file_scoped
# Sort using and Import directives with System.* appearing first
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false
dotnet_style_namespace_match_folder = true
dotnet_diagnostic.IDE0130.severity = warning You can generate a default dotnet new editorconfig |
This works for me, but |
You are expected to control which fixes are enabled and which are not using the editorconfig file. |
@IanIsFluent If you are using OmniSharp, you would need to additionally enable |
@terdong's fix works for me, but does anyone know why it doesn't work with the newer LSP powered version of the extension? Is it a roslyn thing, the extension itself or just up to configuration? Struggling to find any information about it |
Any one still struggling with this, do this: Press Ctrl + . (Control key + period key) for Windows or Command + . for Mac when the cursor is inside the file. |
I maintain an extension called C# Organize Usings (repo) that can also handle this, along with sorting & spacing as well. It's compatible with both Omnisharp and Roslyn and it can be configured to run "on save". |
Is your feature request related to a problem? Please describe.
tl;dr: OmniSharp should allow configuring the formatter (omnisharp.json) to remove unused imports.
#1245 shows that it is possible to "remove unused usings" in a document using Omnisharp. However, this feature cannot be used during a "Format" operation (as per comment #1245 (comment)). Only "organizing" imports is possible via the omnisharp.json configuration (#1686).
Describe the solution you would like
OmniSharp should allow configuring the formatter (omnisharp.json) to remove unused imports.
Applicable Scenarios
The text was updated successfully, but these errors were encountered: