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

Fixed some things the palettes implementation missed #29

Merged
merged 2 commits into from
Oct 22, 2022
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 @@ -34,7 +34,7 @@ public class TextDocumentCompletionHandler : BaseRpcMessageHandler
CommitCharacters = new[] { ":" }
};

readonly CompletionItem defaultsCompletionItem = new()
readonly CompletionItem defaultsCompletionItem = new ()
{
Label = "Defaults",
Kind = CompletionItemKind.Constructor,
Expand Down Expand Up @@ -262,7 +262,6 @@ protected override IEnumerable<CompletionItem> HandleRulesValue(CursorTarget cur
var tempWeaponNames = weaponNames;
var tempConditionNames = conditionNames;
var tempCursorNames = cursorNames;
var tempPaletteNames = paletteNames;

MapManifest mapManifest = default;
if (cursorTarget.FileType == FileType.MapRules)
Expand All @@ -276,7 +275,7 @@ protected override IEnumerable<CompletionItem> HandleRulesValue(CursorTarget cur
tempActorNames = tempActorNames.Union(mapSymbols.ActorDefinitions.Select(x => x.First().ToCompletionItem()));
tempWeaponNames = tempWeaponNames.Union(mapSymbols.WeaponDefinitions.Select(x => x.First().ToCompletionItem()));
tempConditionNames = tempConditionNames.Union(mapSymbols.ConditionDefinitions.Select(x => x.First().ToCompletionItem()));
tempPaletteNames = tempPaletteNames.Union(mapSymbols.PaletteDefinitions.Select(x => x.First().ToCompletionItem()));
paletteNames = paletteNames.Union(mapSymbols.PaletteDefinitions.Select(x => x.First().ToCompletionItem()));
spriteSequenceImageNames = spriteSequenceImageNames.Union(
mapSymbols.SpriteSequenceImageDefinitions.Select(x => x.First().ToCompletionItem()));
}
Expand All @@ -298,7 +297,7 @@ protected override IEnumerable<CompletionItem> HandleRulesValue(CursorTarget cur
return tempCursorNames;

if (fieldInfo.OtherAttributes.Any(x => x.Name == "PaletteReference"))
return tempPaletteNames.Where(x => !string.IsNullOrEmpty(x.Label));
return paletteNames.Where(x => !string.IsNullOrEmpty(x.Label));

// Pretend there is such a thing as a "SequenceImageReferenceAttribute" until we add it in OpenRA one day.
// NOTE: This will improve if/when we add the attribute.
Expand Down Expand Up @@ -431,11 +430,15 @@ protected override IEnumerable<CompletionItem> HandleWeaponValue(CursorTarget cu

if (mapManifest.MapReference != null && symbolCache.Maps.TryGetValue(mapManifest.MapReference, out var mapSymbols))
{
paletteNames = paletteNames.Union(mapSymbols.PaletteDefinitions.Select(x => x.First().ToCompletionItem()));
spriteSequenceImageNames = spriteSequenceImageNames.Union(
mapSymbols.SpriteSequenceImageDefinitions.Select(x => x.First().ToCompletionItem()));
}
}

if (fieldInfo.OtherAttributes.Any(x => x.Name == "PaletteReference"))
return paletteNames.Where(x => !string.IsNullOrEmpty(x.Label));

// Pretend there is such a thing as a "SequenceImageReferenceAttribute" until we add it in OpenRA one day.
// NOTE: This will improve if/when we add the attribute.
if (fieldInfos.Any(x => x.OtherAttributes.Any(y => y.Name == "SequenceReference"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ protected override IEnumerable<Location> HandleRulesValue(CursorTarget cursorTar
actorDefinitions = actorDefinitions.Union(mapSymbols.ActorDefinitions[cursorTarget.TargetString]);
weaponDefinitions = weaponDefinitions.Union(mapSymbols.WeaponDefinitions[cursorTarget.TargetString]);
conditionDefinitions = conditionDefinitions.Union(mapSymbols.ConditionDefinitions[cursorTarget.TargetString]);
paletteDefinitions = paletteDefinitions.Union(mapSymbols.PaletteDefinitions[cursorTarget.TargetString]);

spriteSequenceImageDefinitions = spriteSequenceImageDefinitions
.SelectMany(x => x)
Expand Down Expand Up @@ -333,6 +334,7 @@ protected override IEnumerable<Location> HandleWeaponValue(CursorTarget cursorTa
}
}

var paletteDefinitions = modSymbols.PaletteDefinitions[cursorTarget.TargetString];
var spriteSequenceImageDefinitions = symbolCache[cursorTarget.ModId].ModSymbols.SpriteSequenceImageDefinitions;

MapManifest mapManifest = default;
Expand All @@ -344,13 +346,17 @@ protected override IEnumerable<Location> HandleWeaponValue(CursorTarget cursorTa
if (mapManifest.MapReference != null && symbolCache.Maps.TryGetValue(mapManifest.MapReference, out var mapSymbols))
{
// Merge mod symbols with map symbols.
paletteDefinitions = paletteDefinitions.Union(mapSymbols.PaletteDefinitions[cursorTarget.TargetString]);
spriteSequenceImageDefinitions = spriteSequenceImageDefinitions
.SelectMany(x => x)
.Union(mapSymbols.SpriteSequenceImageDefinitions.SelectMany(x => x))
.ToLookup(x => x.Name, y => y);
}
}

if (fieldInfo.OtherAttributes.Any(x => x.Name == "PaletteReference"))
return paletteDefinitions.Select(x => x.Location.ToLspLocation(x.Type.Length));

// Pretend there is such a thing as a "SequenceImageReferenceAttribute" until we add it in OpenRA one day.
// NOTE: This will improve if/when we add the attribute.
if (fieldInfos.Any(x => x.OtherAttributes.Any(y => y.Name == "SequenceReference"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ protected override Hover HandleRulesValue(CursorTarget cursorTarget)
var weaponDefinitions = modSymbols.WeaponDefinitions.Select(x => x.Key);
var conditionDefinitions = modSymbols.ConditionDefinitions.Select(x => x.Key);
var cursorDefinitions = modSymbols.CursorDefinitions.Select(x => x.Key);
var paletteDefinitions = modSymbols.PaletteDefinitions.Select(x => x.Key);
var paletteDefinitions = modSymbols.PaletteDefinitions;
var spriteSequenceImageDefinitions = modSymbols.SpriteSequenceImageDefinitions;

MapManifest mapManifest = default;
Expand All @@ -195,6 +195,12 @@ protected override Hover HandleRulesValue(CursorTarget cursorTarget)
actorDefinitions = actorDefinitions.Union(mapSymbols.ActorDefinitions.Select(x => x.Key));
weaponDefinitions = weaponDefinitions.Union(mapSymbols.WeaponDefinitions.Select(x => x.Key));
conditionDefinitions = conditionDefinitions.Union(mapSymbols.ConditionDefinitions.Select(x => x.Key));

// Merge mod symbols with map symbols.
paletteDefinitions = paletteDefinitions
.SelectMany(x => x)
.Union(mapSymbols.PaletteDefinitions.SelectMany(x => x))
.ToLookup(x => x.Name, y => y);
spriteSequenceImageDefinitions = spriteSequenceImageDefinitions
.SelectMany(x => x)
.Union(mapSymbols.SpriteSequenceImageDefinitions.SelectMany(x => x))
Expand Down Expand Up @@ -223,7 +229,7 @@ protected override Hover HandleRulesValue(CursorTarget cursorTarget)

if (fieldInfo.OtherAttributes.Any(x => x.Name == "PaletteReference") && paletteDefinitions.Contains(cursorTarget.TargetString))
{
var palette = modSymbols.PaletteDefinitions[cursorTarget.TargetString].First();
var palette = paletteDefinitions[cursorTarget.TargetString].First();
return HoverFromHoverInfo(palette.ToMarkdownInfoString(), range);
}

Expand Down Expand Up @@ -444,6 +450,7 @@ protected override Hover HandleWeaponValue(CursorTarget cursorTarget)
}
}

var paletteDefinitions = modSymbols.PaletteDefinitions;
var spriteSequenceImageDefinitions = modSymbols.SpriteSequenceImageDefinitions;

MapManifest mapManifest = default;
Expand All @@ -455,13 +462,23 @@ protected override Hover HandleWeaponValue(CursorTarget cursorTarget)
if (mapManifest.MapReference != null && symbolCache.Maps.TryGetValue(mapManifest.MapReference, out var mapSymbols))
{
// Merge mod symbols with map symbols.
paletteDefinitions = paletteDefinitions
.SelectMany(x => x)
.Union(mapSymbols.PaletteDefinitions.SelectMany(x => x))
.ToLookup(x => x.Name, y => y);
spriteSequenceImageDefinitions = spriteSequenceImageDefinitions
.SelectMany(x => x)
.Union(mapSymbols.SpriteSequenceImageDefinitions.SelectMany(x => x))
.ToLookup(x => x.Name, y => y);
}
}

if (fieldInfo.OtherAttributes.Any(x => x.Name == "PaletteReference") && paletteDefinitions.Contains(cursorTarget.TargetString))
{
var palette = paletteDefinitions[cursorTarget.TargetString].First();
return HoverFromHoverInfo(palette.ToMarkdownInfoString(), range);
}

// Pretend there is such a thing as a "SequenceImageReferenceAttribute" until we add it in OpenRA one day.
// NOTE: This will improve if/when we add the attribute.
if (fieldInfos.Any(x => x.OtherAttributes.Any(y => y.Name == "SequenceReference"
Expand Down