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))
{
if (!definitions.TryGetValue("build", out var buildProperties))
{
// legacy build properties not found !
return [];
}
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)
{
return rootElement
.GetProperty("definitions")
.TryGetProperty(buildPropertyName, out baseSchema);
}

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