Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Merge branch 'VS2022-conversion'
Browse files Browse the repository at this point in the history
  • Loading branch information
malware-dev committed May 7, 2023
2 parents d7d89ae + cefcda8 commit f0fa2c2
Show file tree
Hide file tree
Showing 79 changed files with 624 additions and 2,717 deletions.
Binary file modified Release/PublishTool/BuildForPublish.exe
Binary file not shown.
13 changes: 13 additions & 0 deletions Source/.idea/.idea.Malware's Dev Kit/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Source/.idea/.idea.Malware's Dev Kit/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Source/.idea/.idea.Malware's Dev Kit/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Source/.idea/.idea.Malware's Dev Kit/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Source/.idea/.idea.Malware's Dev Kit/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Source/MDK/Build/AnalysisExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static bool IsInterfaceImplementation(this ISymbol symbol)
.Any(member =>
{
var implementation = symbol.ContainingType.FindImplementationForInterfaceMember(member);
return implementation != null && implementation.Equals(symbol);
return implementation != null && SymbolEqualityComparer.Default.Equals(implementation, symbol);
});
}

Expand Down
8 changes: 4 additions & 4 deletions Source/MDK/Build/Annotations/MdkAnnotationRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ SyntaxTriviaList TrimTrivia(SyntaxTriviaList source)
if (trivia.GetStructure() is RegionDirectiveTriviaSyntax regionDirective)
{
list.AddRange(regionDirective.GetLeadingTrivia());
while (list.Count > 0 && list[list.Count - 1].Kind() == SyntaxKind.WhitespaceTrivia)
while (list.Count > 0 && list[list.Count - 1].IsKind(SyntaxKind.WhitespaceTrivia))
list.RemoveAt(list.Count - 1);
list.AddRange(regionDirective.GetTrailingTrivia().SkipWhile(t => t.Kind() == SyntaxKind.EndOfLineTrivia));
list.AddRange(regionDirective.GetTrailingTrivia().SkipWhile(t => t.IsKind(SyntaxKind.EndOfLineTrivia)));
continue;
}

