Skip to content

Commit

Permalink
Merge pull request #36 from Lombiq/issue/OSOE-179
Browse files Browse the repository at this point in the history
OSOE-179: Updating Analyzers to latest
  • Loading branch information
Piedone committed Oct 16, 2023
2 parents 8fdf69d + 61ea80c commit 2c88e71
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 31 deletions.
12 changes: 9 additions & 3 deletions Lombiq.Vsix.Orchard/Commands/InjectDependencyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Windows.Forms;
using Task = System.Threading.Tasks.Task;

Expand All @@ -22,6 +23,8 @@ internal sealed class InjectDependencyCommand
private readonly IEnumerable<IFieldNameFromDependencyGenerator> _fieldNameGenerators;
private readonly IEnumerable<IDependencyNameProvider> _dependencyNameProviders;

private CancellationToken _cancellationToken;

public static InjectDependencyCommand Instance { get; private set; }

private InjectDependencyCommand(
Expand All @@ -42,9 +45,12 @@ await package.GetServiceAsync<IDependencyInjector>().ConfigureAwait(true),
await package.GetServicesAsync<IFieldNameFromDependencyGenerator>().ConfigureAwait(true),
await package.GetServicesAsync<IDependencyNameProvider>().ConfigureAwait(true));

public async Task InitializeUIAsync()
public async Task InitializeUIAsync(CancellationToken cancellationToken)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
_cancellationToken = cancellationToken;

await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

(await _package.GetServiceAsync<IMenuCommandService>().ConfigureAwait(true)).AddCommand(
new MenuCommand(
MenuItemCallback,
Expand All @@ -60,7 +66,7 @@ private void MenuItemCallback(object sender, EventArgs e) =>

private async Task MenuItemCallbackAsync()
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(_cancellationToken);
const string injectDependencyCaption = "Inject Dependency";
var dte = await _package.GetDteAsync().ConfigureAwait(true);

Expand Down
43 changes: 25 additions & 18 deletions Lombiq.Vsix.Orchard/Commands/OpenErrorLogCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.ComponentModel.Design;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Task = System.Threading.Tasks.Task;

Expand All @@ -30,6 +31,7 @@ internal sealed class OpenErrorLogCommand : IAsyncDisposable
private bool _hasSeenErrorLogUpdate;
private bool _errorIndicatorStateChanged;
private ILogFileStatus _latestUpdatedLogFileStatus;
private CancellationToken _cancellationToken;

private OpenErrorLogCommand(
AsyncPackage package,
Expand All @@ -53,12 +55,14 @@ public static async Task CreateAsync(AsyncPackage package, ILogWatcherSettingsAc
await package.GetServicesAsync<ILogFileWatcher>().ConfigureAwait(true),
await package.GetServiceAsync<IBlinkStickManager>().ConfigureAwait(true));

await Instance.InitalizeWatchersAsync().ConfigureAwait(true);
await Instance.InitializeWatchersAsync().ConfigureAwait(true);
}

public async Task InitializeUIAsync()
public async Task InitializeUIAsync(CancellationToken cancellationToken)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
_cancellationToken = cancellationToken;

await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

_openErrorLogCommand = new OleMenuCommand(OpenErrorLogCallback, new CommandID(CommandSet, CommandId));
_openErrorLogCommand.BeforeQueryStatus += OpenErrorLogCommandBeforeQueryStatusCallback;
Expand All @@ -82,7 +86,7 @@ public async ValueTask DisposeAsync()
(await _logWatcherSettingsAccessor.GetSettingsAsync().ConfigureAwait(true)).SettingsUpdated -= LogWatcherSettingsUpdatedCallback;
}

private async Task InitalizeWatchersAsync()
private async Task InitializeWatchersAsync()
{
_hasSeenErrorLogUpdate = true;
_errorIndicatorStateChanged = true;
Expand Down Expand Up @@ -150,36 +154,39 @@ private void LogWatcherSettingsUpdatedCallback(object sender, LogWatcherSettings

private async Task LogWatcherSettingsUpdatedCallbackAsync(LogWatcherSettingsUpdatedEventArgs e)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(_cancellationToken);
var isEnabled = e.Settings.LogWatcherEnabled;
var orchardLogWatcherToolbar = ((CommandBars)(await _package.GetDteAsync()
.ConfigureAwait(true)).CommandBars)[CommandBarNames.OrchardLogWatcherToolbarName];
orchardLogWatcherToolbar.Visible = isEnabled;

// Since this method will be called from the UI thread not blocking it with the watcher changes that can
// potentially take some time.
await Task.Run(() =>
{
// If the settings are repeatedly change then wait for the first one to finish before starting the next.
lock (_settingsChangeLock)
await Task.Run(
() =>
{
if (isEnabled)
// If the settings are repeatedly change then wait for the first one to finish before starting the next.
lock (_settingsChangeLock)
{
StartLogFileWatching();
if (isEnabled)
{
StartLogFileWatching();
}
else
{
StopLogFileWatching();
}
}
else
{
StopLogFileWatching();
}
}
}).ConfigureAwait(true);
},
_cancellationToken)
.ConfigureAwait(true);

await UpdateOpenErrorLogCommandAccessibilityAndTextAsync().ConfigureAwait(true);
}

private async Task UpdateOpenErrorLogCommandAccessibilityAndTextAsync(ILogFileStatus logFileStatus = null)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(_cancellationToken);
var logWatcherSettings = await _logWatcherSettingsAccessor.GetSettingsAsync().ConfigureAwait(true);

if (!(await _package.GetDteAsync().ConfigureAwait(true)).SolutionIsOpen())
Expand Down
7 changes: 6 additions & 1 deletion Lombiq.Vsix.Orchard/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<Project>
<Import Project="../tools/Lombiq.Analyzers/VisualStudioExtension.Build.props" />
<!-- Uncomment this to run .NET static code analyzers during rebuilds. -->
<!--<PropertyGroup>
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
</PropertyGroup>-->

<Import Project="../tools/Lombiq.Analyzers/Lombiq.Analyzers.VisualStudioExtension/Build.props" />
</Project>
1 change: 1 addition & 0 deletions Lombiq.Vsix.Orchard/Lombiq.Vsix.Orchard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
<Content Include="Readme.md">
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<None Include="Directory.Build.props" />
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
await InjectDependencyCommand.CreateAsync(this).ConfigureAwait(true);
await OpenErrorLogCommand.CreateAsync(this, this).ConfigureAwait(true);

await InjectDependencyCommand.Instance.InitializeUIAsync().ConfigureAwait(true);
await OpenErrorLogCommand.Instance.InitializeUIAsync().ConfigureAwait(true);
await InjectDependencyCommand.Instance.InitializeUIAsync(cancellationToken).ConfigureAwait(true);
await OpenErrorLogCommand.Instance.InitializeUIAsync(cancellationToken).ConfigureAwait(true);
}

