Skip to content
Open
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
33 changes: 29 additions & 4 deletions src/Fallout.Build.Shared/CompletionUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ public static IReadOnlyDictionary<string, string[]> GetItemsFromSchema(
var rootElement = schema.RootElement;
var definitions = rootElement.GetProperty("definitions").EnumerateObject().ToDictionary(x => x.Name, x => x);

var parameterProperties = rootElement.GetProperty("definitions").TryGetProperty("FalloutBuild", out var baseSchema)
? baseSchema.GetProperty("properties").EnumerateObject()
.Concat(rootElement.GetProperty("allOf")[0].TryGetProperty("properties", out var properties) ? properties.EnumerateObject() : [])
: definitions["build"].Value.GetProperty("properties").EnumerateObject();
var parameterProperties = GetParameterProperties(rootElement, definitions);

return parameterProperties
.Where(filter)
Expand Down Expand Up @@ -72,6 +69,34 @@ string[] GetValues(JsonProperty property)
}
}

private static IEnumerable<JsonProperty> GetParameterProperties(JsonElement rootElement,
Dictionary<string, JsonProperty> definitions)
{
if (!TryGetSchema(rootElement, "FalloutBuild", out var baseSchema) &&
// Backward compatibility with NukeBuild projects not yet migrated
!TryGetSchema(rootElement, "NukeBuild", out baseSchema))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🔧🤖 The negated TryGetSchema chain with the out baseSchema trick is hard to follow. Pick the first of FalloutBuild/NukeBuild found in definitions, then fall back to build.

{
if (!definitions.TryGetValue("build", out var buildProperties))
{
// legacy build properties not found !
return [];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤔🤖 A missing build definition used to throw KeyNotFoundException and now returns nothing silently. Is that intended? If so, say why; the comment on line 81 doesn't.

}
return buildProperties.Value.GetProperty("properties").EnumerateObject();
}

return baseSchema.GetProperty("properties").EnumerateObject()
.Concat(rootElement.GetProperty("allOf")[0].TryGetProperty("properties", out var properties)
? properties.EnumerateObject()
: []);
}

private static bool TryGetSchema(JsonElement rootElement, string buildPropertyName, out JsonElement baseSchema)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

♻️🤖 TryGetSchema can go: definitions is already a dictionary, so use definitions.TryGetValue(name, out var property).

{
return rootElement
.GetProperty("definitions")
.TryGetProperty(buildPropertyName, out baseSchema);
}

// ReSharper disable once CognitiveComplexity
public static IEnumerable<string> GetRelevantItems(
string words,
Expand Down
Loading