if (trivia.GetStructure() is EndRegionDirectiveTriviaSyntax endRegionDirective)
{
list.AddRange(endRegionDirective.GetLeadingTrivia());
while (list.Count > 0 && list[list.Count - 1].Kind() == SyntaxKind.WhitespaceTrivia)
while (list.Count > 0 && list[list.Count - 1].IsKind(SyntaxKind.WhitespaceTrivia))
list.RemoveAt(list.Count - 1);
list.AddRange(endRegionDirective.GetTrailingTrivia().SkipWhile(t => t.Kind() == SyntaxKind.EndOfLineTrivia));
list.AddRange(endRegionDirective.GetTrailingTrivia().SkipWhile(t => t.IsKind(SyntaxKind.EndOfLineTrivia)));
continue;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/MDK/Build/Composers/Default/NewlineCleaner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public NewlineCleaner() : base(true)
public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
{
trivia = base.VisitTrivia(trivia);
if (trivia.Kind() == SyntaxKind.EndOfLineTrivia && trivia.ToString() == "\r\n")
if (trivia.IsKind(SyntaxKind.EndOfLineTrivia) && trivia.ToString() == "\r\n")
{
trivia = SyntaxFactory.EndOfLine("\n");
}
Expand Down
4 changes: 2 additions & 2 deletions Source/MDK/Build/Composers/Minifying/CodeSimplifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ void TrimTrivia(SyntaxTriviaList leadingTrivia, List<SyntaxTrivia> newTrivia)
case SyntaxKind.DocumentationCommentExteriorTrivia:
case SyntaxKind.SingleLineDocumentationCommentTrivia:
case SyntaxKind.MultiLineDocumentationCommentTrivia:
while (index < leadingTrivia.Count && leadingTrivia[index].Kind() != SyntaxKind.EndOfLineTrivia)
while (index < leadingTrivia.Count && !leadingTrivia[index].IsKind(SyntaxKind.EndOfLineTrivia))
index++;
while (newTrivia.Count > 0 && newTrivia[newTrivia.Count - 1].Kind() == SyntaxKind.WhitespaceTrivia)
while (newTrivia.Count > 0 && newTrivia[newTrivia.Count - 1].IsKind(SyntaxKind.WhitespaceTrivia))
newTrivia.RemoveAt(newTrivia.Count - 1);
continue;

Expand Down
4 changes: 2 additions & 2 deletions Source/MDK/Build/Composers/Minifying/LineWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public override SyntaxNode VisitInterpolatedStringExpression(InterpolatedStringE
public override SyntaxToken VisitToken(SyntaxToken token)
{
token = base.VisitToken(token);
if (token.Kind() == SyntaxKind.None)
if (token.IsKind(SyntaxKind.None))
return token;

if (token.ShouldBePreserved())
Expand All @@ -101,7 +101,7 @@ public override SyntaxToken VisitToken(SyntaxToken token)

_isPreservedBlock = false;

if (token.Kind() == SyntaxKind.None)
if (token.IsKind(SyntaxKind.None))
return token;

var span = token.GetLocation().GetLineSpan();
Expand Down
5 changes: 5 additions & 0 deletions Source/MDK/Build/Composers/Minifying/MinifyingComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public override async Task<string> GenerateAsync(ProgramComposition composition,
}


/// <summary>
/// Generate the final script after all processors have run.
/// </summary>
/// <param name="composition"></param>
/// <returns></returns>
protected async Task<string> GenerateScriptAsync(ProgramComposition composition)
{
var root = composition.RootNode;
Expand Down
5 changes: 3 additions & 2 deletions Source/MDK/Build/Composers/Minifying/SymbolRenamer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ public async Task<ProgramComposition> ProcessAsync([NotNull] ProgramComposition

var document = composition.Document;
var documentId = document.Id;
var newSolution = await Renamer.RenameSymbolAsync(document.Project.Solution, definition.Symbol, newName, document.Project.Solution.Options);
composition = await composition.WithDocumentAsync(newSolution.GetDocument(documentId));
//var newSolution = await Renamer.RenameSymbolAsync(document.Project.Solution, definition.Symbol, newName, document.Project.Solution.Options);
var newSolution = await Renamer.RenameSymbolAsync(document.Project.Solution, definition.Symbol, new SymbolRenameOptions(), newName);
composition = await composition.WithDocumentAsync(newSolution.GetDocument(documentId)!);
symbolDefinitions = analyzer.FindSymbols(composition, config).ToList();
symbolDefinitions.Sort((a, b) => a.SyntaxNode.FullSpan.Start);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class WhitespaceCompactor : ProgramRewriter
public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
{
trivia = base.VisitTrivia(trivia);
if (trivia.Kind() == SyntaxKind.EndOfLineTrivia && trivia.ToString() == "\r\n")
if (trivia.IsKind(SyntaxKind.EndOfLineTrivia) && trivia.ToString() == "\r\n")
trivia = trivia.CopyAnnotationsTo(SyntaxFactory.EndOfLine("\n"));

return trivia;
Expand Down
6 changes: 3 additions & 3 deletions Source/MDK/Build/Composers/StripComments/CommentStripper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void TrimTrivia(SyntaxTriviaList trivia, List<SyntaxTrivia> newTrivia, bool trai
newTrivia.Add(triviaItem);
continue;
}
if (lastPreserved && triviaItem.Kind() == SyntaxKind.WhitespaceTrivia)
if (lastPreserved && triviaItem.IsKind(SyntaxKind.WhitespaceTrivia))
{
lastPreserved = false;
continue;
Expand All @@ -70,11 +70,11 @@ void TrimTrivia(SyntaxTriviaList trivia, List<SyntaxTrivia> newTrivia, bool trai
case SyntaxKind.DocumentationCommentExteriorTrivia:
case SyntaxKind.SingleLineDocumentationCommentTrivia:
case SyntaxKind.MultiLineDocumentationCommentTrivia:
while (index < trivia.Count && trivia[index].Kind() != SyntaxKind.EndOfLineTrivia)
while (index < trivia.Count && !trivia[index].IsKind(SyntaxKind.EndOfLineTrivia))
index++;
if (trailingMode)
index--;
while (newTrivia.Count > 0 && newTrivia[newTrivia.Count - 1].Kind() == SyntaxKind.WhitespaceTrivia)
while (newTrivia.Count > 0 && newTrivia[newTrivia.Count - 1].IsKind(SyntaxKind.WhitespaceTrivia))
newTrivia.RemoveAt(newTrivia.Count - 1);
continue;

Expand Down
4 changes: 2 additions & 2 deletions Source/MDK/Build/DocumentAnalysis/DocumentAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ ClassDeclarationSyntax MoveBraceTrivia(ClassDeclarationSyntax node)

// Skip the whitespace and line the brace itself is on
var i = 0;
while (i < trailingTrivia.Count && trailingTrivia[i].Kind() == SyntaxKind.WhitespaceTrivia)
while (i < trailingTrivia.Count && trailingTrivia[i].IsKind(SyntaxKind.WhitespaceTrivia))
i++;
if (i < trailingTrivia.Count && trailingTrivia[i].Kind() == SyntaxKind.EndOfLineTrivia)
if (i < trailingTrivia.Count && trailingTrivia[i].IsKind(SyntaxKind.EndOfLineTrivia))
i++;
node = node.WithOpenBraceToken(node.OpenBraceToken.WithTrailingTrivia(SyntaxFactory.EndOfLine("\n")));
if (i < trailingTrivia.Count)
Expand Down
4 changes: 2 additions & 2 deletions Source/MDK/Build/DocumentAnalysis/ProgramScriptPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ public override string GenerateContent()

// Skip the whitespace and line the brace itself is on
var i = 0;
while (i < trailingTrivia.Count && trailingTrivia[i].Kind() == SyntaxKind.WhitespaceTrivia)
while (i < trailingTrivia.Count && trailingTrivia[i].IsKind(SyntaxKind.WhitespaceTrivia))
i++;
if (i < trailingTrivia.Count && trailingTrivia[i].Kind() == SyntaxKind.EndOfLineTrivia)
if (i < trailingTrivia.Count && trailingTrivia[i].IsKind(SyntaxKind.EndOfLineTrivia))
i++;
for (; i < trailingTrivia.Count; i++)
buffer.Append(trailingTrivia[i].ToFullString());
Expand Down
6 changes: 3 additions & 3 deletions Source/MDK/Build/TypeTrimming/TypeTrimmer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ public async Task<ProgramComposition> ProcessAsync([NotNull] ProgramComposition
throw new ArgumentNullException(nameof(composition));
if (config == null)
throw new ArgumentNullException(nameof(config));
var nodes = new Dictionary<ISymbol, Node>();
var nodes = new Dictionary<ISymbol, Node>(SymbolEqualityComparer.Default);
var analyzer = new UsageAnalyzer();
var symbolDefinitions = await analyzer.FindUsagesAsync(composition, config);
var symbolLookup = symbolDefinitions.GroupBy(d => d.Symbol).ToDictionary(g => g.Key, g => g.ToList());
var symbolLookup = symbolDefinitions.GroupBy(d => d.Symbol, SymbolEqualityComparer.Default).ToDictionary(g => g.Key, g => g.ToList(), SymbolEqualityComparer.Default);
var rootNode = composition.RootNode;
foreach (var definition in symbolDefinitions)
{
if (!(definition.Symbol is ITypeSymbol typeSymbol))
if (definition.Symbol is not ITypeSymbol typeSymbol)
continue;
if (typeSymbol.TypeKind == TypeKind.TypeParameter)
continue;
Expand Down
1 change: 1 addition & 0 deletions Source/MDK/Commands/DeployProjectCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public DeployProjectCommand(ExtendedPackage package) : base(package)

protected override async void OnExecute()
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
if (!TryGetValidProject(out Project project, out _))
{
VsShellUtilities.ShowMessageBox(ServiceProvider, Text.ProjectOptionsCommand_OnExecute_NoMDKProjectsDescription, Text.ProjectOptionsCommand_OnExecute_NoMDKProjects, OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
Expand Down
14 changes: 12 additions & 2 deletions Source/MDK/Commands/ProjectDependentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using EnvDTE;
using Malware.MDKServices;
using MDK.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Command = MDK.VisualStudio.Command;

namespace MDK.Commands
Expand All @@ -14,18 +15,24 @@ protected ProjectDependentCommand(ExtendedPackage package) : base(package)

protected override void OnBeforeQueryStatus()
{
ThreadHelper.ThrowIfNotOnUIThread();
var package = (MDKPackage)Package;
OleCommand.Visible = package.IsEnabled && TryGetValidProject(out _);
}

protected bool TryGetValidProject(out Project project, out MDKProjectProperties projectProperties)
{
ThreadHelper.ThrowIfNotOnUIThread();
var package = (MDKPackage)Package;
package.Echo("MDK Command", Id, "is attempting to retrieve an MDK project");
var dte2 = (EnvDTE80.DTE2)Package.DTE;
project = ((IEnumerable)dte2.ToolWindows.SolutionExplorer.SelectedItems)
.OfType<UIHierarchyItem>()
.Select(item => item.Object)
.Select(item =>
{
ThreadHelper.ThrowIfNotOnUIThread();
return item.Object;
})
.OfType<Project>()
.FirstOrDefault();
if (project == null)
Expand All @@ -45,6 +52,9 @@ protected bool TryGetValidProject(out Project project, out MDKProjectProperties
}

protected bool TryGetValidProject(out MDKProjectProperties projectProperties)
=> TryGetValidProject(out _, out projectProperties);
{
ThreadHelper.ThrowIfNotOnUIThread();
return TryGetValidProject(out _, out projectProperties);
}
}
}
1 change: 1 addition & 0 deletions Source/MDK/Commands/ProjectOptionsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public ProjectOptionsCommand(ExtendedPackage package) : base(package)

protected override void OnExecute()
{
ThreadHelper.ThrowIfNotOnUIThread();
if (!TryGetValidProject(out MDKProjectProperties projectInfo))
{
VsShellUtilities.ShowMessageBox(ServiceProvider, Text.ProjectOptionsCommand_OnExecute_NoMDKProjectsDescription, Text.ProjectOptionsCommand_OnExecute_NoMDKProjects, OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
Expand Down
1 change: 1 addition & 0 deletions Source/MDK/Commands/RefreshWhitelistCacheCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ protected override void OnBeforeQueryStatus()

protected override void OnExecute()
{
ThreadHelper.ThrowIfNotOnUIThread();
var package = (MDKPackage)Package;

if (RefreshWhitelistCacheDialog.ShowDialog(new RefreshWhitelistCacheDialogModel(package, package.DTE)) == true)
Expand Down
1 change: 1 addition & 0 deletions Source/MDK/Commands/ScriptManagerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public BlueprintManagerCommand(ExtendedPackage package) : base(package)

protected override void OnExecute()
{
ThreadHelper.ThrowIfNotOnUIThread();
if (!TryGetValidProject(out MDKProjectProperties projectInfo))
{
VsShellUtilities.ShowMessageBox(ServiceProvider, Text.BlueprintManagerCommand_OnExecute_NoMDKProjectsDescription, Text.BlueprintManagerCommand_OnExecute_NoMDKProjects, OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
Expand Down
Loading

0 comments on commit f0fa2c2

Please sign in to comment.