protected override void Dispose(bool disposing)
Expand Down
4 changes: 2 additions & 2 deletions Lombiq.Vsix.Orchard/Models/DependencyName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class DependencyName

public class DependencyNameEqualityComparer : IEqualityComparer<DependencyName>
{
public bool Equals(DependencyName first, DependencyName second) => first.Name == second.Name;
public bool Equals(DependencyName x, DependencyName y) => x.Name == y.Name;

public int GetHashCode(DependencyName dependencyName) => StringComparer.Ordinal.GetHashCode(dependencyName);
public int GetHashCode(DependencyName obj) => StringComparer.Ordinal.GetHashCode(obj);
}
}
2 changes: 1 addition & 1 deletion Lombiq.Vsix.Orchard/Models/LogFileStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public override bool Equals(object obj)
}

public override int GetHashCode() =>
StringComparer.Ordinal.GetHashCode($"{HasContent}/{Exists}/{Path}/{LastUpdatedUtc}");
StringComparer.Ordinal.GetHashCode(FormattableString.Invariant($"{HasContent}/{Exists}/{Path}/{LastUpdatedUtc}"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected virtual string GetCamelCased(string value)
return char.ToLowerInvariant(value[0]) + value.Substring(1);
}

private static IEnumerable<char> GetUpperCasedLetters(string value) =>
value.Where(letter => char.IsUpper(letter));
private static List<char> GetUpperCasedLetters(string value) =>
value.Where(letter => char.IsUpper(letter)).ToList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected virtual IEnumerable<string> GetAllMatchingPaths(
IEnumerable<string> patterns,
string logFileName)
{
var fullPaths = patterns.Select(pattern => Path.Combine(root, pattern, logFileName).Replace("/", "\\"));
var fullPaths = patterns.Select(pattern => Path.Combine(root, pattern, logFileName).Replace('/', '\\'));

return fullPaths.SelectMany(fullPath =>
{
Expand Down
2 changes: 1 addition & 1 deletion tools/Lombiq.Analyzers
Submodule Lombiq.Analyzers updated 78 files
+0 −285 .editorconfig
+8 −0 .gitattributes
+23 −0 .github/workflows/create-jira-issues-for-community-activities.yml
+16 −0 .github/workflows/publish-nuget.yml
+0 −12 .github/workflows/publish.yml
+35 −0 .github/workflows/test-analysis-failure.yml
+8 −0 .github/workflows/validate-pull-request.yml
+6 −0 .gitignore
+0 −49 Build.props
+0 −47 CommonPackages.props
+41 −0 ConvertTo-Nuspec.ps1
+0 −92 Docs/AddingAnalyzers.md
+0 −103 Docs/ConfiguringAnalyzers.md
+0 −431 General.ruleset
+69 −0 Lombiq.Analyzers.NetFx/Build.props
+4 −6 Lombiq.Analyzers.NetFx/License.md
+36 −0 Lombiq.Analyzers.NetFx/Lombiq.Analyzers.NetFx.csproj
+13 −0 Lombiq.Analyzers.NetFx/Lombiq.Analyzers.NetFx.globalconfig
+30 −0 Lombiq.Analyzers.NetFx/Lombiq.Analyzers.NetFx.nuspec.template
+ Lombiq.Analyzers.NetFx/NuGetIcon.png
+5 −0 Lombiq.Analyzers.NetFx/Readme.md
+7 −0 Lombiq.Analyzers.NetFx/build/Lombiq.Analyzers.NetFx.props
+7 −0 Lombiq.Analyzers.Orchard1/Build.props
+13 −0 Lombiq.Analyzers.Orchard1/License.md
+31 −0 Lombiq.Analyzers.Orchard1/Lombiq.Analyzers.Orchard1.csproj
+17 −0 Lombiq.Analyzers.Orchard1/Lombiq.Analyzers.Orchard1.globalconfig
+30 −0 Lombiq.Analyzers.Orchard1/Lombiq.Analyzers.Orchard1.nuspec.template
+ Lombiq.Analyzers.Orchard1/NuGetIcon.png
+5 −0 Lombiq.Analyzers.Orchard1/Readme.md
+7 −0 Lombiq.Analyzers.Orchard1/build/Lombiq.Analyzers.Orchard1.props
+6 −0 Lombiq.Analyzers.OrchardCore/Build.props
+13 −0 Lombiq.Analyzers.OrchardCore/License.md
+30 −0 Lombiq.Analyzers.OrchardCore/Lombiq.Analyzers.OrchardCore.csproj
+25 −0 Lombiq.Analyzers.OrchardCore/Lombiq.Analyzers.OrchardCore.globalconfig
+29 −0 Lombiq.Analyzers.OrchardCore/Lombiq.Analyzers.OrchardCore.nuspec.template
+ Lombiq.Analyzers.OrchardCore/NuGetIcon.png
+5 −0 Lombiq.Analyzers.OrchardCore/Readme.md
+7 −0 Lombiq.Analyzers.OrchardCore/build/Lombiq.Analyzers.OrchardCore.props
+6 −0 Lombiq.Analyzers.VisualStudioExtension/Build.props
+13 −0 Lombiq.Analyzers.VisualStudioExtension/License.md
+30 −0 Lombiq.Analyzers.VisualStudioExtension/Lombiq.Analyzers.VisualStudioExtension.csproj
+10 −0 Lombiq.Analyzers.VisualStudioExtension/Lombiq.Analyzers.VisualStudioExtension.globalconfig
+30 −0 Lombiq.Analyzers.VisualStudioExtension/Lombiq.Analyzers.VisualStudioExtension.nuspec.template
+ Lombiq.Analyzers.VisualStudioExtension/NuGetIcon.png
+5 −0 Lombiq.Analyzers.VisualStudioExtension/Readme.md
+7 −0 Lombiq.Analyzers.VisualStudioExtension/build/Lombiq.Analyzers.VisualStudioExtension.props
+0 −33 Lombiq.Analyzers.csproj
+49 −0 Lombiq.Analyzers.sln
+45 −0 Lombiq.Analyzers/.editorconfig
+25 −0 Lombiq.Analyzers/AnalyzerPackages.props
+89 −0 Lombiq.Analyzers/Build.props
+121 −0 Lombiq.Analyzers/Docs/AddingAnalyzers.md
+80 −0 Lombiq.Analyzers/Docs/ConfiguringAnalyzers.md
+4 −8 Lombiq.Analyzers/Docs/UsingAnalyzersDuringCommandLineBuilds.md
+6 −8 Lombiq.Analyzers/Docs/UsingAnalyzersDuringDevelopment.md
+13 −0 Lombiq.Analyzers/License.md
+29 −0 Lombiq.Analyzers/Lombiq.Analyzers.csproj
+661 −0 Lombiq.Analyzers/Lombiq.Analyzers.globalconfig
+29 −0 Lombiq.Analyzers/Lombiq.Analyzers.nuspec.template
+ Lombiq.Analyzers/NuGetIcon.png
+5 −0 Lombiq.Analyzers/Readme.md
+0 −0 Lombiq.Analyzers/SonarLint.xml
+7 −0 Lombiq.Analyzers/build/Lombiq.Analyzers.props
+0 −0 Lombiq.Analyzers/stylecop.json
+0 −40 NetFx.Build.props
+0 −15 Orchard1.ruleset
+0 −24 OrchardCore.ruleset
+30 −17 Readme.md
+16 −0 TestSolutions/AnalyzerViolations.cs
+9 −0 TestSolutions/Directory.Build.props
+32 −0 TestSolutions/Lombiq.Analyzers.PackageReference/IndirectPackageReference/IndirectPackageReference.csproj
+22 −0 TestSolutions/Lombiq.Analyzers.PackageReference/Lombiq.Analyzers.PackageReference.csproj
+34 −0 TestSolutions/Lombiq.Analyzers.PackageReference/Lombiq.Analyzers.PackageReference.sln
+13 −0 TestSolutions/Lombiq.Analyzers.ProjectReference/Lombiq.Analyzers.ProjectReference.csproj
+39 −0 TestSolutions/Lombiq.Analyzers.ProjectReference/Lombiq.Analyzers.ProjectReference.sln
+0 −6 VisualStudioExtension.Build.props
+0 −7 VisualStudioExtension.ruleset
+0 −3 build/Lombiq.Analyzers.props

0 comments on commit 2c88e71

Please sign in to comment.