-
Notifications
You must be signed in to change notification settings - Fork 747
[NSJ -> STJ]Migrate AutoComplete #7298
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
base: dev-feature-nsj-stj-migration
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace NuGet.Protocol.Model | ||
| { | ||
| internal sealed class AutoCompleteModel | ||
| { | ||
| [JsonPropertyName("data")] | ||
| public string[]? Data { get; set; } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,12 @@ | |
| using System.Globalization; | ||
| using System.Linq; | ||
| using System.Net; | ||
| using System.Text.Json; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Newtonsoft.Json.Linq; | ||
| using NuGet.Protocol.Core.Types; | ||
| using NuGet.Protocol.Model; | ||
| using NuGet.Protocol.Utility; | ||
| using NuGet.Versioning; | ||
|
|
||
| namespace NuGet.Protocol | ||
|
|
@@ -55,32 +57,29 @@ public override async Task<IEnumerable<string>> IdStartsWith( | |
| Common.ILogger logger = log ?? Common.NullLogger.Instance; | ||
|
|
||
| var queryUri = queryUrl.Uri; | ||
| var results = await _client.GetJObjectAsync( | ||
| AutoCompleteModel results = await _client.ProcessStreamAsync( | ||
| new HttpSourceRequest(queryUri, logger), | ||
| async stream => | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what the team code style is, if they link lamdas defined ahead of the method call or within it. |
||
| { | ||
| if (stream == null) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| return await JsonSerializer.DeserializeAsync(stream, JsonContext.Default.AutoCompleteModel, token); | ||
| }, | ||
| logger, | ||
| token); | ||
|
|
||
| token.ThrowIfCancellationRequested(); | ||
| if (results == null) | ||
| { | ||
| return Enumerable.Empty<string>(); | ||
| } | ||
| var data = results.Value<JArray>("data"); | ||
| if (data == null) | ||
| { | ||
| return Enumerable.Empty<string>(); | ||
| } | ||
|
|
||
| // Resolve all the objects | ||
| var outputs = new List<string>(); | ||
| foreach (var result in data) | ||
| if (results?.Data == null) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could adopt the null-coalescing syntax: var returnValue = results?.Data.Where(item => item != null && item.StartsWith(packageIdPrefix, StringComparison.OrdinalIgnoreCase));
return returnValue ?? Enumerable.Empty<string>();Or some variant of that. |
||
| { | ||
| if (result != null) | ||
| { | ||
| outputs.Add(result.ToString()); | ||
| } | ||
| return Enumerable.Empty<string>(); | ||
| } | ||
|
|
||
| return outputs.Where(item => item.StartsWith(packageIdPrefix, StringComparison.OrdinalIgnoreCase)); | ||
| return results.Data | ||
| .Where(item => item != null && item.StartsWith(packageIdPrefix, StringComparison.OrdinalIgnoreCase)); | ||
| } | ||
|
|
||
| public override async Task<IEnumerable<NuGetVersion>> VersionStartsWith( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am surprised that
AutoCompleteModelis always non-null. Is that correct?Does this library not have nullable enabled?