Skip to content

Commit

Permalink
Avoid eagerly warming csharpier, doesn't seem to be a good way to del…
Browse files Browse the repository at this point in the history
…ay that and it is possibly slowing down VS startup. (#1411)

references #1182
  • Loading branch information
belav committed Dec 21, 2024
1 parent 5cf6488 commit 6d285fe
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="83d6b6a0-9e25-4034-80f3-38445d8a8837" Version="1.9.1" Language="en-US" Publisher="CSharpier" />
<Identity Id="83d6b6a0-9e25-4034-80f3-38445d8a8837" Version="1.9.3" Language="en-US" Publisher="CSharpier" />
<DisplayName>CSharpier</DisplayName>
<Description xml:space="preserve">CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules.</Description>
<MoreInfo>https://github.com/belav/csharpier</MoreInfo>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="edd8b38c-baa1-46c6-b82e-1da7a0ba597b" Version="1.9.1" Language="en-US" Publisher="CSharpier" />
<Identity Id="edd8b38c-baa1-46c6-b82e-1da7a0ba597b" Version="1.9.3" Language="en-US" Publisher="CSharpier" />
<DisplayName>CSharpier 2019</DisplayName>
<Description xml:space="preserve">CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules.</Description>
<MoreInfo>https://github.com/belav/csharpier</MoreInfo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,6 @@ IProgress<ServiceProgressData> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -42,17 +41,30 @@ 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)
{
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion Src/CSharpier.VisualStudio/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down

0 comments on commit 6d285fe

Please sign in to comment.