-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Implement Naming Styles for editorconfig UI #58075
Merged
jmarolf
merged 26 commits into
dotnet:release/dev17.1
from
jmarolf:features/editorconfig-naming-style-support
Dec 7, 2021
Merged
Changes from 8 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
883a2c5
move Language enum further down the stack
jmarolf d77a8f8
implement naming styles option parser with text span support
jmarolf a7e051a
add folder description
jmarolf 5e5cbc8
Add namging style option support
jmarolf 682a9df
add folder description
jmarolf a773abe
Add views for naming styles
jmarolf 48f54b4
Update src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Nami…
jmarolf 1886364
Update src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Edit…
jmarolf 49088b0
Update src/EditorFeatures/Core/EditorConfigSettings/Updater/NamingSty…
jmarolf da90d81
Update src/EditorFeatures/Core/EditorConfigSettings/Updater/NamingSty…
jmarolf 3a28801
lengthen the search box to align with the tabs above it
jmarolf cbce098
enable nullable on test files
jmarolf 525cb16
de-duplicate local functions
jmarolf 03da9e5
simplify boolean logic
jmarolf 98006e6
use resource strings in tests
jmarolf b53f7d1
return immutable array for static severities
jmarolf 74e9ca0
update readme with a relative path link
jmarolf 761eb1e
using TryPeekNext
jmarolf ba7bdb3
using disposeable pooled objects
jmarolf 2c9fed1
renamge rangeOpt to numberRange
jmarolf 264eefb
fix Span and Section being swapped from the base
jmarolf b2ca734
update incorrect comment
jmarolf a321a3f
Combine Lex with static function
jmarolf 132f6b0
return false if we fail to determine the language for a path
jmarolf cb5cfc0
use Lazy instead of fancy InterlockedInitialize
jmarolf 86ef543
move search bar up by 12 pixels
jmarolf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/EditorFeatures/Core/EditorConfigSettings/Data/NamingStyleSetting.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles; | ||
using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Updater; | ||
using Microsoft.CodeAnalysis.EditorConfig.Parsing.NamingStyles; | ||
using Microsoft.CodeAnalysis.NamingStyles; | ||
|
||
namespace Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Data | ||
{ | ||
internal class NamingStyleSetting | ||
{ | ||
private NamingStyle[] _allStyles; | ||
private readonly NamingStyleSettingsUpdater? _settingsUpdater; | ||
|
||
public NamingStyleSetting( | ||
NamingRule namingRule, | ||
NamingStyle[] allStyles, | ||
NamingStyleSettingsUpdater settingsUpdater, | ||
string? fileName = null) | ||
{ | ||
Style = namingRule.NamingStyle; | ||
_allStyles = allStyles; | ||
Type = namingRule.SymbolSpecification; | ||
Severity = namingRule.EnforcementLevel; | ||
_settingsUpdater = settingsUpdater; | ||
Location = new SettingLocation(fileName is null ? LocationKind.VisualStudio : LocationKind.EditorConfig, fileName); | ||
} | ||
|
||
private NamingStyleSetting() | ||
{ | ||
_allStyles = Array.Empty<NamingStyle>(); | ||
} | ||
|
||
public event EventHandler<EventArgs>? SettingChanged; | ||
|
||
internal static NamingStyleSetting FromParseResult(NamingStyleOption namingStyleOption) | ||
{ | ||
return new NamingStyleSetting | ||
{ | ||
Style = namingStyleOption.NamingScheme.AsNamingStyle(), | ||
Type = namingStyleOption.ApplicableSymbolInfo.AsSymbolSpecification(), | ||
Severity = namingStyleOption.Severity, | ||
Location = new SettingLocation(LocationKind.EditorConfig, namingStyleOption.Section.FilePath) | ||
}; | ||
} | ||
|
||
internal NamingStyle Style { get; set; } | ||
internal SymbolSpecification? Type { get; set; } | ||
|
||
public string StyleName => Style.Name; | ||
public string[] AllStyles => _allStyles.Select(style => style.Name).ToArray(); | ||
public string TypeName => Type?.Name ?? string.Empty; | ||
public ReportDiagnostic Severity { get; private set; } | ||
public SettingLocation? Location { get; protected set; } | ||
|
||
private void OnSettingChanged((object, object?) setting) | ||
{ | ||
if (setting is (ReportDiagnostic severity, _)) | ||
{ | ||
Severity = severity; | ||
SettingChanged?.Invoke(this, EventArgs.Empty); | ||
} | ||
|
||
if (setting is (NamingStyle style, NamingStyle[] allStyles)) | ||
{ | ||
Style = style; | ||
_allStyles = allStyles; | ||
SettingChanged?.Invoke(this, EventArgs.Empty); | ||
} | ||
} | ||
|
||
internal void ChangeSeverity(ReportDiagnostic severity) | ||
{ | ||
if (Location is not null) | ||
{ | ||
Location = Location with { LocationKind = LocationKind.EditorConfig }; | ||
_settingsUpdater?.QueueUpdate((OnSettingChanged, this), severity); | ||
} | ||
} | ||
|
||
internal void ChangeStyle(int selectedIndex) | ||
{ | ||
if (selectedIndex > -1 && selectedIndex < _allStyles.Length && Location is not null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this throw index out of bounds? |
||
{ | ||
Location = Location with { LocationKind = LocationKind.EditorConfig }; | ||
_settingsUpdater?.QueueUpdate((OnSettingChanged, this), _allStyles[selectedIndex]); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This should be
ImmutableArray<string>