Skip to content

Commit

Permalink
Closer to compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamTheCoder committed Sep 15, 2024
1 parent add80ff commit d247cc9
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 85 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NoWarn>$(NoWarn);1998;NU5100;NU1900;NU1901;NU1902;NU1903;NU1904</NoWarn>
<NoWarn>$(NoWarn);1998;NU5100;NU1900;NU1901;NU1902;NU1903;NU1904;VSEXTPREVIEW_SETTINGS</NoWarn>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<LangVersion>10.0</LangVersion>
<AssemblyVersion>9.2.6.0</AssemblyVersion>
Expand Down
1 change: 0 additions & 1 deletion Vsix/CodeConversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using CodeConv.Shared.Util;
using EnvDTE;
using ICSharpCode.CodeConverter.Common;
using Microsoft.CodeAnalysis.Text;
Expand Down
31 changes: 8 additions & 23 deletions Vsix/CodeConverterPackage.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
using System;
using System.ComponentModel.Design;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;
using ICSharpCode.CodeConverter.VsExtension.ICSharpCode.CodeConverter.VsExtension;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.Extensibility;
using Microsoft.VisualStudio.LanguageServices;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Threading;
using Task = System.Threading.Tasks.Task;
#pragma warning disable CEE0012 // TODO: I can't find any information on what this means

namespace ICSharpCode.CodeConverter.VsExtension;

/// <summary>
/// Implements the VS package exposed by this assembly.
///
/// This package will load when:
/// This package should load when:
/// * Visual Studio has been configured not to support UIContextRules and has a solution with a csproj or vbproj
/// * Someone clicks one of the menu items
/// * Someone opens the options page (it doesn't need to load in this case, but it seems to anyway)
/// </summary>
/// <remarks>
/// Until the package is loaded, converting a multiple selection of projects won't work because there's no way to set a ProvideUIContextRule that covers that case
/// </remarks>
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
[VisualStudioContribution]
public sealed class CodeConverterPackage : Extension
Expand All @@ -39,10 +28,6 @@ public sealed class CodeConverterPackage : Extension
public CodeConverterPackage(VisualStudioExtensibility extensibility)
{
_extensibility = extensibility;
// Inside this method you can place any initialization code that does not require
// any Visual Studio service because at this point the package object is created but
// not sited yet inside Visual Studio environment. The place to do all the other
// initialization is the Initialize method.
}

protected override void Dispose(bool disposing)
Expand All @@ -63,20 +48,20 @@ public override ExtensionConfiguration ExtensionConfiguration {

}
}
[Experimental("VSEXTPREVIEW_SETTINGS")]

protected override void InitializeServices(IServiceCollection serviceCollection)
{
base.InitializeServices(serviceCollection);
this.InitializeSettingsAsync(_extensibility).Forget();
}
[Experimental("VSEXTPREVIEW_SETTINGS")]

private async Task InitializeSettingsAsync(VisualStudioExtensibility extensibility)
{
await extensibility.Settings().SubscribeAsync(
[ConverterSettings.ConverterSettingsCategory],
CancellationToken.None,
values => {
// look up in dictionary the values
CancellationToken.None, values => {
var settingsAccessor = new ConverterSettingsAccessor(values);
//TODO: Bind/pass this somewhere
});
}
}
6 changes: 5 additions & 1 deletion Vsix/ConverterOptionsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace ICSharpCode.CodeConverter.VsExtension;
/// <summary>
/// Sample https://github.com/microsoft/VSExtensibility/blob/main/New_Extensibility_Model/Samples/SettingsSample/SettingDefinitions.cs
/// </summary>
[Experimental("VSEXTPREVIEW_SETTINGS")]
internal static class ConverterSettings
{
[VisualStudioContribution]
Expand Down Expand Up @@ -39,3 +38,8 @@ internal static class ConverterSettings
Minimum = 1,
};
}

namespace ICSharpCode.CodeConverter.VsExtension
{
}

28 changes: 28 additions & 0 deletions Vsix/ConverterSettingsAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.VisualStudio.Extensibility.Settings;

namespace ICSharpCode.CodeConverter.VsExtension.ICSharpCode.CodeConverter.VsExtension;

public class ConverterSettingsAccessor
{
private readonly SettingValues _settings;

public ConverterSettingsAccessor(SettingValues settings)
{
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
}

public bool CopyResultToClipboardForSingleDocument => GetBooleanSetting(ConverterSettings.CopyResultToClipboardForSingleDocument);
public bool AlwaysOverwriteFiles => GetBooleanSetting(ConverterSettings.AlwaysOverwriteFiles);
public bool CreateBackups => GetBooleanSetting(ConverterSettings.CreateBackups);
public int FormattingTimeout => GetIntegerSetting(ConverterSettings.FormattingTimeout);

private bool GetBooleanSetting(Setting.Boolean setting)
{
return _settings.TryGetValue(setting.FullId, out var value) ? value.ValueOrDefault(setting.DefaultValue) : setting.DefaultValue;
}

private int GetIntegerSetting(Setting.Integer setting)
{
return _settings.TryGetValue(setting.FullId, out var value) ? value.ValueOrDefault(setting.DefaultValue) : setting.DefaultValue;
}
}
50 changes: 0 additions & 50 deletions Vsix/OleMenuCommandWithBlockingStatus.cs

This file was deleted.

9 changes: 0 additions & 9 deletions Vsix/ServiceProviderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ public static async Task<T> GetServiceAsync<T>(this IAsyncServiceProvider provid
{
return (T)(await provider.GetServiceAsync(typeof(T)));
}

public static async Task<T> GetDialogPageAsync<T>(this Package provider) where T : DialogPage
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var dialogPage = (T) provider.GetDialogPage(typeof(T));
await TaskScheduler.Default;
return dialogPage;
}

public static async Task<TReturn> GetServiceAsync<TService, TReturn>(this IAsyncServiceProvider provider)
{
return (TReturn)(await provider.GetServiceAsync(typeof(TService)));
Expand Down

0 comments on commit d247cc9

Please sign in to comment.