Repository navigation
Import EditorConfig templates from dotnet/templates #85157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 128 commits
e20715c
c2b847c
16ef4d7
63798e0
5b5cbf2
75e7da8
e7d1a72
5f47096
0e2d40b
204fd18
a51b816
a7923bd
b81ba3e
7b6ff0f
cf1509d
263aa2c
c1a9b39
7d5caae
1876ee3
5650df2
14ae3d3
57afd70
8383986
b54f2b0
8483e7e
49179df
92e0c83
f38249d
33c8e57
12ef5ee
53f8943
3feda1d
7393b65
838620a
2694f63
fa02a88
7aca9d5
e9bf6bf
2ce63be
81b3759
3d618ce
b664cc7
752e0e4
3eddecf
4a08a4e
b38da43
6a4bf5a
750c595
81d604a
5ce661c
961f4bf
13efd90
67e4e98
f19b021
2c692ec
13a5a99
ee6ea58
ac52d24
b139691
c6687e3
4eeebab
eb4857e
0ed1edf
79a25bb
3a10ae9
a848c7f
b2a3239
b6ab0d2
f0e827f
ee1fa44
813e9f4
8ea56de
0cd411a
e3b3455
e7cd9d0
288aa00
b3c1388
6e355d3
903e441
4a5e265
e6866b8
946bfb8
800bb91
9627978
37436c4
ffa6dfc
3dc3a7d
632ce48
45d4ba0
52026b3
af82228
ac60cf5
a9e0f3a
33d7977
8dc02ae
28dd904
e23ad7e
a1ffe13
14cb4c8
afded3f
58a28b2
f06588a
4bdfe78
5442e70
19fc31a
5684e8f
02b6fe0
1c3b040
573e4ad
840affc
05b801c
28ba5d1
e7dd95e
7aa132c
5559cd5
a88b7ab
5f055fd
8747a6e
257f5aa
fc7e19b
b48c8fd
858fd56
7bc126a
2eaca5e
6e53187
0c956b3
60622e1
f1f7cd9
393d34f
d2b36cb
e49c1db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ BenchmarkDotNet.Artifacts/ | |
| [Bb]inaries/ | ||
| [Bb]in/ | ||
| [Oo]bj/ | ||
| src/VisualStudio/EditorConfig/Templates/ModifiedTemplates/ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this something that should be landing in artifacts? |
||
| .dotnet/ | ||
| .tools/ | ||
| .packages/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using Microsoft.VisualStudio.Shell; | ||
| using Microsoft.VisualStudio.Templates.Editorconfig.Wizard.Generator; | ||
| using Microsoft.VisualStudio.Templates.Editorconfig.Wizard.Logging.Kinds; | ||
| using Microsoft.VisualStudio.Templates.Editorconfig.Wizard.Utilities; | ||
| using System.ComponentModel.Design; | ||
| using System.Threading.Tasks; | ||
| using static Microsoft.VisualStudio.Templates.Editorconfig.Wizard.Logging.Logger; | ||
|
|
||
| namespace Microsoft.VisualStudio.Templates.Editorconfig.Command.Commands; | ||
|
|
||
| internal class AddEditorConfigFileCommand : CommandBase | ||
| { | ||
| protected override CommandID Id { get; } = new CommandID(PackageGuids.AddEditorConfigCmdSet, PackageIds.AddEditorConfigFileCommand); | ||
|
|
||
| protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) | ||
| { | ||
| using var _ = LogUserAction(UserTask.CreateFromRightClickMenu); | ||
| if (Package is not null) | ||
| { | ||
| await Package.JoinableTaskFactory.SwitchToMainThreadAsync(Package.DisposalToken); | ||
| var (success, fileName) = EditorConfigFileGenerator.TryAddFileToSolution(); | ||
| Assert(success, "Unable to add the editorconfig file to the solution"); | ||
|
|
||
| if (success && fileName is not null) | ||
| { | ||
| VSHelpers.OpenFile(fileName); | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using Microsoft.VisualStudio.Templates.Editorconfig.Wizard.Generator; | ||
| using Microsoft.VisualStudio.Templates.Editorconfig.Wizard.Logging.Kinds; | ||
| using Microsoft.VisualStudio.Workspace.VSIntegration.UI; | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel.Design; | ||
| using static Microsoft.VisualStudio.Templates.Editorconfig.Wizard.Logging.Logger; | ||
|
|
||
| namespace Microsoft.VisualStudio.Templates.Editorconfig.Command.Commands; | ||
|
|
||
| internal class AddEditorConfigFileCommandHandler : CommandHandlerBase | ||
| { | ||
| protected override CommandID Id { get; } = new CommandID(PackageGuids.AddEditorConfigCmdSet, PackageIds.AddEditorConfigFileAnyCodeCommand); | ||
|
|
||
| protected override bool QueryStatus(List<WorkspaceVisualNodeBase> selection) | ||
| => selection.Count == 1 && selection[0] is IFolderNode; | ||
|
Comment on lines
+18
to
+19
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which command is this defined for? Are we loading this package/DLL just to proffer a command like this? I'm just wondering if we were to pull this into any of our existing assemblies we can remove a DLL load. |
||
|
|
||
| protected override bool Execute(List<WorkspaceVisualNodeBase> selection) | ||
| { | ||
| Assert(selection.Count == 1, "Multiple items selected"); | ||
| if (selection.Count == 1 && selection[0] is IFolderNode folder) | ||
| { | ||
| using var _1 = LogUserAction(UserTask.CreateFromRightClickMenuAnyCode); | ||
| _ = EditorConfigFileGenerator.TryAddFileToFolder(folder.FullPath); | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using Microsoft.VisualStudio.Workspace.VSIntegration.UI; | ||
| using System.ComponentModel.Composition; | ||
|
|
||
| namespace Microsoft.VisualStudio.Templates.Editorconfig.Command.Commands; | ||
|
|
||
| [Export(typeof(INodeExtender))] | ||
| internal class AddEditorConfigFileCommandProvider : INodeExtender | ||
| { | ||
| private IWorkspaceCommandHandler _handler = new AddEditorConfigFileCommandHandler(); | ||
|
|
||
| public IChildrenSource? ProvideChildren(WorkspaceVisualNodeBase parentNode) => null; | ||
|
|
||
| public IWorkspaceCommandHandler? ProvideCommandHandler(WorkspaceVisualNodeBase parentNode) | ||
| => parentNode is IFolderNode ? _handler : null; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using Microsoft.VisualStudio.Shell; | ||
| using Microsoft.VisualStudio.Templates.Editorconfig.Wizard.Logging.Kinds; | ||
| using System; | ||
| using System.ComponentModel.Design; | ||
| using System.Threading.Tasks; | ||
| using static Microsoft.VisualStudio.Templates.Editorconfig.Wizard.Logging.Logger; | ||
|
|
||
| namespace Microsoft.VisualStudio.Templates.Editorconfig.Command.Commands; | ||
|
|
||
| internal abstract class CommandBase | ||
| { | ||
| public static async Task<T> InitializeAsync<T>(AsyncPackage package) | ||
| where T : CommandBase, new() | ||
| { | ||
| T command = new(); | ||
|
|
||
| command.Command = new OleMenuCommand(command.Execute, command.Id); | ||
| command.Package = package; | ||
| await package.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken); | ||
| IMenuCommandService obj = (IMenuCommandService)await package.GetServiceAsync(typeof(IMenuCommandService)); | ||
| Assumes.Present(obj); | ||
| Assert(obj is not null, "unable to get the menu command service"); | ||
| if (obj is not null) | ||
| { | ||
| obj.AddCommand(command.Command); | ||
| LogEvent(EventId.CommandRegistered); | ||
| } | ||
| return command; | ||
| } | ||
|
|
||
| public OleMenuCommand? Command { get; protected set; } | ||
|
|
||
| public AsyncPackage? Package { get; protected set; } | ||
|
|
||
| private void Execute(object? sender, EventArgs e) | ||
| { | ||
| EventArgs e2 = e; | ||
| Package?.JoinableTaskFactory.RunAsync(async delegate | ||
| { | ||
| try | ||
| { | ||
| await ExecuteAsync((OleMenuCmdEventArgs)e2); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| LogException(ex, "Error executing command"); | ||
| throw; | ||
| } | ||
| }).FileAndForget("AddEditorConfigFileCommand"); | ||
| } | ||
|
|
||
| protected abstract CommandID Id { get; } | ||
|
|
||
| protected abstract Task ExecuteAsync(OleMenuCmdEventArgs e); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using Microsoft.VisualStudio.OLE.Interop; | ||
| using Microsoft.VisualStudio.Shell; | ||
| using Microsoft.VisualStudio.Workspace.VSIntegration.UI; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel.Design; | ||
|
|
||
| namespace Microsoft.VisualStudio.Templates.Editorconfig.Command.Commands; | ||
|
|
||
| internal abstract class CommandHandlerBase : IWorkspaceCommandHandler | ||
| { | ||
| public virtual int Priority => 100; | ||
| public virtual bool IgnoreOnMultiselect => true; | ||
|
|
||
| protected abstract CommandID Id { get; } | ||
|
|
||
| protected abstract bool QueryStatus(List<WorkspaceVisualNodeBase> selection); | ||
| protected abstract bool Execute(List<WorkspaceVisualNodeBase> selection); | ||
|
|
||
| public int Exec(List<WorkspaceVisualNodeBase> selection, Guid cmdGroup, uint cmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) | ||
| { | ||
| ThreadHelper.ThrowIfNotOnUIThread(); | ||
|
|
||
| if (IsSupportedCommand(cmdGroup, cmdId) && Execute(selection)) | ||
| { | ||
| return VSConstants.S_OK; | ||
| } | ||
|
|
||
| return (int)Constants.OLECMDERR_E_NOTSUPPORTED; | ||
| } | ||
|
|
||
| public bool QueryStatus(List<WorkspaceVisualNodeBase> selection, Guid cmdGroup, uint cmdId, ref uint cmdf, ref string? customTitle) | ||
| { | ||
| if (IsSupportedCommand(cmdGroup, cmdId)) | ||
| { | ||
| if (QueryStatus(selection)) | ||
| { | ||
| cmdf = (uint)(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED); | ||
| } | ||
| else | ||
| { | ||
| cmdf = (uint)OLECMDF.OLECMDF_INVISIBLE; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| private bool IsSupportedCommand(Guid cmdGroup, uint cmdId) | ||
| => cmdGroup == Id.Guid && cmdId == Id.ID; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using Microsoft.VisualStudio.Shell; | ||
| using Microsoft.VisualStudio.Templates.Editorconfig.Command.Commands; | ||
| using Microsoft.VisualStudio.Templates.Editorconfig.Wizard.Logging.Kinds; | ||
| using System; | ||
| using System.Runtime.InteropServices; | ||
| using System.Threading; | ||
| using static Microsoft.VisualStudio.Templates.Editorconfig.Wizard.Logging.Logger; | ||
| using Task = System.Threading.Tasks.Task; | ||
|
|
||
| namespace Microsoft.VisualStudio.Templates.Editorconfig.Command; | ||
|
|
||
| [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] | ||
| [ProvideMenuResource("Menus.ctmenu", 1)] | ||
| [Guid(PackageGuids.AddEditorConfigString)] | ||
| public sealed class EditorconfigCommandPackage : AsyncPackage | ||
| { | ||
| protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress) | ||
| { | ||
| using var _ = LogOperation(OperationId.InitializePackage); | ||
| await CommandBase.InitializeAsync<AddEditorConfigFileCommand>(this); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information.--> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net472</TargetFramework> | ||
| <IsTestProject>false</IsTestProject> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- VSIX Properties --> | ||
| <PropertyGroup> | ||
| <EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems> | ||
| <EnableDefaultItems>true</EnableDefaultItems> | ||
| <ExtensionInstallationFolder>Microsoft\Editorconfig\Command</ExtensionInstallationFolder> | ||
| <ExtensionInstallationRoot>CommonExtensions</ExtensionInstallationRoot> | ||
| <GeneratePkgDefFile>true</GeneratePkgDefFile> | ||
| <IncludeAssemblyInVSIXContainer>true</IncludeAssemblyInVSIXContainer> | ||
| <Ngen>false</Ngen> | ||
| <SetupProductArch>Neutral</SetupProductArch> | ||
| <UseCodebase>true</UseCodebase> | ||
| <VisualStudioInsertionComponent>Templates.Editorconfig.Command</VisualStudioInsertionComponent> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <VSCTCompile Include="VSCommandTable.vsct"> | ||
| <ResourceName>Menus.ctmenu</ResourceName> | ||
| <SubType>Designer</SubType> | ||
| </VSCTCompile> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup Label="PkgDef"> | ||
| <PkgDefPackageRegistration Include="{57a6a527-1255-45c4-bcdb-6a4f50b73b3e}" Name="EditorconfigCommandPackage" Class="Microsoft.VisualStudio.Templates.Editorconfig.Command.EditorconfigCommandPackage" AllowsBackgroundLoad="true" /> | ||
| <None Include="PackageRegistration.pkgdef" PkgDefEntry="FileContent" /> | ||
| <None Include="source.extension.vsixmanifest" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- Project References --> | ||
| <ItemGroup> | ||
| <ProjectReference Include="..\Wizard\Microsoft.VisualStudio.Templates.Editorconfig.Wizard.csproj"> | ||
| <Name>Microsoft.VisualStudio.Templates.Editorconfig.Wizard</Name> | ||
| <IncludeOutputGroupsInVSIX>BuiltProjectOutputGroup;GetCopyToOutputDirectoryItems;SatelliteDllsProjectOutputGroup</IncludeOutputGroupsInVSIX> | ||
| <IncludeOutputGroupsInVSIXLocalOnly>DebugSymbolsProjectOutputGroup%3b</IncludeOutputGroupsInVSIXLocalOnly> | ||
| <ForceIncludeInVSIX>true</ForceIncludeInVSIX> | ||
| </ProjectReference> | ||
| </ItemGroup> | ||
|
|
||
| <!-- Package References --> | ||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.VisualStudio.SDK" /> | ||
| <PackageReference Include="Microsoft.VisualStudio.Workspace.VSIntegration" /> | ||
| <PackageReference Include="Microsoft.VisualStudio.Telemetry" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [$RootKey$\Menus] | ||
| "{57a6a527-1255-45c4-bcdb-6a4f50b73b3e}"=", Menus.ctmenu, 1" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.VisualStudio.Templates.Editorconfig.Command; | ||
|
|
||
| internal sealed partial class PackageGuids | ||
| { | ||
| public const string AddEditorConfigString = "57a6a527-1255-45c4-bcdb-6a4f50b73b3e"; | ||
| public static Guid AddEditorConfig = new Guid(AddEditorConfigString); | ||
| public const string AddEditorConfigCmdSetString = "713dfda7-0c2f-41ee-8326-54895666044a"; | ||
| public static readonly Guid AddEditorConfigCmdSet = new(AddEditorConfigCmdSetString); | ||
| } | ||
|
|
||
| public static class PackageIds | ||
| { | ||
| public const int AddGroup = 0x0001; | ||
| public const int AddGroupAnyCode = 0x0002; | ||
| public const int AddEditorConfigFileCommand = 0x0200; | ||
| public const int AddEditorConfigFileAnyCodeCommand = 0x0201; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary change.