-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add style option (and UI) for preferring file scoped namespaces #55043
Add style option (and UI) for preferring file scoped namespaces #55043
Conversation
src/Features/CSharp/Portable/ConvertNamespace/ConvertNamespaceCodeFixProvider.cs
Outdated
Show resolved
Hide resolved
…CodeFixProvider.cs
src/Features/CSharp/Portable/ConvertNamespace/ConvertNamespaceCodeRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
…CodeRefactoringProvider.cs
…jmabadi/roslyn into fileScopedNamespaceStyle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both automation object and editorconfig UI need to be updated for this new option.
src/Features/CSharp/Portable/ConvertNamespace/ConvertNamespaceCodeFixProvider.cs
Outdated
Show resolved
Hide resolved
|
||
// if the diagnostic is hidden, show it anywhere from the `namespace` keyword through the name. | ||
// otherwise, if it's not hidden, just squiggle the name. | ||
var diagnosticLocation = severity.WithDefaultSeverity(DiagnosticSeverity.Hidden) == ReportDiagnostic.Hidden |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried the severity
variable here only reflects the option = value:severity
syntax but not reflecting the dotnet_diagnostic.ID.severity = severity
syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this follows what we do with use-expression-body. i'm going to stick with this pattern under teh presumption that it's correct. if not, we shoudl fix it for all of these. i do not want to have multiple different patterns at the same time :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tagging @mavasani to confirm if there is a problem here in which case I'll file an issue.
|
||
var option = optionSet.GetOption(CSharpCodeStyleOptions.PreferFileScopedNamespace); | ||
var userPrefersRegularNamespaces = !option.Value; | ||
var analyzerDisabled = option.Notification.Severity == ReportDiagnostic.Suppress; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here. Notification.Severity
most likely doesn't reflect the dotnet_diagnostic.....
syntax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i reaklly do not want our features to deviate from each other. until there is a suitable new style we should keep our code consistent. Otherwise we'll just have a hodgepodge of impls with varying patterns that people have to udnerstand. If and when we have some new pattern that everything should follow, we can move all our code to that at once.
I haven't looked at the code yet, but is there a more descriptive name than "regular namespace"? Like "block-scoped namespace", or "block bodied namespace" to match how we talk about methods. If new C# templates are going to use top level statements in .NET 6, I could see them using file-scoped namespaces in the same timeframe, or in the future, so that word "regular" will tend to lose its meaning. |
Yes, this is a good point. I will use 'block-bodied' or 'block-scoped' instead :) |
src/Features/CSharp/Portable/ConvertNamespace/ConvertNamespaceCodeRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: #55043 (review) is not addressed yet
@Youssef1313 I'm not doing editorconfig UI until #52343 is addressed. There are just too many duplicated strings in random places that have to be resolved before going that path. |
Co-authored-by: Youssef Victor <youssefvictor00@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmarolf can you either add the EditorConfig side of this, or let me know when we can add EditorConfig settings without duplication? Thanks! |
I second this so that way source generators (like CsWin32) can pick it up and then generate using file scoped namespace. Bonus if something like this can be done to |
@AraHaan as mentioned already, a source generator can see these values when it executes and can generate accordingly. |
UI looks like this:
and
This is exposed through the lightbulb as both an analyzer and a refactoring (similar ot how prefer-expression-body works). The analyzer will enforce the code style if set. The refactoring will allow you to switch to the either direction if you prefer. It looks like this:
Todo:
Relates to test plan: #49000