Skip to content

Commit 38e26cd

Browse files
committed
Add support for Properties (get/set) + make Disasmo less fragile around weirdly configured projects
1 parent 151cd1c commit 38e26cd

File tree

14 files changed

+109
-58
lines changed

14 files changed

+109
-58
lines changed

Disasmo/Resources/DisasmoLoader3.cs_template

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class DisasmoLoader
3232
if (fastType != null)
3333
{
3434
PrecompileMethods(fastType, methodName);
35+
PrecompileProperties(fastType, methodName);
3536
return;
3637
}
3738

@@ -44,6 +45,21 @@ public class DisasmoLoader
4445
if (type.FullName?.Replace('+', '.').Contains(typeName) == true)
4546
{
4647
PrecompileMethods(type, methodName);
48+
PrecompileProperties(type, methodName);
49+
}
50+
}
51+
}
52+
53+
private static void PrecompileProperties(Type type, string propertyName)
54+
{
55+
foreach (PropertyInfo propInfo in type.GetProperties((BindingFlags)60))
56+
{
57+
if (propInfo.Name == "*" || propInfo.Name == propertyName)
58+
{
59+
if (propInfo.GetMethod != null)
60+
RuntimeHelpers.PrepareMethod(propInfo.GetMethod.MethodHandle);
61+
if (propInfo.SetMethod != null)
62+
RuntimeHelpers.PrepareMethod(propInfo.SetMethod.MethodHandle);
4763
}
4864
}
4965
}

Disasmo/Utils/RemoteCheckedJitManager.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

