diff --git a/Src/CSharpier.VisualStudio/CSharpier.VisualStudio/source.extension.vsixmanifest b/Src/CSharpier.VisualStudio/CSharpier.VisualStudio/source.extension.vsixmanifest index 2dcc6c075..e009f8cad 100644 --- a/Src/CSharpier.VisualStudio/CSharpier.VisualStudio/source.extension.vsixmanifest +++ b/Src/CSharpier.VisualStudio/CSharpier.VisualStudio/source.extension.vsixmanifest @@ -1,7 +1,7 @@ - + CSharpier CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules. https://github.com/belav/csharpier diff --git a/Src/CSharpier.VisualStudio/CSharpier.VisualStudio2019/source.extension.vsixmanifest b/Src/CSharpier.VisualStudio/CSharpier.VisualStudio2019/source.extension.vsixmanifest index 85c27791c..491059e65 100644 --- a/Src/CSharpier.VisualStudio/CSharpier.VisualStudio2019/source.extension.vsixmanifest +++ b/Src/CSharpier.VisualStudio/CSharpier.VisualStudio2019/source.extension.vsixmanifest @@ -1,7 +1,7 @@ - + CSharpier 2019 CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules. https://github.com/belav/csharpier diff --git a/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierPackage.cs b/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierPackage.cs index aa0217065..0dad5ca30 100644 --- a/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierPackage.cs +++ b/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierPackage.cs @@ -35,23 +35,6 @@ IProgress progress await ReformatWithCSharpier.InitializeAsync(this); await InstallerService.InitializeAsync(this); - try - { -#pragma warning disable VSSDK006 - var dte = await this.GetServiceAsync(typeof(DTE)) as DTE; -#pragma warning restore - if (dte?.ActiveDocument != null) - { - CSharpierProcessProvider - .GetInstance(this) - .FindAndWarmProcess(dte.ActiveDocument.FullName); - } - } - catch (Exception ex) - { - Logger.Instance.Error(ex); - } - SolutionEvents.OnAfterOpenSolution += this.HandleOpenSolution; } diff --git a/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierProcessProvider.cs b/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierProcessProvider.cs index 4df85a009..1e2eb08ef 100644 --- a/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierProcessProvider.cs +++ b/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierProcessProvider.cs @@ -69,6 +69,12 @@ public void FindAndWarmProcess(string filePath) this.warmingByDirectory.Remove(directory); } + public bool HasWarmedProcessFor(string filePath) + { + var directory = new FileInfo(filePath).DirectoryName; + return this.csharpierVersionByDirectory.TryGetValue(directory, out _); + } + public ICSharpierProcess GetProcessFor(string filePath) { var directory = new FileInfo(filePath).DirectoryName; diff --git a/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/ReformatWithCSharpier.cs b/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/ReformatWithCSharpier.cs index 5b6f884cd..b6baf25aa 100644 --- a/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/ReformatWithCSharpier.cs +++ b/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/ReformatWithCSharpier.cs @@ -14,13 +14,12 @@ internal sealed class ReformatWithCSharpier private readonly DTE dte; private readonly FormattingService formattingService; + private readonly CSharpierProcessProvider cSharpierProcessProvider; public static ReformatWithCSharpier Instance { get; private set; } = default!; public static async Task InitializeAsync(CSharpierPackage package) { - await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken); - var commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; @@ -42,6 +41,7 @@ DTE dte menuItem.BeforeQueryStatus += this.QueryStatus; commandService.AddCommand(menuItem); this.formattingService = FormattingService.GetInstance(package); + this.cSharpierProcessProvider = CSharpierProcessProvider.GetInstance(package); } private void QueryStatus(object sender, EventArgs e) @@ -49,10 +49,22 @@ private void QueryStatus(object sender, EventArgs e) ThreadHelper.ThrowIfNotOnUIThread(); var button = (OleMenuCommand)sender; - button.Visible = this.dte.ActiveDocument.Name.EndsWith(".cs"); - button.Enabled = this.formattingService.ProcessSupportsFormatting( - this.dte.ActiveDocument + var hasWarmedProcess = this.cSharpierProcessProvider.HasWarmedProcessFor( + this.dte.ActiveDocument.FullName ); + button.Visible = this.dte.ActiveDocument.Name.EndsWith(".cs"); + + if (!hasWarmedProcess) + { + // default to assuming they can format, that way if they do format we can start everything up properly + button.Enabled = true; + } + else + { + button.Enabled = this.formattingService.ProcessSupportsFormatting( + this.dte.ActiveDocument + ); + } } private void Execute(object sender, EventArgs e) diff --git a/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/ReformatWithCSharpierOnSave.cs b/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/ReformatWithCSharpierOnSave.cs index e30e6cbfc..9a434aa6a 100644 --- a/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/ReformatWithCSharpierOnSave.cs +++ b/Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/ReformatWithCSharpierOnSave.cs @@ -76,6 +76,8 @@ public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowF var documentInfo = this.runningDocumentTable.GetDocumentInfo(docCookie); var documentPath = documentInfo.Moniker; + Logger.Instance.Debug("Trying to find - " + documentPath); + return this.dte.ActiveDocument?.FullName == documentPath ? this.dte.ActiveDocument : this.dte.Documents?.Item(documentPath); diff --git a/Src/CSharpier.VisualStudio/ChangeLog.md b/Src/CSharpier.VisualStudio/ChangeLog.md index 70c66208b..65d318b93 100644 --- a/Src/CSharpier.VisualStudio/ChangeLog.md +++ b/Src/CSharpier.VisualStudio/ChangeLog.md @@ -1,4 +1,7 @@ -## [1.9.1] +## [1.9.3] +- Remove eagerly warming csharpier at startup. Optimize right click menu so it doesn't have noticeable delay on initial file that is open at startup. + +## [1.9.1] - Fix bug if you open CSharpier options page without a solution loaded in VisualStudio ## [1.9.0]