mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
[Analyzers] Update StyleCop and enable SA1200 (#22707)
* update StyleCop and enable SA1200 * Fix merge issues * fix build and added using rule
This commit is contained in:
committed by
GitHub
parent
617150cf50
commit
6d138e80fb
@@ -2,10 +2,10 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Wox.Plugin.Interfaces;
|
||||
|
||||
namespace Microsoft.Plugin.Folder
|
||||
{
|
||||
using Wox.Plugin.Interfaces;
|
||||
|
||||
public class SearchResult : IFileDropResult
|
||||
{
|
||||
public string Path { get; set; }
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Microsoft.Plugin.Folder.Sources
|
||||
return query.Any(c => c.Equals('>'));
|
||||
}
|
||||
|
||||
private (string search, string incompleteName) Process(string search)
|
||||
private (string Search, string IncompleteName) Process(string search)
|
||||
{
|
||||
string incompleteName = string.Empty;
|
||||
if (HasSpecialChars(search) || !_directory.Exists($@"{search}\"))
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Wox.Plugin.Interfaces;
|
||||
|
||||
namespace Microsoft.Plugin.Indexer.SearchHelper
|
||||
{
|
||||
using Wox.Plugin.Interfaces;
|
||||
|
||||
public class SearchResult : IFileDropResult
|
||||
{
|
||||
// Contains the Path of the file or folder
|
||||
|
||||
@@ -29,8 +29,8 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
|
||||
public void ErrorResultOnInvalidKeywordQuery(string typedString, string expectedResult)
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new ();
|
||||
Query expectedQuery = new (typedString, "=");
|
||||
Mock<Main> main = new();
|
||||
Query expectedQuery = new(typedString, "=");
|
||||
|
||||
// Act
|
||||
var result = main.Object.Query(expectedQuery).FirstOrDefault().SubTitle;
|
||||
@@ -56,8 +56,8 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
|
||||
public void NoResultOnInvalidGlobalQuery(string typedString)
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new ();
|
||||
Query expectedQuery = new (typedString);
|
||||
Mock<Main> main = new();
|
||||
Query expectedQuery = new(typedString);
|
||||
|
||||
// Act
|
||||
var result = main.Object.Query(expectedQuery).Count;
|
||||
@@ -80,9 +80,9 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
|
||||
public void NoResultIfQueryEndsWithBinaryOperator(string typedString)
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new ();
|
||||
Query expectedQuery = new (typedString);
|
||||
Query expectedQueryWithKeyword = new ("=" + typedString, "=");
|
||||
Mock<Main> main = new();
|
||||
Query expectedQuery = new(typedString);
|
||||
Query expectedQueryWithKeyword = new("=" + typedString, "=");
|
||||
|
||||
// Act
|
||||
var result = main.Object.Query(expectedQuery).Count;
|
||||
@@ -101,9 +101,9 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
|
||||
public void NoErrorForDivisionByNumberWithDecimalDigits(string typedString)
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new ();
|
||||
Query expectedQuery = new (typedString);
|
||||
Query expectedQueryWithKeyword = new ("=" + typedString, "=");
|
||||
Mock<Main> main = new();
|
||||
Query expectedQuery = new(typedString);
|
||||
Query expectedQueryWithKeyword = new("=" + typedString, "=");
|
||||
|
||||
// Act
|
||||
var result = main.Object.Query(expectedQuery).FirstOrDefault().SubTitle;
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
|
||||
return !trailTest.Any();
|
||||
}
|
||||
|
||||
private static (TrailDirection direction, TrailType type) BracketTrail(char @char)
|
||||
private static (TrailDirection Direction, TrailType Type) BracketTrail(char @char)
|
||||
{
|
||||
switch (@char)
|
||||
{
|
||||
|
||||
@@ -19,7 +19,8 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
|
||||
@"pi|" +
|
||||
@"==|~=|&&|\|\||" +
|
||||
@"e|[0-9]|0x[0-9a-fA-F]+|0b[01]+|[\+\-\*\/\^\., ""]|[\(\)\|\!\[\]]" +
|
||||
@")+$", RegexOptions.Compiled);
|
||||
@")+$",
|
||||
RegexOptions.Compiled);
|
||||
|
||||
public static bool InputValid(string input)
|
||||
{
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Registry.Helper
|
||||
/// </summary>
|
||||
/// <param name="query">The query to search</param>
|
||||
/// <returns>A combination of a list of base <see cref="RegistryKey"/> and the sub keys</returns>
|
||||
internal static (IEnumerable<RegistryKey>? baseKey, string subKey) GetRegistryBaseKey(in string query)
|
||||
internal static (IEnumerable<RegistryKey>? BaseKey, string SubKey) GetRegistryBaseKey(in string query)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(query))
|
||||
{
|
||||
|
||||
@@ -63,9 +63,9 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
public void IconThemeDarkTest(string typedString, string subTitleMatch, string expectedResult)
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new ();
|
||||
Mock<Main> main = new();
|
||||
main.Object.IconTheme = "dark";
|
||||
Query expectedQuery = new ("(" + typedString, "(");
|
||||
Query expectedQuery = new("(" + typedString, "(");
|
||||
|
||||
// Act
|
||||
string result = main.Object.Query(expectedQuery).FirstOrDefault(predicate: x => x.SubTitle.StartsWith(subTitleMatch, System.StringComparison.CurrentCulture)).IcoPath;
|
||||
@@ -108,9 +108,9 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
public void IconThemeLightTest(string typedString, string subTitleMatch, string expectedResult)
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new ();
|
||||
Mock<Main> main = new();
|
||||
main.Object.IconTheme = "light";
|
||||
Query expectedQuery = new ("(" + typedString, "(");
|
||||
Query expectedQuery = new("(" + typedString, "(");
|
||||
|
||||
// Act
|
||||
var result = main.Object.Query(expectedQuery).FirstOrDefault(x => x.SubTitle.StartsWith(subTitleMatch, System.StringComparison.CurrentCulture)).IcoPath;
|
||||
|
||||
@@ -41,8 +41,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
public void CountWithoutPluginKeyword(string typedString, int expectedResultCount)
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new ();
|
||||
Query expectedQuery = new (typedString);
|
||||
Mock<Main> main = new();
|
||||
Query expectedQuery = new(typedString);
|
||||
|
||||
// Act
|
||||
var result = main.Object.Query(expectedQuery).Count;
|
||||
@@ -63,8 +63,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
public void CountWithPluginKeyword(string typedString, int expectedResultCount)
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new ();
|
||||
Query expectedQuery = new (typedString, "(");
|
||||
Mock<Main> main = new();
|
||||
Query expectedQuery = new(typedString, "(");
|
||||
|
||||
// Act
|
||||
var result = main.Object.Query(expectedQuery);
|
||||
@@ -87,8 +87,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
public void ValidateBehaviorOnGlobalQueries(string typedString, int expectedResultCount)
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new ();
|
||||
Query expectedQuery = new (typedString);
|
||||
Mock<Main> main = new();
|
||||
Query expectedQuery = new(typedString);
|
||||
|
||||
// Act
|
||||
var result = main.Object.Query(expectedQuery);
|
||||
@@ -141,8 +141,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
public void CanFindFormatResult(string typedString, string expectedResult)
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new ();
|
||||
Query expectedQuery = new (typedString, "(");
|
||||
Mock<Main> main = new();
|
||||
Query expectedQuery = new(typedString, "(");
|
||||
|
||||
// Act
|
||||
var result = main.Object.Query(expectedQuery).FirstOrDefault(x => x.SubTitle.StartsWith(expectedResult, StringComparison.CurrentCulture));
|
||||
@@ -160,8 +160,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
public void DateTimeNumberOnlyInput(string typedString, string expectedResult)
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new ();
|
||||
Query expectedQuery = new (typedString, "(");
|
||||
Mock<Main> main = new();
|
||||
Query expectedQuery = new(typedString, "(");
|
||||
|
||||
// Act
|
||||
var result = main.Object.Query(expectedQuery).FirstOrDefault(x => x.SubTitle.StartsWith(expectedResult, StringComparison.CurrentCulture));
|
||||
@@ -188,8 +188,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
public void InvalidInputNotShowsResults(string typedString)
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new ();
|
||||
Query expectedQuery = new (typedString, "(");
|
||||
Mock<Main> main = new();
|
||||
Query expectedQuery = new(typedString, "(");
|
||||
|
||||
// Act
|
||||
var result = main.Object.Query(expectedQuery).FirstOrDefault();
|
||||
@@ -206,8 +206,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
public void InvalidNumberInputShowsErrorMessage(string typedString)
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new ();
|
||||
Query expectedQuery = new (typedString, "(");
|
||||
Mock<Main> main = new();
|
||||
Query expectedQuery = new(typedString, "(");
|
||||
|
||||
// Act
|
||||
var result = main.Object.Query(expectedQuery).FirstOrDefault().Title;
|
||||
@@ -224,8 +224,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
|
||||
public void InvalidInputNotShowsErrorMessage(string typedString)
|
||||
{
|
||||
// Setup
|
||||
Mock<Main> main = new ();
|
||||
Query expectedQuery = new (typedString, "(");
|
||||
Mock<Main> main = new();
|
||||
Query expectedQuery = new(typedString, "(");
|
||||
|
||||
// Act
|
||||
var result = main.Object.Query(expectedQuery).FirstOrDefault();
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using DrawingImaging = System.Drawing.Imaging;
|
||||
using MediaImaging = System.Windows.Media.Imaging;
|
||||
|
||||
namespace PowerLauncher.Helper
|
||||
{
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using DrawingImaging = System.Drawing.Imaging;
|
||||
using MediaImaging = System.Windows.Media.Imaging;
|
||||
|
||||
// based on: https://stackoverflow.com/questions/61041282/showing-image-thumbnail-with-mouse-cursor-while-dragging/61148788#61148788
|
||||
public static class DragDataObject
|
||||
{
|
||||
|
||||
@@ -153,10 +153,11 @@ namespace PowerLauncher.ViewModel
|
||||
{
|
||||
Task.Run(
|
||||
() =>
|
||||
{
|
||||
PluginManager.UpdatePluginMetadata(e.Results, pair.Metadata, e.Query);
|
||||
UpdateResultView(e.Results, e.Query.RawQuery, _updateToken);
|
||||
}, _updateToken);
|
||||
{
|
||||
PluginManager.UpdatePluginMetadata(e.Results, pair.Metadata, e.Query);
|
||||
UpdateResultView(e.Results, e.Query.RawQuery, _updateToken);
|
||||
},
|
||||
_updateToken);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -553,26 +554,47 @@ namespace PowerLauncher.ViewModel
|
||||
|
||||
var queryResultsTask = Task.Factory.StartNew(
|
||||
() =>
|
||||
{
|
||||
Thread.Sleep(20);
|
||||
|
||||
// Keep track of total number of results for telemetry
|
||||
var numResults = 0;
|
||||
|
||||
// Contains all the plugins for which this raw query is valid
|
||||
var plugins = pluginQueryPairs.Keys.ToList();
|
||||
|
||||
var sw = System.Diagnostics.Stopwatch.StartNew();
|
||||
|
||||
try
|
||||
{
|
||||
var resultPluginPair = new System.Collections.Concurrent.ConcurrentDictionary<PluginMetadata, List<Result>>();
|
||||
Thread.Sleep(20);
|
||||
|
||||
if (_settings.PTRunNonDelayedSearchInParallel)
|
||||
// Keep track of total number of results for telemetry
|
||||
var numResults = 0;
|
||||
|
||||
// Contains all the plugins for which this raw query is valid
|
||||
var plugins = pluginQueryPairs.Keys.ToList();
|
||||
|
||||
var sw = System.Diagnostics.Stopwatch.StartNew();
|
||||
|
||||
try
|
||||
{
|
||||
Parallel.ForEach(pluginQueryPairs, (pluginQueryItem) =>
|
||||
var resultPluginPair = new System.Collections.Concurrent.ConcurrentDictionary<PluginMetadata, List<Result>>();
|
||||
|
||||
if (_settings.PTRunNonDelayedSearchInParallel)
|
||||
{
|
||||
try
|
||||
Parallel.ForEach(pluginQueryPairs, (pluginQueryItem) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var plugin = pluginQueryItem.Key;
|
||||
var query = pluginQueryItem.Value;
|
||||
query.SelectedItems = _userSelectedRecord.GetGenericHistory();
|
||||
var results = PluginManager.QueryForPlugin(plugin, query);
|
||||
resultPluginPair[plugin.Metadata] = results;
|
||||
currentCancellationToken.ThrowIfCancellationRequested();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// nothing to do here
|
||||
}
|
||||
});
|
||||
sw.Stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
currentCancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
// To execute a query corresponding to each plugin
|
||||
foreach (KeyValuePair<PluginPair, Query> pluginQueryItem in pluginQueryPairs)
|
||||
{
|
||||
var plugin = pluginQueryItem.Key;
|
||||
var query = pluginQueryItem.Value;
|
||||
@@ -581,64 +603,43 @@ namespace PowerLauncher.ViewModel
|
||||
resultPluginPair[plugin.Metadata] = results;
|
||||
currentCancellationToken.ThrowIfCancellationRequested();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// nothing to do here
|
||||
}
|
||||
});
|
||||
sw.Stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
currentCancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
// To execute a query corresponding to each plugin
|
||||
foreach (KeyValuePair<PluginPair, Query> pluginQueryItem in pluginQueryPairs)
|
||||
{
|
||||
var plugin = pluginQueryItem.Key;
|
||||
var query = pluginQueryItem.Value;
|
||||
query.SelectedItems = _userSelectedRecord.GetGenericHistory();
|
||||
var results = PluginManager.QueryForPlugin(plugin, query);
|
||||
resultPluginPair[plugin.Metadata] = results;
|
||||
currentCancellationToken.ThrowIfCancellationRequested();
|
||||
}
|
||||
}
|
||||
|
||||
lock (_addResultsLock)
|
||||
{
|
||||
// Using CurrentCultureIgnoreCase since this is user facing
|
||||
if (queryText.Equals(_currentQuery, StringComparison.CurrentCultureIgnoreCase))
|
||||
lock (_addResultsLock)
|
||||
{
|
||||
Results.Clear();
|
||||
foreach (var p in resultPluginPair)
|
||||
// Using CurrentCultureIgnoreCase since this is user facing
|
||||
if (queryText.Equals(_currentQuery, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
UpdateResultView(p.Value, queryText, currentCancellationToken);
|
||||
Results.Clear();
|
||||
foreach (var p in resultPluginPair)
|
||||
{
|
||||
UpdateResultView(p.Value, queryText, currentCancellationToken);
|
||||
currentCancellationToken.ThrowIfCancellationRequested();
|
||||
}
|
||||
|
||||
currentCancellationToken.ThrowIfCancellationRequested();
|
||||
numResults = Results.Results.Count;
|
||||
if (!doFinalSort)
|
||||
{
|
||||
Results.Sort(queryTuning);
|
||||
Results.SelectedItem = Results.Results.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
currentCancellationToken.ThrowIfCancellationRequested();
|
||||
numResults = Results.Results.Count;
|
||||
if (!doFinalSort)
|
||||
{
|
||||
Results.Sort(queryTuning);
|
||||
Results.SelectedItem = Results.Results.FirstOrDefault();
|
||||
UpdateResultsListViewAfterQuery(queryText);
|
||||
}
|
||||
}
|
||||
|
||||
currentCancellationToken.ThrowIfCancellationRequested();
|
||||
if (!doFinalSort)
|
||||
bool noInitialResults = numResults == 0;
|
||||
|
||||
if (!delayedExecution.HasValue || delayedExecution.Value)
|
||||
{
|
||||
UpdateResultsListViewAfterQuery(queryText);
|
||||
}
|
||||
}
|
||||
|
||||
bool noInitialResults = numResults == 0;
|
||||
|
||||
if (!delayedExecution.HasValue || delayedExecution.Value)
|
||||
{
|
||||
// Run the slower query of the DelayedExecution plugins
|
||||
currentCancellationToken.ThrowIfCancellationRequested();
|
||||
Parallel.ForEach(plugins, (plugin) =>
|
||||
// Run the slower query of the DelayedExecution plugins
|
||||
currentCancellationToken.ThrowIfCancellationRequested();
|
||||
Parallel.ForEach(plugins, (plugin) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -683,22 +684,23 @@ namespace PowerLauncher.ViewModel
|
||||
// nothing to do here
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// nothing to do here
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// nothing to do here
|
||||
}
|
||||
|
||||
queryTimer.Stop();
|
||||
var queryEvent = new LauncherQueryEvent()
|
||||
{
|
||||
QueryTimeMs = queryTimer.ElapsedMilliseconds,
|
||||
NumResults = numResults,
|
||||
QueryLength = queryText.Length,
|
||||
};
|
||||
PowerToysTelemetry.Log.WriteEvent(queryEvent);
|
||||
}, currentCancellationToken);
|
||||
queryTimer.Stop();
|
||||
var queryEvent = new LauncherQueryEvent()
|
||||
{
|
||||
QueryTimeMs = queryTimer.ElapsedMilliseconds,
|
||||
NumResults = numResults,
|
||||
QueryLength = queryText.Length,
|
||||
};
|
||||
PowerToysTelemetry.Log.WriteEvent(queryEvent);
|
||||
},
|
||||
currentCancellationToken);
|
||||
|
||||
if (doFinalSort)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user