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

Address additional restore changes feedback #70633

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -35,7 +35,7 @@ public DotnetCliHelper(ILoggerFactory loggerFactory)
/// </summary>
private async Task<string> GetDotnetSdkFolderFromDotnetExecutableAsync(string projectOutputDirectory, CancellationToken cancellationToken)
{
using var process = Run("--info", workingDirectory: projectOutputDirectory, shouldLocalizeOutput: false);
using var process = Run(["--info"], workingDirectory: projectOutputDirectory, shouldLocalizeOutput: false);

string? dotnetSdkFolderPath = null;
process.OutputDataReceived += (_, e) =>
Expand Down Expand Up @@ -68,18 +68,20 @@ private async Task<string> GetDotnetSdkFolderFromDotnetExecutableAsync(string pr
return dotnetSdkFolderPath;
}

public Process Run(string arguments, string? workingDirectory, bool shouldLocalizeOutput)
public Process Run(string[] arguments, string? workingDirectory, bool shouldLocalizeOutput)
{
_logger.LogDebug($"Running dotnet CLI command at {_dotnetExecutablePath.Value} in directory {workingDirectory} with arguments {arguments}");

var startInfo = new ProcessStartInfo(_dotnetExecutablePath.Value, arguments)
var startInfo = new ProcessStartInfo(_dotnetExecutablePath.Value)
{
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
RedirectStandardError = true,
};

startInfo.ArgumentList.AddRange(arguments);

if (workingDirectory != null)
{
startInfo.WorkingDirectory = workingDirectory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,20 @@ public Task<string[]> HandleRequestAsync(RequestContext context, CancellationTok
{
Contract.ThrowIfNull(context.Solution);

using var _ = ArrayBuilder<string>.GetInstance(out var projectsBuilder);
// We use a sorted set here for the following reasons
// 1. Ensures the client gets a consistent ordering in the picker (especially useful for integration tests).
// 2. Removes projects with duplicate file paths (for example multi-targeted projects). They all get restored
// together by file path.
var projects = new SortedSet<string>();
foreach (var project in context.Solution.Projects)
{
// To restore via the dotnet CLI, we must have a file path and it must be a .NET core project.
if (project.FilePath != null && projectTargetFrameworkManager.IsDotnetCoreProject(project.Id))
{
projectsBuilder.Add(project.FilePath);
projects.Add(project.FilePath);
}
}

// We may have multiple projects with the same file path in multi-targeting scenarios.
// They'll all get restored together so we only want one result per project file.
projectsBuilder.RemoveDuplicates();

// Ensure the client gets a consistent ordering.
projectsBuilder.Sort(StringComparer.OrdinalIgnoreCase);

return Task.FromResult(projectsBuilder.ToArray());
return Task.FromResult(projects.ToArray());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,18 @@ private async Task RestoreAsync(ImmutableArray<string> pathsToRestore, BufferedP
{
foreach (var path in pathsToRestore)
{
var arguments = $"restore \"{path}\"";
var arguments = new string[] { "restore", path };
Copy link
Member

Choose a reason for hiding this comment

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

Didn't want to inline with collection expressions here?

Copy link
Member Author

Choose a reason for hiding this comment

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

There appear to be a bunch of formatting issues with collection expressions. Every time I try to use them I get formatting warnings (even with 'correct' formatting). I'll file a bug on that one sec.

var workingDirectory = Path.GetDirectoryName(path);
var stageName = string.Format(LanguageServerResources.Restoring_0, Path.GetFileName(path));
ReportProgress(progress, stageName, string.Format(LanguageServerResources.Running_dotnet_restore_on_0, path));

var process = dotnetCliHelper.Run(arguments, workingDirectory, shouldLocalizeOutput: true);

cancellationToken.Register(() =>
{
process?.Kill();
});

process.OutputDataReceived += (sender, args) => ReportProgress(progress, stageName, args.Data);
process.ErrorDataReceived += (sender, args) => ReportProgress(progress, stageName, args.Data);
process.BeginOutputReadLine();
Expand All @@ -65,7 +70,7 @@ private async Task RestoreAsync(ImmutableArray<string> pathsToRestore, BufferedP

if (process.ExitCode != 0)
{
throw new InvalidOperationException(LanguageServerResources.Failed_to_run_restore_see_output_for_details);
ReportProgress(progress, stageName, string.Format(LanguageServerResources.Failed_to_run_restore_on_0, path));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@
<data name="Failed_to_read_runsettings_file_at_0:1" xml:space="preserve">
<value>Failed to read .runsettings file at {0}:{1}</value>
</data>
<data name="Failed_to_run_restore_see_output_for_details" xml:space="preserve">
<value>Failed to run restore, see output for details</value>
<data name="Failed_to_run_restore_on_0" xml:space="preserve">
<value>Failed to run restore on {0}</value>
</data>
<data name="Found_0_tests_in_1" xml:space="preserve">
<value>Found {0} tests in {1}</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ private async Task BuildAsync(Document document, BufferedProgress<RunTestsPartia

// TODO - we likely need to pass the no-restore flag once we have automatic restore enabled.
// https://github.com/dotnet/vscode-csharp/issues/5725
var arguments = $"build {projectFileName}";
using var process = dotnetCliHelper.Run(arguments, workingDirectory, shouldLocalizeOutput: true);
using var process = dotnetCliHelper.Run(["build", projectFileName], workingDirectory, shouldLocalizeOutput: true);

process.OutputDataReceived += (sender, args) => ReportProgress(progress, args.Data);

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.