Skip to content
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

Fix long commands breaking component debugger: #922

Merged
merged 2 commits into from
Dec 10, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -22,7 +23,7 @@ namespace Roslyn.ComponentDebugger
{
[Export(typeof(IDebugProfileLaunchTargetsProvider))]
[AppliesTo(Constants.RoslynComponentCapability)]
public class DebugProfileProvider : IDebugProfileLaunchTargetsProvider
public sealed class DebugProfileProvider : IDebugProfileLaunchTargetsProvider, IDisposable
{
private readonly ConfiguredProject _configuredProject;
private readonly LaunchSettingsManager _launchSettingsManager;
Expand Down Expand Up @@ -69,15 +70,27 @@ public async Task<IReadOnlyList<IDebugLaunchSettings>> QueryDebugTargetsAsync(De

// get its compilation args
var args = await targetProjectUnconfigured.GetCompilationArgumentsAsync().ConfigureAwait(true);
args = args.Remove("/noconfig");

// append the command line args to the debugger launch
settings.Arguments = string.Join(" ", args);
// write the command line args out to a response file
var file = GetResponseFileName();
File.WriteAllText(file, string.Join(" ", args));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this could throw, but for now I'm just letting VS handle it which gives the following experience:
image

We have #728 to track handling errors in a more thoughtful way.


// pass the response file as the argument to the launch command
settings.Arguments = $"@\"{file}\"";
}
}
// https://github.com/dotnet/roslyn-sdk/issues/728 : better error handling
return new IDebugLaunchSettings[] { settings };
}

private static string GetResponseFileName()
{
// prefix with the VS PID so we don't stomp on another instance
var pid = Process.GetCurrentProcess().Id;
return Path.Combine(Path.GetTempPath(), $"{Constants.CommandName}_{pid}.txt");
}

private async Task<string?> GetCompilerRootAsync(SVsServiceProvider? serviceProvider)
{
await _threadingService.SwitchToUIThread();
Expand All @@ -93,5 +106,22 @@ public async Task<IReadOnlyList<IDebugLaunchSettings>> QueryDebugTargetsAsync(De

return null;
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA1031:Do not catch general exception types", Justification = "Best effort only.")]
public void Dispose()
{
try
{
var responseFile = GetResponseFileName();
if (File.Exists(responseFile))
{
File.Delete(responseFile);
}
}
catch
{
// best effort, do nothing if we can't remove it for whatever reason
}
}
}
}