|
| 1 | +using LanguageServer.Json; |
| 2 | + |
| 3 | +namespace LanguageServer.Parameters.General |
| 4 | +{ |
| 5 | + /// <summary> |
| 6 | + /// For <c>initialize</c> |
| 7 | + /// </summary> |
| 8 | + /// <remarks> |
| 9 | + /// The original spec describes the union type of <c>boolean</c> or the intersection type |
| 10 | + /// <c>(TextDocumentRegistrationOptions & StaticRegistrationOptions)</c>. |
| 11 | + /// This implementation defines <see cref="ProviderOptions"/> class instead of the intersection type. |
| 12 | + /// </remarks> |
| 13 | + /// <seealso>Spec 3.6.0</seealso> |
| 14 | + public class ProviderOptionsOrBoolean : Either |
| 15 | + { |
| 16 | + /// <summary> |
| 17 | + /// Defines an implicit conversion of a <see cref="ProviderOptions"/> to a <see cref="ProviderOptionsOrBoolean"/> |
| 18 | + /// </summary> |
| 19 | + /// <param name="value"></param> |
| 20 | + /// <seealso>Spec 3.6.0</seealso> |
| 21 | + public static implicit operator ProviderOptionsOrBoolean(ProviderOptions value) |
| 22 | + => new ProviderOptionsOrBoolean(value); |
| 23 | + |
| 24 | + /// <summary> |
| 25 | + /// Defines an implicit conversion of a <see cref="bool"/> to a <see cref="ProviderOptionsOrBoolean"/> |
| 26 | + /// </summary> |
| 27 | + /// <param name="value"></param> |
| 28 | + /// <seealso>Spec 3.6.0</seealso> |
| 29 | + public static implicit operator ProviderOptionsOrBoolean(bool value) |
| 30 | + => new ProviderOptionsOrBoolean(value); |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// Initializes a new instance of <c>ProviderOptionsOrBoolean</c> with the specified value. |
| 34 | + /// </summary> |
| 35 | + /// <param name="value"></param> |
| 36 | + /// <seealso>Spec 3.6.0</seealso> |
| 37 | + public ProviderOptionsOrBoolean(ProviderOptions value) |
| 38 | + { |
| 39 | + Type = typeof(ProviderOptions); |
| 40 | + Value = value; |
| 41 | + } |
| 42 | + |
| 43 | + /// <summary> |
| 44 | + /// Initializes a new instance of <c>ProviderOptionsOrBoolean</c> with the specified value. |
| 45 | + /// </summary> |
| 46 | + /// <param name="value"></param> |
| 47 | + /// <seealso>Spec 3.6.0</seealso> |
| 48 | + public ProviderOptionsOrBoolean(bool value) |
| 49 | + { |
| 50 | + Type = typeof(bool); |
| 51 | + Value = value; |
| 52 | + } |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// Returns true if its underlying value is a <see cref="ProviderOptions"/>. |
| 56 | + /// </summary> |
| 57 | + /// <seealso>Spec 3.6.0</seealso> |
| 58 | + public bool IsProviderOptions => Type == typeof(ProviderOptions); |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// Returns true if its underlying value is a <see cref="bool"/>. |
| 62 | + /// </summary> |
| 63 | + /// <seealso>Spec 3.6.0</seealso> |
| 64 | + public bool IsBoolean => Type == typeof(bool); |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Gets the value of the current object if its underlying value is a <see cref="ProviderOptions"/>. |
| 68 | + /// </summary> |
| 69 | + /// <seealso>Spec 3.6.0</seealso> |
| 70 | + public ProviderOptions ProviderOptions => GetValue<ProviderOptions>(); |
| 71 | + |
| 72 | + /// <summary> |
| 73 | + /// Gets the value of the current object if its underlying value is a <see cref="bool"/>. |
| 74 | + /// </summary> |
| 75 | + /// <seealso>Spec 3.6.0</seealso> |
| 76 | + public bool Boolean => GetValue<bool>(); |
| 77 | + } |
| 78 | +} |
0 commit comments