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.

references #1182
  • Loading branch information
belav committed Dec 21, 2024
1 parent 5cf6488 commit c7e1545
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
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

0 comments on commit c7e1545

Please sign in to comment.