Conversation
add editorconfig related changes
…than fix everything in the document. also not apply changes to buffer until everything is done rather than doing it per fix.
changed code fix part to use "fix all" and only fixes P1 list rather …
add expression body as one of fix to offer
…ver configured the code cleanup
| <Reference Include="System.Core" /> | ||
| <PackageReference Include="Microsoft.VisualStudio.Shell.15.0" Version="15.0.26730-alpha" /> | ||
| <PackageReference Include="Microsoft.VisualStudio.Shell.Framework" Version="15.0.26730-alpha" /> | ||
| <PackageReference Include="Microsoft.VisualStudio.TextManager.Interop" Version="7.10.6070" /> |
There was a problem hiding this comment.
@jasonmalinowski Is it ok to reference these here from this package? Will this be a concern at all for vs4mac?
There was a problem hiding this comment.
Correct, that can't go there. But this is PR for Personal Review, so at this point @JieCarolHu is still getting things working.
| <value>Code cleanup is not configured</value> | ||
| </data> | ||
| <data name="Config_it_now" xml:space="preserve"> | ||
| <value>Config it now</value> |
There was a problem hiding this comment.
This isn't a good phrase :) Perhaps "Configure it now" instead?
| <value>Config it now</value> | ||
| </data> | ||
| <data name="Donot_show_this_again" xml:space="preserve"> | ||
| <value>Don't show this again</value> |
There was a problem hiding this comment.
name does not match actual value. Also, in general, abbreviations are discouraged from localized messages. So this should be "Do not show this message again".
|
|
||
| namespace Microsoft.CodeAnalysis.Editor.Implementation.Formatting | ||
| { | ||
| [Export] |
There was a problem hiding this comment.
why the direct export?
| using Microsoft.CodeAnalysis.Text; | ||
| using Roslyn.Utilities; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.Editor.Implementation.Formatting |
There was a problem hiding this comment.
Why is the CodeCleanupService in the Formatting namespace?
| internal class CodeCleanupService : ICodeCleanupService | ||
| { | ||
| private static Lazy<IDictionary<PerLanguageOption<bool>, string[]>> _dictionary | ||
| = new Lazy<IDictionary<PerLanguageOption<bool>, string[]>>(GetCodeCleanupOptionMapping); |
There was a problem hiding this comment.
this needs a comment explaining what this is for. it seems very weird htat an option would map statically to any data, given that an option generally represents mutable data.
|
Oh, this is for personal review. will wait until this is ready for comments. |
|
|
||
| namespace Microsoft.CodeAnalysis.Editor.Implementation.Formatting | ||
| { | ||
| public interface ICodeStyleConfigureService : IWorkspaceService |
There was a problem hiding this comment.
you probably not want this to be public type?
|
|
||
| namespace Microsoft.CodeAnalysis.Editor.Implementation.Formatting | ||
| { | ||
| interface ICodeCleanupService |
| return document; | ||
| } | ||
|
|
||
| private List<string> GetEnabledDiagnosticIds(DocumentOptionSet docOptions) |
There was a problem hiding this comment.
IEnumerable < string >
| { | ||
| var diagnosticIds = new List<string>(); | ||
|
|
||
| foreach (var codeCleanupOptions in _optionDiagnosticsMappings.Keys) |
There was a problem hiding this comment.
(var kv in _optionDia....)
There was a problem hiding this comment.
does tuple deconstruct works with keyvaluepair?
|
|
||
| foreach (var codeCleanupOptions in _optionDiagnosticsMappings.Keys) | ||
| { | ||
| if (docOptions.GetOption(codeCleanupOptions)) |
| { | ||
| if (docOptions.GetOption(codeCleanupOptions)) | ||
| { | ||
| diagnosticIds.AddRange(_optionDiagnosticsMappings[codeCleanupOptions]); |
There was a problem hiding this comment.
foreach(var id in kv.Value) yield id
There was a problem hiding this comment.
by the way, is ordering matter? dictionary doesn't maintain ordering of its entries? you might want to just use ImmutableArray((option option, Immutablearray ids)) rather than dictionary since it looks like you won't actually need indexer access for your dictionary.
|
|
||
| private static ImmutableDictionary<PerLanguageOption<bool>, ImmutableArray<string>> GetCodeCleanupOptionMapping() | ||
| { | ||
| var dictionary = new Dictionary<PerLanguageOption<bool>, ImmutableArray<string>>() |
There was a problem hiding this comment.
you can use ImmutableDictionaryBuilder rather than use Dictionary and do ToImmutableDictionary? is it to use built in dictionary object intializer?
There was a problem hiding this comment.
yeah, i don't find a way to use dictionary initializer for Immutable dictionary
| <GroupBox x:Name="FormatDocumentSettingsGroupBox" x:Uid="FormatDocumentSettingsGroupBox" > | ||
| <StackPanel x:Uid="StackPanel_2"> | ||
| <CheckBox x:Name="AreCodeCleanupRulesConfiguredCheckBox" x:Uid="AreCodeCleanupRulesConfiguredCheckBox" Visibility="Hidden" Height="0"/> | ||
| <CheckBox x:Name="AllCSharpFormattingRulesCheckBox" x:Uid="AllCSharpFormattingRulesCheckBox" IsEnabled="False" IsChecked="True"/> |
There was a problem hiding this comment.
I think you don't need this option? user can't change it anyway. and hard to distinguish it with outer clean up since those will call format for their own purpose. it will be impossible for users to know why format is called anyway by whom.
There was a problem hiding this comment.
This checkbox is called out (always checked, not allow to change) in @kuhlenh 's design note.
| </GroupBox> | ||
| <GroupBox x:Name="FormatDocumentSettingsGroupBox" x:Uid="FormatDocumentSettingsGroupBox" > | ||
| <StackPanel x:Uid="StackPanel_2"> | ||
| <CheckBox x:Name="AreCodeCleanupRulesConfiguredCheckBox" x:Uid="AreCodeCleanupRulesConfiguredCheckBox" Visibility="Hidden" Height="0"/> |
There was a problem hiding this comment.
is there reason this hidden checkbox is here?
| FixLanguageFeaturesCheckBox.Content = CSharpVSResources.Fix_language_features; | ||
|
|
||
| // IsCodeCleanupConfiguredCheckBox is hidden all the time, and it tracks if the user ever configured the code cleanup | ||
| BindToOption(AreCodeCleanupRulesConfiguredCheckBox, CodeCleanupOptions.AreCodeCleanupRulesConfigured, LanguageNames.CSharp); |
There was a problem hiding this comment.
I think you don't need to do this but use the Option straight when needed.
| internal void SetCodeCleanupAsConfigured() | ||
| { | ||
| // AreCodeCleanupConfiguredCheckBox is hidden all the time, and it tracks if the user ever configured the code cleanup | ||
| if (!AreCodeCleanupRulesConfiguredCheckBox.IsChecked.HasValue || AreCodeCleanupRulesConfiguredCheckBox.IsChecked.Value == false) |
There was a problem hiding this comment.
you can use "CodeCleanupOptions.AreCodeCleanupRulesConfigured" directly?
There was a problem hiding this comment.
so, if user click "cancel" then we repeatedly show the info bar to users? we might want to split infobar display checking and whether user opt-in to use code clean to 2 different options.
|
Can you use what this does?
http://source.roslyn.io/#Microsoft.VisualStudio.LanguageServices.Implementation/Options/OptionBinding.cs,12
|
|
retest windows_release_vs-integration_prtest please |
|
retest windows_debug_spanish_unit32_prtest please |
| return GetFixesAsync(document, range, includeSuppressionFixes, diagnosticId: null, cancellationToken); | ||
| } | ||
|
|
||
| private async Task<ImmutableArray<CodeFixCollection>> GetFixesAsync(Document document, TextSpan range, bool includeSuppressionFixes, string diagnosticId, CancellationToken cancellationToken) |
There was a problem hiding this comment.
diagnosticId [](start = 148, length = 12)
Nit: Rename to diagnosticIdOpt
| /// this can be expensive since it is force analyzing diagnostics if it doesn't have up-to-date one yet. | ||
| /// </summary> | ||
| Task<IEnumerable<DiagnosticData>> GetDiagnosticsForSpanAsync(Document document, TextSpan range, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default); | ||
| Task<IEnumerable<DiagnosticData>> GetDiagnosticsForSpanAsync(Document document, TextSpan range, bool includeSuppressedDiagnostics = false, string diagnosticId = null, CancellationToken cancellationToken = default); |
There was a problem hiding this comment.
diagnosticId [](start = 154, length = 12)
Rename to diagnosticIdOpt and also add comment explaining the semantics for null and non-null value.
|
created #27497 to add more tests |
| namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Formatting | ||
| { | ||
| [UseExportProvider] | ||
| public class CodeCleanupTests |
There was a problem hiding this comment.
CodeCleanupTests [](start = 17, length = 16)
Synced up with @carhu@microsoft.com offline and she plans to extend the tests, but probably not as part of this PR due to time constraints. I think we should at least have the following tests:
- Simple unit tests, one per option, that verify code cleanup works fine with only single option enabled.
- Unit tests with multiple options enabled, but the reported diagnostics are not conflicting, hence can all be fixed.
- Unit tests with multiple options enabled, where reported diagnostics have conflicting spans and hence not all can be fixed. Is this possible for our currently chosen diagnostics/fixers?
- Verify options persistence after changing the workspace option.
| nameof(CodeCleanupOptions), nameof(AreCodeCleanupRulesConfigured), defaultValue: false, | ||
| storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Are Code Cleanup Rules Configured")); | ||
|
|
||
| public static readonly PerLanguageOption<bool> NeverShowCodeCleanupInfoBarAgain = new PerLanguageOption<bool>( |
There was a problem hiding this comment.
NeverShowCodeCleanupInfoBarAgain [](start = 55, length = 32)
Question: Which options go into AutomationObject and which don't? @heejaechang@outlook.com probably knows the answer..
|
@jinujoseph could you approve this? |
|
Approved to merge for 15.8.Preview3 |
|
test windows_release_vs-integration_prtest |
Code cleanup with Format document button (Ctrl+k, d)
Customer scenario
When user ctrl+k, d on a C# document, it brings up the code cleanup info bar to ask user to configure the code cleanup options. Once user configures the options, next time they click ctrl+k, d, it will clean up using the enabled fixers and format the document.
Bugs this fixes
NA
Workarounds, if any
NA
Risk
Low, it only affects the scenario of ctrl+k, d.
Performance impact
Low, it only affects the scenario of ctrl+k, d. It adds some time for the ctrl+k,d if user configured a lot of fixers
Is this a regression from a previous update?
NA
Root cause analysis
NA
How was the bug found?
NA
Test documentation updated?
No