Skip to content
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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
883a2c5
move Language enum further down the stack
jmarolf Dec 1, 2021
d77a8f8
implement naming styles option parser with text span support
jmarolf Dec 1, 2021
a7e051a
add folder description
jmarolf Dec 2, 2021
5e5cbc8
Add namging style option support
jmarolf Dec 2, 2021
682a9df
add folder description
jmarolf Dec 2, 2021
a773abe
Add views for naming styles
jmarolf Dec 2, 2021
48f54b4
Update src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Nami…
jmarolf Dec 2, 2021
1886364
Update src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Edit…
jmarolf Dec 2, 2021
49088b0
Update src/EditorFeatures/Core/EditorConfigSettings/Updater/NamingSty…
jmarolf Dec 2, 2021
da90d81
Update src/EditorFeatures/Core/EditorConfigSettings/Updater/NamingSty…
jmarolf Dec 2, 2021
3a28801
lengthen the search box to align with the tabs above it
jmarolf Dec 2, 2021
cbce098
enable nullable on test files
jmarolf Dec 2, 2021
525cb16
de-duplicate local functions
jmarolf Dec 2, 2021
03da9e5
simplify boolean logic
jmarolf Dec 2, 2021
98006e6
use resource strings in tests
jmarolf Dec 2, 2021
b53f7d1
return immutable array for static severities
jmarolf Dec 2, 2021
74e9ca0
update readme with a relative path link
jmarolf Dec 2, 2021
761eb1e
using TryPeekNext
jmarolf Dec 3, 2021
ba7bdb3
using disposeable pooled objects
jmarolf Dec 3, 2021
2c9fed1
renamge rangeOpt to numberRange
jmarolf Dec 3, 2021
264eefb
fix Span and Section being swapped from the base
jmarolf Dec 6, 2021
b2ca734
update incorrect comment
jmarolf Dec 6, 2021
a321a3f
Combine Lex with static function
jmarolf Dec 6, 2021
132f6b0
return false if we fail to determine the language for a path
jmarolf Dec 6, 2021
cb5cfc0
use Lazy instead of fancy InterlockedInitialize
jmarolf Dec 6, 2021
86ef543
move search bar up by 12 pixels
jmarolf Dec 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.CodeAnalysis.Editor.EditorConfigSettings;
using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Data;
using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Updater;
using Microsoft.CodeAnalysis.EditorConfig;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Updater;
using Microsoft.CodeAnalysis.EditorConfig;

namespace Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Data
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Data;
using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Extensions;
using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Updater;
using Microsoft.CodeAnalysis.EditorConfig;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Data;
using Microsoft.CodeAnalysis.EditorConfig;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
// 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.

#nullable disable

using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.EditorConfig;
using Microsoft.CodeAnalysis.EditorConfig.Parsing;
using Microsoft.CodeAnalysis.Text;
using Xunit;

