Skip to content

Commit 0298477

Browse files
authored
Merge pull request #53515 from dotnet/merges/release/dev16.10-to-release/dev16.10-vs-deps
Merge release/dev16.10 to release/dev16.10-vs-deps
2 parents dc0aff2 + 28511a6 commit 0298477

15 files changed

Lines changed: 84 additions & 59 deletions

src/EditorFeatures/CSharpTest/EditorConfigSettings/Updater/SettingsUpdaterTests.TestAnalyzerConfigOptions.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System;
56
using System.Diagnostics.CodeAnalysis;
67
using Microsoft.CodeAnalysis.Diagnostics;
78

@@ -11,12 +12,22 @@ public partial class SettingsUpdaterTests
1112
{
1213
private class TestAnalyzerConfigOptions : AnalyzerConfigOptions
1314
{
14-
public static TestAnalyzerConfigOptions Instance = new TestAnalyzerConfigOptions();
15+
public static TestAnalyzerConfigOptions Instance = new();
16+
private readonly Func<string, string?>? _lookup = null;
17+
18+
public TestAnalyzerConfigOptions()
19+
{
20+
}
21+
22+
public TestAnalyzerConfigOptions(Func<string, string?> lookup)
23+
{
24+
_lookup = lookup;
25+
}
1526

1627
public override bool TryGetValue(string key, [NotNullWhen(true)] out string? value)
1728
{
18-
value = null;
19-
return false;
29+
value = _lookup?.Invoke(key);
30+
return value != null;
2031
}
2132
}
2233
}

src/EditorFeatures/CSharpTest/EditorConfigSettings/Updater/SettingsUpdaterTests.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.Collections.Generic;
56
using System.Linq;
7+
using System.Threading;
68
using System.Threading.Tasks;
79
using Microsoft.CodeAnalysis.AddImports;
810
using Microsoft.CodeAnalysis.CodeStyle;
@@ -24,6 +26,8 @@ namespace Microsoft.CodeAnalysis.Editor.UnitTests
2426
[UseExportProvider]
2527
public partial class SettingsUpdaterTests : TestBase
2628
{
29+
private const string EditorconfigPath = "/a/b/config";
30+
2731
private static Workspace CreateWorkspaceWithProjectAndDocuments()
2832
{
2933
var projectId = ProjectId.CreateNewId();
@@ -34,7 +38,7 @@ private static Workspace CreateWorkspaceWithProjectAndDocuments()
3438
.AddProject(projectId, "proj1", "proj1.dll", LanguageNames.CSharp)
3539
.AddDocument(DocumentId.CreateNewId(projectId), "goo.cs", "public class Goo { }")
3640
.AddAdditionalDocument(DocumentId.CreateNewId(projectId), "add.txt", "text")
37-
.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId), "editorcfg", SourceText.From(""), filePath: "/a/b/config")));
41+
.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId), "editorcfg", SourceText.From(""), filePath: EditorconfigPath)));
3842