Disasmo/Utils/SymbolUtils.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public static DisasmoSymbolInfo FromSymbol(ISymbol symbol)
3232
methodName = symbol.Name;
3333
}
3434
}
35+
else if (symbol is IPropertySymbol prop)
36+
{
37+
target = "*" + symbol.ContainingType.Name + ":get_" + symbol.Name + " " + "*" + symbol.ContainingType.Name + ":set_" + symbol.Name;
38+
hostType = symbol.ContainingType.ToString();
39+
methodName = symbol.Name;
40+
}
3541
else
3642
{
3743
// the whole class

RELEASE_NOTES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 5.5.0
2+
3+
* Added support for getters/setters (properties)
4+
* Minor improvements around dotnet-build
5+
16
# 5.4.1
27

38
* Hot-fix for flowgraphs

src/Vsix/Analyzers/DisasmMethodOrClassAction.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ protected override async Task<bool> IsValidSymbol(Document document, int tokenPo
5454
return true;
5555
if (token.Parent is ConstructorDeclarationSyntax)
5656
return true;
57+
if (token.Parent is PropertyDeclarationSyntax)
58+
return true;
5759
}
5860
catch
5961
{
@@ -70,6 +72,9 @@ static ISymbol FindRelatedSymbol(SemanticModel semanticModel, SyntaxNode node, b
7072
if (node is MethodDeclarationSyntax m)
7173
return semanticModel.GetDeclaredSymbol(m, ct);
7274

75+
if (node is PropertyDeclarationSyntax p)
76+
return semanticModel.GetDeclaredSymbol(p, ct);
77+
7378
if (node is ConstructorDeclarationSyntax ctor)
7479
return semanticModel.GetDeclaredSymbol(ctor, ct);
7580

src/Vsix/DisasmoPackage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static async Task<Version> GetLatestVersionOnline()
8787
public Version GetCurrentVersion()
8888
{
8989
//TODO: fix
90-
return new Version(5, 4, 1);
90+
return new Version(5, 5, 0);
9191

9292
//try
9393
//{

src/Vsix/Properties/Settings.Designer.cs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Vsix/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,8 @@
5656
<Setting Name="DisableLightBulb" Type="System.Boolean" Scope="User">
5757
<Value Profile="(Default)">False</Value>
5858
</Setting>
59+
<Setting Name="DontGuessTFM" Type="System.Boolean" Scope="User">
60+
<Value Profile="(Default)">False</Value>
61+
</Setting>
5962
</Settings>
6063
</SettingsFile>

src/Vsix/Utils/IdeUtils.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Windows;
88
using Disasmo.Utils;
99
using EnvDTE;
10+
using Microsoft.VisualStudio.ProjectSystem;
1011
using Microsoft.VisualStudio.ProjectSystem.Properties;
1112
using Microsoft.VisualStudio.Shell;
1213
using Microsoft.VisualStudio.Shell.Interop;
@@ -98,8 +99,30 @@ public static void RunDiffTools(string contentLeft, string contentRight)
9899
}
99100
}
100101

102+
public static async Task<IProjectProperties> GetProjectProperties(UnconfiguredProject unconfiguredProject, string config)
103+
{
104+
try
105+
{
106+
// it will throw "Release config was not found" to the Output if there is no such config in the project
107+
ProjectConfiguration releaseConfig = await unconfiguredProject.Services.ProjectConfigurationsService.GetProjectConfigurationAsync("Release");
108+
ConfiguredProject configuredProject = await unconfiguredProject.LoadConfiguredProjectAsync(releaseConfig);
109+
return configuredProject.Services.ProjectPropertiesProvider.GetCommonProperties();
110+
}
111+
catch
112+
{
113+
// VS was not able to find the given config (but it still might exist)
114+
return null;
115+
}
116+
}
117+
101118
public static async Task<(string, int)> GetTargetFramework(IProjectProperties projectProperties)
102119
{
120+
if (projectProperties == null)
121+
{
122+
// It is likely hidden somewhere in props, TODO: find a better way
123+
return ("net7.0", 7);
124+
}
125+
103126
try
104127
{
105128
string tfms = await projectProperties.GetEvaluatedPropertyValueAsync("TargetFrameworks");

src/Vsix/ViewModels/MainViewModel.cs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using Microsoft.VisualStudio.ProjectSystem;
1717
using Microsoft.VisualStudio.ProjectSystem.Properties;
1818
using System.Collections.ObjectModel;
19-
using Disasmo.Properties;
2019

2120
namespace Disasmo
2221
{
@@ -40,8 +39,8 @@ public class MainViewModel : ViewModelBase
4039
// let's use new name for the temp folder each version to avoid possible issues (e.g. changes in the Disasmo.Loader)
4140
private string DisasmoFolder => "Disasmo-v" + DisasmoPackage.Current?.GetCurrentVersion();
4241

43-
public SettingsViewModel SettingsVm { get; } = new SettingsViewModel();
44-
public IntrinsicsViewModel IntrinsicsVm { get; } = new IntrinsicsViewModel();
42+
public SettingsViewModel SettingsVm { get; } = new();
43+
public IntrinsicsViewModel IntrinsicsVm { get; } = new();
4544

4645
public event Action MainPageRequested;
4746

@@ -128,7 +127,6 @@ public string FgPngPath
128127
get => _fgPngPath;
129128
set => Set(ref _fgPngPath, value);
130129
}
131-
132130

133131
public ICommand RefreshCommand => new RelayCommand(() => RunOperationAsync(_currentSymbol));
134132

@@ -550,12 +548,7 @@ public async void RunOperationAsync(ISymbol symbol)
550548

551549
// Find Release-x64 configuration:
552550
Project currentProject = dte.GetActiveProject();
553-
UnconfiguredProject unconfiguredProject = GetUnconfiguredProject(currentProject);
554-
555-
// it will throw "Release config was not found" to the Output if there is no such config in the project
556-
ProjectConfiguration releaseConfig = await unconfiguredProject.Services.ProjectConfigurationsService.GetProjectConfigurationAsync("Release");
557-
ConfiguredProject configuredProject = await unconfiguredProject.LoadConfiguredProjectAsync(releaseConfig);
558-
IProjectProperties projectProperties = configuredProject.Services.ProjectPropertiesProvider.GetCommonProperties();
551+
IProjectProperties projectProperties = await IdeUtils.GetProjectProperties(GetUnconfiguredProject(currentProject), "Release");
559552

560553
ThrowIfCanceled();
561554

@@ -635,7 +628,8 @@ public async void RunOperationAsync(ISymbol symbol)
635628
}
636629
}
637630

638-
DisasmoOutDir = Path.Combine(await projectProperties.GetEvaluatedPropertyValueAsync("OutputPath"), DisasmoFolder + (SettingsVm.UseDotnetPublishForReload ? "_published" : ""));
631+
string outputDir = projectProperties == null ? "bin" : await projectProperties.GetEvaluatedPropertyValueAsync("OutputPath");
632+
DisasmoOutDir = Path.Combine(outputDir, DisasmoFolder + (SettingsVm.UseDotnetPublishForReload ? "_published" : ""));
639633
string currentProjectDirPath = Path.GetDirectoryName(_currentProjectPath);
640634

641635
dte.SaveAllActiveDocuments();
@@ -648,13 +642,15 @@ public async void RunOperationAsync(ISymbol symbol)
648642
return;
649643
}
650644

645+
string tfmPart = SettingsVm.DontGuessTFM ? "" : $"-f {_currentTf}";
646+
651647
ProcessResult publishResult;
652648
if (SettingsVm.UseDotnetPublishForReload)
653649
{
654650
LoadingStatus = $"dotnet publish -r win-x64 -c Release -o ...";
655651

656652
string dotnetPublishArgs =
657-
$"publish -f {_currentTf} -r win-x64 -c Release -o {DisasmoOutDir} --self-contained true /p:PublishTrimmed=false /p:PublishSingleFile=false /p:WarningLevel=0 /p:TreatWarningsAsErrors=false -v:q";
653+
$"publish {tfmPart} -r win-x64 -c Release -o {DisasmoOutDir} --self-contained true /p:PublishTrimmed=false /p:PublishSingleFile=false /p:WarningLevel=0 /p:TreatWarningsAsErrors=false -v:q";
658654

659655
publishResult = await ProcessUtils.RunProcess("dotnet", dotnetPublishArgs, null, currentProjectDirPath, cancellationToken: UserCt);
660656
}
@@ -669,23 +665,25 @@ public async void RunOperationAsync(ISymbol symbol)
669665

670666
LoadingStatus = "dotnet build -c Release -o ...";
671667

672-
string dotnetBuildArgs = $"build -f {_currentTf} -c Release -o {DisasmoOutDir} --no-self-contained " +
668+
string dotnetBuildArgs = $"build {tfmPart} -c Release -o {DisasmoOutDir} --no-self-contained " +
673669
"/p:RuntimeIdentifier=\"\" " +
674670
"/p:RuntimeIdentifiers=\"\" " +
675671
"/p:WarningLevel=0 " +
676672
"/p:TreatWarningsAsErrors=false ";
677-
678-
if (SettingsVm.UseNoRestoreFlag)
679-
dotnetBuildArgs += " --no-restore --no-dependencies --nologo";
680673

681-
var fasterBuildArgs = new Dictionary<string, string>
674+
Dictionary<string, string> fasterBuildEnvVars = new Dictionary<string, string>
682675
{
683-
["DOTNET_TC_QuickJitForLoops"] = "1", // slightly speeds up build (not needed for >=.net7.0)
684676
["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "1",
685-
["DOTNET_MULTILEVEL_LOOKUP"] = "0",
686677
["DOTNET_CLI_TELEMETRY_OPTOUT"] = "1"
687678
};
688-
publishResult = await ProcessUtils.RunProcess("dotnet", dotnetBuildArgs, fasterBuildArgs,
679+
680+
if (SettingsVm.UseNoRestoreFlag)
681+
{
682+
dotnetBuildArgs += " --no-restore --no-dependencies --nologo";
683+
fasterBuildEnvVars["DOTNET_MULTILEVEL_LOOKUP"] = "0";
684+
}
685+
686+
publishResult = await ProcessUtils.RunProcess("dotnet", dotnetBuildArgs, fasterBuildEnvVars,
689687
currentProjectDirPath,
690688
cancellationToken: UserCt);
691689
}

0 commit comments

Comments
 (0)