Custom Suggestors
Quantum Console will suggest autocompletions as you type, including commands, macros, enum values and more. You may want to extend this suggestion system by writing a custom suggestor that provides new suggestions.
Any class implementing IQcSuggestor
will automatically be injected into the QuantumSuggestor
and used when getting suggestions
Warning
Since suggestors are injected they may be stripped out when building with managed stripping. To avoid this use see bytecode stripping
Examples
using QFSW.QC;
public class BoolSuggestor : IQcSuggestor
{
public IEnumerable<IQcSuggestion> GetSuggestions(SuggestionContext context, SuggestorOptions options)
{
if (context.TargetType == typeof(bool))
{
yield return new RawSuggestion("true");
yield return new RawSuggestion("false");
}
}
}
Custom Suggestor Tags
By creating custom suggestor tags, you can create custom suggestors that are tailored to more specific, explicit use cases rather than generalizing and inferring from the information in the context.
To create a new tag, you must:
- Create a new type implementing
IQcSuggestorTag
- Create a new attribute deriving from
SuggestorTagAttribute
that returns the tag - Create a custom suggestor that checks for the tag with
HasTag<T>
Examples
The following example adds the [AbilityName]
tag, which when used on command arguments, will cause the abilities from Subsideria to be suggested.
using QFSW.QC;
public struct AbilityNameTag : IQcSuggestorTag
{
}
public sealed class AbilityNameAttribute : SuggestorTagAttribute
{
private readonly IQcSuggestorTag[] _tags = { new AbilityNameTag() };
public override IQcSuggestorTag[] GetSuggestorTags()
{
return _tags;
}
}
public class AbilityNameSuggestor : BasicCachedQcSuggestor<string>
{
protected override bool CanProvideSuggestions(SuggestionContext context, SuggestorOptions options)
{
return context.HasTag<AbilityNameTag>();
}
protected override IQcSuggestion ItemToSuggestion(string abilityName)
{
return new RawSuggestion(abilityName, true);
}
protected override IEnumerable<string> GetItems(SuggestionContext context, SuggestorOptions options)
{
return new string[]
{
"Ion Thrusters",
"Detonate",
"Chronostatis",
"Quantum Dampeners",
"Singularity Cannon",
};
}
}