3943
return workspace;
4044
}
@@ -81,9 +85,8 @@ await TestAsync(
8185
[Fact, Trait(Traits.Feature, Traits.Features.EditorConfigUI)]
8286
public async Task TestAddNewBoolCodeStyleOptionWithSeverityAsync()
8387
{
84-
var option = CSharpCodeStyleOptions.PreferThrowExpression.DefaultValue;
85-
option.Value = true;
86-
option.Notification = CodeStyle.NotificationOption2.Suggestion;
88+
ICodeStyleOption option = CSharpCodeStyleOptions.PreferThrowExpression.DefaultValue;
89+
option = option.WithValue(true).WithNotification(NotificationOption2.Suggestion);
8790
await TestAsync(
8891
string.Empty,
8992
"[*.cs]\r\ncsharp_style_throw_expression=true:suggestion",
@@ -93,9 +96,8 @@ await TestAsync(
9396
[Fact, Trait(Traits.Feature, Traits.Features.EditorConfigUI)]
9497
public async Task TestAddNewEnumCodeStyleOptionWithSeverityAsync()
9598
{
96-
var option = CSharpCodeStyleOptions.PreferredUsingDirectivePlacement.DefaultValue;
97-
option.Value = AddImportPlacement.InsideNamespace;
98-
option.Notification = CodeStyle.NotificationOption2.Warning;
99+
ICodeStyleOption option = CSharpCodeStyleOptions.PreferredUsingDirectivePlacement.DefaultValue;
100+
option = option.WithValue(AddImportPlacement.InsideNamespace).WithNotification(NotificationOption2.Warning);
99101
await TestAsync(
100102
string.Empty,
101103
"[*.cs]\r\ncsharp_using_directive_placement=inside_namespace:warning",
@@ -337,20 +339,27 @@ public async Task TestAnalyzerSettingsUpdaterService()
337339
public async Task TestCodeStyleSettingUpdaterService()
338340
{
339341
var workspace = CreateWorkspaceWithProjectAndDocuments();
340-
var updater = new OptionUpdater(workspace, "/a/b/config");
342+
var updater = new OptionUpdater(workspace, EditorconfigPath);
343+
var value = "false:silent";
344+
var editorOptions = new TestAnalyzerConfigOptions(key => value);
341345
var setting = CodeStyleSetting.Create(CSharpCodeStyleOptions.AllowBlankLineAfterColonInConstructorInitializer,
342346
"",
343-
TestAnalyzerConfigOptions.Instance,
347+
editorOptions,
344348
workspace.Options,
345349
updater);
346350
setting.ChangeSeverity(DiagnosticSeverity.Error);
347351
var updates = await updater.GetChangedEditorConfigAsync(default);
348352
var update = Assert.Single(updates);
349-
Assert.Equal("[*.cs]\r\ncsharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental=true:error", update.NewText);
350-
setting.ChangeValue(1);
353+
Assert.Equal("[*.cs]\r\ncsharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental=false:error", update.NewText);
354+
value = "false:error";
355+
var editorconfig = workspace.CurrentSolution.Projects.SelectMany(p => p.AnalyzerConfigDocuments.Where(a => a.FilePath == EditorconfigPath)).Single();
356+
var text = await editorconfig.GetTextAsync();
357+
var newSolution = workspace.CurrentSolution.WithAnalyzerConfigDocumentText(editorconfig.Id, text);
358+
Assert.True(workspace.TryApplyChanges(newSolution));
359+
setting.ChangeValue(0);
351360
updates = await updater.GetChangedEditorConfigAsync(default);
352361
update = Assert.Single(updates);
353-
Assert.Equal("[*.cs]\r\ncsharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental=false:error", update.NewText);
362+
Assert.Equal("[*.cs]\r\ncsharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental=true:error", update.NewText);
354363
}
355364

356365
[Fact, Trait(Traits.Feature, Traits.Features.EditorConfigUI)]

src/EditorFeatures/Core/EditorConfigSettings/Data/AnalyzerSetting.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ internal void ChangeSeverity(DiagnosticSeverity severity)
5151
return;
5252

5353
Severity = severity;
54-
_ = _settingsUpdater.QueueUpdateAsync(this, severity);
54+
_settingsUpdater.QueueUpdate(this, severity);
5555
}
5656
}
5757
}

src/EditorFeatures/Core/EditorConfigSettings/Data/CodeStyle/CodeStyleSetting.BooleanCodeStyleSetting.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,15 @@ public BooleanCodeStyleSetting(Option2<CodeStyleOption2<bool>> option,
3535

3636
protected override void ChangeSeverity(NotificationOption2 severity)
3737
{
38-
var option = GetOption();
39-
option.Notification = severity;
40-
_ = Updater.QueueUpdateAsync(_option, option);
38+
ICodeStyleOption option = GetOption();
39+
Updater.QueueUpdate(_option, option.WithNotification(severity));
4140
}
4241

4342
public override void ChangeValue(int valueIndex)
4443
{
4544
var value = valueIndex == 0;
46-
var option = GetOption();
47-
option.Value = value;
48-
_ = Updater.QueueUpdateAsync(_option, option);
45+
ICodeStyleOption option = GetOption();
46+
Updater.QueueUpdate(_option, option.WithValue(value));
4947
}
5048

5149
protected override CodeStyleOption2<bool> GetOption()

src/EditorFeatures/Core/EditorConfigSettings/Data/CodeStyle/CodeStyleSetting.EnumCodeStyleSetting.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@ public EnumCodeStyleSetting(Option2<CodeStyleOption2<T>> option,
3737

3838
protected override void ChangeSeverity(NotificationOption2 severity)
3939
{
40-
var option = GetOption();
41-
option.Notification = severity;
42-
_ = Updater.QueueUpdateAsync(_option, option);
40+
ICodeStyleOption option = GetOption();
41+
Updater.QueueUpdate(_option, option.WithNotification(severity));
4342
}
4443

4544
public override void ChangeValue(int valueIndex)
4645
{
47-
var option = GetOption();
48-
option.Value = _enumValues[valueIndex];
49-
_ = Updater.QueueUpdateAsync(_option, option);
46+
ICodeStyleOption option = GetOption();
47+
Updater.QueueUpdate(_option, option.WithValue(_enumValues[valueIndex]));
5048
}
5149

5250
protected override CodeStyleOption2<T> GetOption()

src/EditorFeatures/Core/EditorConfigSettings/Data/CodeStyle/CodeStyleSetting.PerLanguageBooleanCodeStyleSetting.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,15 @@ public PerLanguageBooleanCodeStyleSetting(PerLanguageOption2<CodeStyleOption2<bo
3535

3636
protected override void ChangeSeverity(NotificationOption2 severity)
3737
{
38-
var option = GetOption();
39-
option.Notification = severity;
40-
_ = Updater.QueueUpdateAsync(_option, option);
38+
ICodeStyleOption option = GetOption();
39+
Updater.QueueUpdate(_option, option.WithNotification(severity));
4140
}
4241

4342
public override void ChangeValue(int valueIndex)
4443
{
4544
var value = valueIndex == 0;
46-
var option = GetOption();
47-
option.Value = value;
48-
_ = Updater.QueueUpdateAsync(_option, option);
45+
ICodeStyleOption option = GetOption();
46+
Updater.QueueUpdate(_option, option.WithValue(value));
4947
}
5048

5149
protected override CodeStyleOption2<bool> GetOption()

src/EditorFeatures/Core/EditorConfigSettings/Data/CodeStyle/CodeStyleSetting.PerLanguageEnumCodeStyleSetting.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@ public PerLanguageEnumCodeStyleSetting(PerLanguageOption2<CodeStyleOption2<T>> o
3737

3838
protected override void ChangeSeverity(NotificationOption2 severity)
3939
{
40-
var option = GetOption();
41-
option.Notification = severity;
42-
_ = Updater.QueueUpdateAsync(_option, option);
40+
ICodeStyleOption option = GetOption();
41+
Updater.QueueUpdate(_option, option.WithNotification(severity));
4342
}
4443

4544
public override void ChangeValue(int valueIndex)
4645
{
47-
var option = GetOption();
48-
option.Value = _enumValues[valueIndex];
49-
_ = Updater.QueueUpdateAsync(_option, option);
46+
ICodeStyleOption option = GetOption();
47+
Updater.QueueUpdate(_option, option.WithValue(_enumValues[valueIndex]));
5048
}
5149

5250
protected override CodeStyleOption2<T> GetOption()

src/EditorFeatures/Core/EditorConfigSettings/Data/Formatting/FormattingSetting`1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public FormattingSetting(Option2<T> option,
6868
public override void SetValue(object value)
6969
{
7070
Value = (T)value;
71-
_ = Updater.QueueUpdateAsync(_option, value);
71+
Updater.QueueUpdate(_option, value);
7272
}
7373

7474
public override object? GetValue() => Value;

src/EditorFeatures/Core/EditorConfigSettings/Data/Formatting/PerLanguageFormattingSetting.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public PerLanguageFormattingSetting(PerLanguageOption2<T> option,
6868
public override void SetValue(object value)
6969
{
7070
Value = (T)value;
71-
_ = Updater.QueueUpdateAsync(_option, value);
71+
Updater.QueueUpdate(_option, value);
7272
}
7373

7474
public override object? GetValue() => Value;

src/EditorFeatures/Core/EditorConfigSettings/Updater/ISettingUpdater.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System.Collections.Generic;
65
using System.Threading;
76
using System.Threading.Tasks;
87
using Microsoft.CodeAnalysis.Text;
@@ -11,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Updater
1110
{
1211
internal interface ISettingUpdater<TSetting, TValue>
1312
{
14-
Task<bool> QueueUpdateAsync(TSetting setting, TValue value);
13+
void QueueUpdate(TSetting setting, TValue value);
1514
Task<SourceText?> GetChangedEditorConfigAsync(SourceText sourceText, CancellationToken token);
1615
Task<bool> HasAnyChangesAsync();
1716
}

0 commit comments

Comments
 (0)