namespace Microsoft.CodeAnalysis.UnitTests.EditorConfigParsing
{
public class EditorConfigFileParserTests
{
internal static EditorConfigFile<EditorConfigOption> CreateParseResults(string editorconfigFilePath, params (string headerText, TextSpan span, bool isGlobal)[] sections)
{
var list = new List<EditorConfigOption>();
foreach (var (headerText, span, isGlobal) in sections)
{
var section = new Section(editorconfigFilePath, isGlobal, span, headerText, $"[{headerText}]");
var parseResult = new EditorConfigOption(section, null);
list.Add(parseResult);
}

return new EditorConfigFile<EditorConfigOption>(editorconfigFilePath, list.ToImmutableArray());
}

[Fact]
internal void TestGetBestSection()
{
var parseResults = CreateParseResults(@"C:\dev\.editorconfig",
(string.Empty, TextSpan.FromBounds(0, 9), true),
("*.cs", TextSpan.FromBounds(10, 19), false),
("*.vb", TextSpan.FromBounds(20, 29), false),
("*.{cs,vb}", TextSpan.FromBounds(30, 39), false),
("*.{cs,csx,vb,vbx}", TextSpan.FromBounds(40, 49), false));

Assert.True(parseResults.TryGetSectionForLanguage(Language.CSharp, out var section));
Assert.Equal(10, section.Span.Start);
Assert.Equal("*.cs", section.Text);

Assert.True(parseResults.TryGetSectionForLanguage(Language.VisualBasic, out section));
Assert.Equal(20, section.Span.Start);
Assert.Equal("*.vb", section.Text);

Assert.True(parseResults.TryGetSectionForLanguage((Language.CSharp | Language.VisualBasic), out section));
Assert.Equal(30, section.Span.Start);
Assert.Equal("*.{cs,vb}", section.Text);
}

[Fact]
internal void TestNoBestSection()
{
var parseResults = CreateParseResults(@"C:\dev\.editorconfig",
(string.Empty, TextSpan.FromBounds(0, 9), true),
("*.vb", TextSpan.FromBounds(20, 29), false),
("*.{cs,vb}", TextSpan.FromBounds(30, 39), false),
("*.{cs,csx,vb,vbx}", TextSpan.FromBounds(40, 49), false),
("*s", TextSpan.FromBounds(50, 59), false),
("*", TextSpan.FromBounds(60, 69), false),
("*.{cs,csx}", TextSpan.FromBounds(70, 79), false));

Assert.False(parseResults.TryGetSectionForLanguage(Language.CSharp, out _));
}

[Fact]
internal void TestGetBestSectionWithDifferMatchCriteria()
{
var parseResults = CreateParseResults(@"C:\dev\.editorconfig",
(string.Empty, TextSpan.FromBounds(0, 9), true),
("*.vb", TextSpan.FromBounds(20, 29), false),
("*.{cs,vb}", TextSpan.FromBounds(30, 39), false),
("*.{cs,csx,vb,vbx}", TextSpan.FromBounds(40, 49), false),
("*s", TextSpan.FromBounds(50, 59), false),
("*", TextSpan.FromBounds(60, 69), false),
("*.{cs,csx}", TextSpan.FromBounds(70, 79), false));

Assert.True(parseResults.TryGetSectionForLanguage(Language.CSharp, SectionMatch.ExactLanguageMatchWithOthers, out var section));
Assert.Equal(70, section.Span.Start);
Assert.Equal("*.{cs,csx}", section.Text);
}

[Fact]
internal void TestGetBestSectionWithAnyPattern()
{
var parseResults = CreateParseResults(@"C:\dev\.editorconfig",
(string.Empty, TextSpan.FromBounds(0, 9), true),
("*.vb", TextSpan.FromBounds(20, 29), false),
("*.{cs,csx,vb,vbx}", TextSpan.FromBounds(40, 49), false),
("*s", TextSpan.FromBounds(50, 59), false),
("*", TextSpan.FromBounds(60, 69), false),
("*.{cs,csx}", TextSpan.FromBounds(70, 79), false));

Assert.True(parseResults.TryGetSectionForLanguage(Language.CSharp, SectionMatch.Any, out var section));
Assert.Equal(70, section.Span.Start);
Assert.Equal("*.{cs,csx}", section.Text);

Assert.True(parseResults.TryGetSectionForLanguage(Language.VisualBasic, SectionMatch.Any, out section));
Assert.Equal(20, section.Span.Start);
Assert.Equal("*.vb", section.Text);

Assert.True(parseResults.TryGetSectionForLanguage((Language.CSharp | Language.VisualBasic), SectionMatch.Any, out section));
Assert.Equal(40, section.Span.Start);
Assert.Equal("*.{cs,csx,vb,vbx}", section.Text);
}

[Fact]
internal void TestGetBestSectionForFile()
{
var parseResults = CreateParseResults(@"C:\dev\.editorconfig",
(string.Empty, TextSpan.FromBounds(0, 9), true),
("*.cs", TextSpan.FromBounds(10, 19), false),
("*.vb", TextSpan.FromBounds(20, 29), false),
("*.{cs,vb}", TextSpan.FromBounds(30, 39), false),
("*.{cs,csx,vb,vbx}", TextSpan.FromBounds(40, 49), false),
("*s", TextSpan.FromBounds(50, 59), false),
("*", TextSpan.FromBounds(60, 69), false),
("*.{cs,csx}", TextSpan.FromBounds(70, 79), false));

Assert.True(parseResults.TryGetSectionForFilePath(@"C:\dev\sources\CSharp\Program.cs", out var section));
Assert.Equal(10, section.Span.Start);
Assert.Equal("*.cs", section.Text);

Assert.True(parseResults.TryGetSectionForFilePath(@"C:\dev\sources\VisualBasic\Program.vb", out section));
Assert.Equal(20, section.Span.Start);
Assert.Equal("*.vb", section.Text);
}

[Fact]
internal void TestGetBestSectionForFilePatternWithDefaults()
{
var parseResults = CreateParseResults(@"C:\dev\.editorconfig",
(string.Empty, TextSpan.FromBounds(0, 9), true),
("sources/**/*.cs", TextSpan.FromBounds(10, 19), false),
("sources/**/*.vb", TextSpan.FromBounds(20, 29), false),
("*.{cs,vb}", TextSpan.FromBounds(30, 39), false),
("*.{cs,csx,vb,vbx}", TextSpan.FromBounds(40, 49), false),
("*s", TextSpan.FromBounds(50, 59), false),
("*", TextSpan.FromBounds(60, 69), false),
("*.{cs,csx}", TextSpan.FromBounds(70, 79), false));

Assert.False(parseResults.TryGetSectionForFilePath(@"C:\dev\sources\CSharp\Program.cs", out _));
Assert.False(parseResults.TryGetSectionForFilePath(@"C:\dev\sources\VisualBasic\Program.vb", out _));
}

[Fact]
internal void TestGetBestSectionForFilePattern()
{
var parseResults = CreateParseResults(@"C:\dev\.editorconfig",
(string.Empty, TextSpan.FromBounds(0, 9), true),
("sources/**/*.cs", TextSpan.FromBounds(10, 19), false),
("sources/**/*.vb", TextSpan.FromBounds(20, 29), false),
("*.{cs,vb}", TextSpan.FromBounds(30, 39), false),
("*.{cs,csx,vb,vbx}", TextSpan.FromBounds(40, 49), false),
("*s", TextSpan.FromBounds(50, 59), false),
("*", TextSpan.FromBounds(60, 69), false),
("*.{cs,csx}", TextSpan.FromBounds(70, 79), false));

Assert.True(parseResults.TryGetSectionForFilePath(@"C:\dev\sources\CSharp\Program.cs", SectionMatch.Any, out var section));
Assert.Equal(70, section.Span.Start);
Assert.Equal("*.{cs,csx}", section.Text);

Assert.True(parseResults.TryGetSectionForFilePath(@"C:\dev\sources\VisualBasic\Program.vb", SectionMatch.Any, out section));
Assert.Equal(40, section.Span.Start);
Assert.Equal("*.{cs,csx,vb,vbx}", section.Text);
}

[Fact]
internal void TestGetBestSectionForFilePatternTie()
{
var parseResults = CreateParseResults(@"C:\dev\.editorconfig",
(string.Empty, TextSpan.FromBounds(0, 9), true),
("*.{cs,csx,vbx}", TextSpan.FromBounds(30, 39), false),
("*.{cs,csx,vb,vbx}", TextSpan.FromBounds(40, 49), false),
("*s", TextSpan.FromBounds(50, 59), false),
("*", TextSpan.FromBounds(60, 69), false));

Assert.True(parseResults.TryGetSectionForFilePath(@"C:\dev\sources\CSharp\Program.cs", SectionMatch.Any, out var section));
Assert.Equal(30, section.Span.Start);
Assert.Equal("*.{cs,csx,vbx}", section.Text);

Assert.True(parseResults.TryGetSectionForFilePath(@"C:\dev\sources\VisualBasic\Program.vb", SectionMatch.Any, out section));
Assert.Equal(40, section.Span.Start);
Assert.Equal("*.{cs,csx,vb,vbx}", section.Text);
}

[Fact]
internal void TestGetBestSectionForSuperetFilePatternTie()
{
var parseResults = CreateParseResults(@"C:\dev\.editorconfig",
(string.Empty, TextSpan.FromBounds(0, 9), true),
("*.*b", TextSpan.FromBounds(30, 39), false),
("*.*b", TextSpan.FromBounds(80, 89), false),
("*.*b", TextSpan.FromBounds(130, 139), false),
("*.*s", TextSpan.FromBounds(40, 49), false),
("*.*s", TextSpan.FromBounds(90, 99), false),
("*.*s", TextSpan.FromBounds(120, 129), false),
("*s", TextSpan.FromBounds(50, 59), false),
("*s", TextSpan.FromBounds(100, 109), false),
("*", TextSpan.FromBounds(60, 69), false),
("*b", TextSpan.FromBounds(70, 79), false),
("*b", TextSpan.FromBounds(110, 119), false));

Assert.True(parseResults.TryGetSectionForFilePath(@"C:\dev\sources\CSharp\Program.cs", SectionMatch.Any, out var section));
Assert.Equal(120, section.Span.Start);
Assert.Equal("*.*s", section.Text);

Assert.True(parseResults.TryGetSectionForFilePath(@"C:\dev\sources\VisualBasic\Program.vb", SectionMatch.Any, out section));
Assert.Equal(130, section.Span.Start);
Assert.Equal("*.*b", section.Text);
}

[Fact]
internal void TestGetBestSectionWithSplat()
{
var parseResults = CreateParseResults(@"C:\dev\.editorconfig",
(string.Empty, TextSpan.FromBounds(0, 9), true),
("*s", TextSpan.FromBounds(100, 109), false),
("*", TextSpan.FromBounds(60, 69), false));

Assert.True(parseResults.TryGetSectionForFilePath(@"C:\dev\sources\CSharp\Program.cs", SectionMatch.Any, out var section));
Assert.Equal(100, section.Span.Start);
Assert.Equal("*s", section.Text);

Assert.True(parseResults.TryGetSectionForFilePath(@"C:\dev\sources\VisualBasic\Program.vb", SectionMatch.Any, out section));
Assert.Equal(60, section.Span.Start);
Assert.Equal("*", section.Text);
}

[Fact]
internal void TestGetBestSectionWithGlobalSection()
{
var parseResults = CreateParseResults(@"C:\dev\.editorconfig",
(string.Empty, TextSpan.FromBounds(0, 9), true),
("*s", TextSpan.FromBounds(100, 109), false));

Assert.True(parseResults.TryGetSectionForFilePath(@"C:\dev\sources\CSharp\Program.cs", SectionMatch.Any, out var section));
Assert.Equal(100, section.Span.Start);
Assert.Equal("*s", section.Text);

Assert.True(parseResults.TryGetSectionForFilePath(@"C:\dev\sources\VisualBasic\Program.vb", SectionMatch.Any, out section));
Assert.Equal(0, section.Span.Start);
Assert.Equal(string.Empty, section.Text);
}
}
}
Loading