From c89a4adadd105dbe78ea4466cf1c61ff8b6f78ae Mon Sep 17 00:00:00 2001 From: SynesthesiaDev_ Date: Fri, 21 Aug 2026 13:00:23 +0200 Subject: [PATCH] Fix `.optional()` returning first item of enum instead of null --- .gitignore | 6 +- Codon.BinaryCodec/BinaryCodecDefinitions.cs | 2 +- Codon.BinaryCodec/BinaryCodecs.cs | 18 +- Codon.Codec/Codecs.cs | 2 +- Codon.Codec/Extensions.cs | 8 +- Codon.Optionals/Extensions.cs | 22 ++ Codon.Optionals/Optional.cs | 52 ++-- .../.idea.CodonPlugin.sln/.idea/.gitignore | 13 + .../.idea/.idea.CodonPlugin.sln/.idea/.name | 1 + .../.idea.CodonPlugin.sln/.idea/discord.xml | 14 + .../.idea.CodonPlugin.sln/.idea/encodings.xml | 4 + .../.idea/indexLayout.xml | 8 + .../.idea/.idea.CodonPlugin.sln/.idea/vcs.xml | 6 + .../.idea/.idea.CodonPlugin/.idea/.gitignore | 13 + .../.idea/.idea.CodonPlugin/.idea/.name | 1 + .../.idea/.idea.CodonPlugin/.idea/discord.xml | 14 + .../.idea.CodonPlugin/.idea/encodings.xml | 4 + .../.idea.CodonPlugin/.idea/indexLayout.xml | 8 + .../.idea/.idea.CodonPlugin/.idea/vcs.xml | 6 + Codon.Plugin/.idea/dictionaries/project.xml | 7 + .../Model/RdCodonPluginModel.Generated.cs | 294 ++++++++++++++++++ Codon.Plugin/src/dotnet/nuget.config | 8 + .../RdCodonPluginModel.Generated.kt | 219 +++++++++++++ Codon.Tests/BinaryCodecsTests.cs | 4 +- Codon.Tests/CodecTests.cs | 2 +- Codon.Tests/EdgeCasesTests.cs | 17 +- Codon.Tests/OptionalAndDefaultCodecTests.cs | 2 +- Codon.Tests/VersionCodecTests.cs | 2 +- 28 files changed, 705 insertions(+), 52 deletions(-) create mode 100644 Codon.Optionals/Extensions.cs create mode 100644 Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/.gitignore create mode 100644 Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/.name create mode 100644 Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/discord.xml create mode 100644 Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/encodings.xml create mode 100644 Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/indexLayout.xml create mode 100644 Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/vcs.xml create mode 100644 Codon.Plugin/.idea/.idea.CodonPlugin/.idea/.gitignore create mode 100644 Codon.Plugin/.idea/.idea.CodonPlugin/.idea/.name create mode 100644 Codon.Plugin/.idea/.idea.CodonPlugin/.idea/discord.xml create mode 100644 Codon.Plugin/.idea/.idea.CodonPlugin/.idea/encodings.xml create mode 100644 Codon.Plugin/.idea/.idea.CodonPlugin/.idea/indexLayout.xml create mode 100644 Codon.Plugin/.idea/.idea.CodonPlugin/.idea/vcs.xml create mode 100644 Codon.Plugin/.idea/dictionaries/project.xml create mode 100644 Codon.Plugin/src/dotnet/Rider.Plugins.CodonPlugin/Model/RdCodonPluginModel.Generated.cs create mode 100644 Codon.Plugin/src/dotnet/nuget.config create mode 100644 Codon.Plugin/src/rider/generated/kotlin/com/jetbrains/rider/plugins/codonplugin/RdCodonPluginModel.Generated.kt diff --git a/.gitignore b/.gitignore index 35063fc..7a26c89 100644 --- a/.gitignore +++ b/.gitignore @@ -51,4 +51,8 @@ CodeCoverage/ # NUnit *.VisualState.xml TestResult.xml -nunit-*.xml \ No newline at end of file +nunit-*.xml +Codon.Plugin/.gradle +Codon.Plugin/.intellijPlatform +Codon.Plugin/build +Codon.Plugin/protocol/build diff --git a/Codon.BinaryCodec/BinaryCodecDefinitions.cs b/Codon.BinaryCodec/BinaryCodecDefinitions.cs index 4feb696..e79bdd9 100644 --- a/Codon.BinaryCodec/BinaryCodecDefinitions.cs +++ b/Codon.BinaryCodec/BinaryCodecDefinitions.cs @@ -267,7 +267,7 @@ public void Write(IByteBuffer buffer, Optional value) public Optional Read(IByteBuffer buffer) { - return BinaryCodecs.BOOLEAN.Read(buffer) ? Optional.Of(innerCodec.Read(buffer)) : Optional.Empty(); + return BinaryCodecs.BOOLEAN.Read(buffer) ? Optional.Of(innerCodec.Read(buffer)) : Optional.Empty(); } } diff --git a/Codon.BinaryCodec/BinaryCodecs.cs b/Codon.BinaryCodec/BinaryCodecs.cs index 77fee44..17f53a8 100644 --- a/Codon.BinaryCodec/BinaryCodecs.cs +++ b/Codon.BinaryCodec/BinaryCodecs.cs @@ -2,7 +2,9 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; using System.Runtime.CompilerServices; +using Codon.Optionals; using DotNetty.Buffers; #pragma warning disable CS8714 // The type cannot be used as type parameter in the generic type or method. Nullability of type argument doesn't match 'notnull' constraint. @@ -39,13 +41,13 @@ public static class BinaryCodecs public static readonly IBinaryCodec GUID = BYTE_ARRAY.Transform(guid => guid.ToByteArray(), bytes => new Guid(bytes)); - public static BinaryCodecDefinitions.RecursiveBinaryCodec Recursive(Func, IBinaryCodec> self) where T : notnull => new(self); + public static IBinaryCodec Recursive(Func, IBinaryCodec> self) where T : notnull => new BinaryCodecDefinitions.RecursiveBinaryCodec(self); public static IBinaryCodec ByteArray(int? maxSize = null) => new BinaryCodecDefinitions.ByteArrayBinaryCodec(maxSize); public static IBinaryCodec ByteBuffer(int? maxSize = null) => new BinaryCodecDefinitions.ByteBufferBinaryCodec(maxSize); - public static BinaryCodecDefinitions.EnumBinaryCodec Enum() where E : Enum => new(); + public static IBinaryCodec Enum() where E : Enum => new BinaryCodecDefinitions.EnumBinaryCodec(); public static IBinaryCodec Flags() where Te : struct, Enum => BYTE.Transform(te => Unsafe.As(ref te), by => Unsafe.As(ref by)); @@ -73,32 +75,32 @@ public interface IBinaryCodec void Write(IByteBuffer buffer, T value); T Read(IByteBuffer buffer); - BinaryCodecDefinitions.OptionalBinaryCodec Optional() + IBinaryCodec> Optional() { return new BinaryCodecDefinitions.OptionalBinaryCodec(this); } - BinaryCodecDefinitions.DefaultBinaryCodec Default(T defaultValue) + IBinaryCodec Default(T defaultValue) { return new BinaryCodecDefinitions.DefaultBinaryCodec(this, defaultValue); } - BinaryCodecDefinitions.TransformativeBinaryCodec Transform(Func from, Func to) + IBinaryCodec Transform(Func from, Func to) { return new BinaryCodecDefinitions.TransformativeBinaryCodec(this, from, to); } - BinaryCodecDefinitions.DictionaryBinaryCodec MapTo(IBinaryCodec valueCodec, int? maxSize = null) where V : notnull + IBinaryCodec> MapTo(IBinaryCodec valueCodec, int? maxSize = null) where V : notnull { return new BinaryCodecDefinitions.DictionaryBinaryCodec(this, valueCodec, maxSize); } - BinaryCodecDefinitions.ListBinaryCodec List(int? maxSize = null) + IBinaryCodec> List(int? maxSize = null) { return new BinaryCodecDefinitions.ListBinaryCodec(this, maxSize); } - BinaryCodecDefinitions.UnionBinaryCodec Union(Func> serializerFactory, Func keyFunc) where K : notnull + IBinaryCodec Union(Func> serializerFactory, Func keyFunc) where K : notnull { return new BinaryCodecDefinitions.UnionBinaryCodec(this, keyFunc, serializerFactory); } diff --git a/Codon.Codec/Codecs.cs b/Codon.Codec/Codecs.cs index 1de4085..8b093ed 100644 --- a/Codon.Codec/Codecs.cs +++ b/Codon.Codec/Codecs.cs @@ -114,7 +114,7 @@ public override Optional Decode(ITranscoder transcoder, D value) return EqualityComparer.Default.Equals(value, nullValue) ? Optionals.Optional.Empty() - : Optionals.Optional.From(Inner.Decode(transcoder, value)); + : Optionals.Optional.Of(Inner.Decode(transcoder, value)); } catch (Exception) { diff --git a/Codon.Codec/Extensions.cs b/Codon.Codec/Extensions.cs index 158d41b..5ab7d28 100644 --- a/Codon.Codec/Extensions.cs +++ b/Codon.Codec/Extensions.cs @@ -16,15 +16,15 @@ public static class Extensions public static Optional ToOptional(this T? nullable) where T : struct { return nullable.HasValue - ? new Optional(nullable.Value) - : new Optional(); + ? Optional.Of(nullable.Value) + : Optional.Empty(); } public static Optional ToOptional(this T? obj) where T : class { return obj is not null - ? new Optional(obj) - : new Optional(); + ? Optional.Of(obj) + : Optional.Empty(); } public static JsonElement ToJson(this string text) => JsonDocument.Parse(text).RootElement; diff --git a/Codon.Optionals/Extensions.cs b/Codon.Optionals/Extensions.cs new file mode 100644 index 0000000..ecfd08f --- /dev/null +++ b/Codon.Optionals/Extensions.cs @@ -0,0 +1,22 @@ +// Copyright (c) 2026 SynesthesiaDev . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Runtime.CompilerServices; + +namespace Codon.Optionals; + +public static class Extensions +{ + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T? ToNullableStruct(this Optional optional) where T : struct + { + return optional.IsPresent ? optional.Value : null; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T? ToNullableClass(this Optional optional) where T : class + { + return optional.IsPresent ? optional.Value : null; + } + +} diff --git a/Codon.Optionals/Optional.cs b/Codon.Optionals/Optional.cs index ee5a752..91a8457 100644 --- a/Codon.Optionals/Optional.cs +++ b/Codon.Optionals/Optional.cs @@ -1,58 +1,54 @@ namespace Codon.Optionals; -public class Optional(bool isPresent, T? value) +public class Optional { - public T? Value => IsPresent ? value : default; - - public readonly bool IsPresent = isPresent; + public T? Value { get; set; } + public bool IsPresent { get; set; } public bool IsMissing => !IsPresent; - public Optional() : this(false, default) + public Optional() { + IsPresent = false; + Value = default; } - public Optional(T? value) : this(value != null, value) + public Optional(object? value) { + if (value is null) + { + IsPresent = false; + Value = default; + } + else + { + IsPresent = true; + Value = (T)value; + } } - public T GetOrElse(T defaultValue) - { - return IsPresent ? Value! : defaultValue; - } + public T GetOrElse(T defaultValue) => IsPresent ? Value! : defaultValue; - public override string ToString() - { - return IsMissing ? "null" : Value!.ToString()!; - } + public override string ToString() => IsMissing ? "null" : Value!.ToString()!; public bool Equals(Optional? other) { if (other is null) return false; - if (ReferenceEquals(this, other)) return true; - if (IsMissing && other.IsMissing) return true; - if (IsMissing || other.IsMissing) return false; return EqualityComparer.Default.Equals(Value!, other.Value!); } - public override bool Equals(object? obj) - { - return obj is Optional other && Equals(other); - } + public override bool Equals(object? obj) => obj is Optional other && Equals(other); + + public override int GetHashCode() => IsMissing ? 0 : EqualityComparer.Default.GetHashCode(Value!); - public override int GetHashCode() - { - return IsMissing ? 0 : EqualityComparer.Default.GetHashCode(Value!); - } } public static class Optional { - public static Optional Empty() => new(false, default); - public static Optional Of(T? value) => new(value); - public static Optional From(T value) => new(true, value); + public static Optional Empty() => new(); + public static Optional Of(object? value) => new(value); } diff --git a/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/.gitignore b/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/.gitignore new file mode 100644 index 0000000..57921d3 --- /dev/null +++ b/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/contentModel.xml +/modules.xml +/.idea.CodonPlugin.sln.iml +/projectSettingsUpdater.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/.name b/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/.name new file mode 100644 index 0000000..2483eb9 --- /dev/null +++ b/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/.name @@ -0,0 +1 @@ +CodonPlugin.sln \ No newline at end of file diff --git a/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/discord.xml b/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/discord.xml new file mode 100644 index 0000000..912db82 --- /dev/null +++ b/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/discord.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/encodings.xml b/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/indexLayout.xml b/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/vcs.xml b/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Codon.Plugin/.idea/.idea.CodonPlugin.sln/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/.gitignore b/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/.gitignore new file mode 100644 index 0000000..61c55bf --- /dev/null +++ b/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/.idea.CodonPlugin.iml +/modules.xml +/projectSettingsUpdater.xml +/contentModel.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/.name b/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/.name new file mode 100644 index 0000000..e8071da --- /dev/null +++ b/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/.name @@ -0,0 +1 @@ +CodonPlugin \ No newline at end of file diff --git a/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/discord.xml b/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/discord.xml new file mode 100644 index 0000000..912db82 --- /dev/null +++ b/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/discord.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/encodings.xml b/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/indexLayout.xml b/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/vcs.xml b/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Codon.Plugin/.idea/.idea.CodonPlugin/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Codon.Plugin/.idea/dictionaries/project.xml b/Codon.Plugin/.idea/dictionaries/project.xml new file mode 100644 index 0000000..f0a7a7c --- /dev/null +++ b/Codon.Plugin/.idea/dictionaries/project.xml @@ -0,0 +1,7 @@ + + + + rdgen + + + \ No newline at end of file diff --git a/Codon.Plugin/src/dotnet/Rider.Plugins.CodonPlugin/Model/RdCodonPluginModel.Generated.cs b/Codon.Plugin/src/dotnet/Rider.Plugins.CodonPlugin/Model/RdCodonPluginModel.Generated.cs new file mode 100644 index 0000000..e84c5a3 --- /dev/null +++ b/Codon.Plugin/src/dotnet/Rider.Plugins.CodonPlugin/Model/RdCodonPluginModel.Generated.cs @@ -0,0 +1,294 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a RdGen v1.13. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +using System; +using System.Linq; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using JetBrains.Annotations; + +using JetBrains.Core; +using JetBrains.Diagnostics; +using JetBrains.Collections; +using JetBrains.Collections.Viewable; +using JetBrains.Lifetimes; +using JetBrains.Serialization; +using JetBrains.Rd; +using JetBrains.Rd.Base; +using JetBrains.Rd.Impl; +using JetBrains.Rd.Tasks; +using JetBrains.Rd.Util; +using JetBrains.Rd.Text; + + +// ReSharper disable RedundantEmptyObjectCreationArgumentList +// ReSharper disable InconsistentNaming +// ReSharper disable RedundantOverflowCheckingContext + + +namespace Rider.Plugins.CodonPlugin.Model +{ + + + /// + ///

Generated from: RdCodonPluginModel.kt:11

+ ///
+ public class RdCodonPluginModel : RdExtBase + { + //fields + //public fields + + /// + /// This is an example protocol call. + /// + [NotNull] public IRdEndpoint MyCall => _MyCall; + + /// + /// This is an example protocol call for getting a backend icon. + /// + [NotNull] public IRdEndpoint MyIconCall => _MyIconCall; + + //private fields + [NotNull] private readonly RdCall _MyCall; + [NotNull] private readonly RdCall _MyIconCall; + + //primary constructor + private RdCodonPluginModel( + [NotNull] RdCall myCall, + [NotNull] RdCall myIconCall + ) + { + if (myCall == null) throw new ArgumentNullException("myCall"); + if (myIconCall == null) throw new ArgumentNullException("myIconCall"); + + _MyCall = myCall; + _MyIconCall = myIconCall; + BindableChildren.Add(new KeyValuePair("myCall", _MyCall)); + BindableChildren.Add(new KeyValuePair("myIconCall", _MyIconCall)); + } + //secondary constructor + internal RdCodonPluginModel ( + ) : this ( + new RdCall(RdCallRequest.Read, RdCallRequest.Write, RdCallResponse.Read, RdCallResponse.Write), + new RdCall(JetBrains.Rd.Impl.Serializers.ReadVoid, JetBrains.Rd.Impl.Serializers.WriteVoid, JetBrains.Rider.Model.IconModel.Read, JetBrains.Rider.Model.IconModel.Write) + ) {} + //deconstruct trait + //statics + + + + protected override long SerializationHash => -2925658527367673754L; + + protected override Action Register => RegisterDeclaredTypesSerializers; + public static void RegisterDeclaredTypesSerializers(ISerializers serializers) + { + + serializers.RegisterToplevelOnce(typeof(JetBrains.Rider.Model.IdeRoot), JetBrains.Rider.Model.IdeRoot.RegisterDeclaredTypesSerializers); + } + + + //constants + + //custom body + //methods + //equals trait + //hash code trait + //pretty print + public override void Print(PrettyPrinter printer) + { + printer.Println("RdCodonPluginModel ("); + using (printer.IndentCookie()) { + printer.Print("myCall = "); _MyCall.PrintEx(printer); printer.Println(); + printer.Print("myIconCall = "); _MyIconCall.PrintEx(printer); printer.Println(); + } + printer.Print(")"); + } + //toString + public override string ToString() + { + var printer = new SingleLinePrettyPrinter(); + Print(printer); + return printer.ToString(); + } + } + public static class SolutionRdCodonPluginModelEx + { + public static RdCodonPluginModel GetRdCodonPluginModel(this JetBrains.Rider.Model.Solution solution) + { + return solution.GetOrCreateExtension("rdCodonPluginModel", () => new RdCodonPluginModel()); + } + } + + + /// + ///

Generated from: RdCodonPluginModel.kt:13

+ ///
+ public sealed class RdCallRequest : IPrintable, IEquatable + { + //fields + //public fields + [NotNull] public string MyField {get; private set;} + + //private fields + //primary constructor + public RdCallRequest( + [NotNull] string myField + ) + { + if (myField == null) throw new ArgumentNullException("myField"); + + MyField = myField; + } + //secondary constructor + //deconstruct trait + public void Deconstruct([NotNull] out string myField) + { + myField = MyField; + } + //statics + + public static CtxReadDelegate Read = (ctx, reader) => + { + var myField = reader.ReadString(); + var _result = new RdCallRequest(myField); + return _result; + }; + + public static CtxWriteDelegate Write = (ctx, writer, value) => + { + writer.Write(value.MyField); + }; + + //constants + + //custom body + //methods + //equals trait + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((RdCallRequest) obj); + } + public bool Equals(RdCallRequest other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return MyField == other.MyField; + } + //hash code trait + public override int GetHashCode() + { + unchecked { + var hash = 0; + hash = hash * 31 + MyField.GetHashCode(); + return hash; + } + } + //pretty print + public void Print(PrettyPrinter printer) + { + printer.Println("RdCallRequest ("); + using (printer.IndentCookie()) { + printer.Print("myField = "); MyField.PrintEx(printer); printer.Println(); + } + printer.Print(")"); + } + //toString + public override string ToString() + { + var printer = new SingleLinePrettyPrinter(); + Print(printer); + return printer.ToString(); + } + } + + + /// + ///

Generated from: RdCodonPluginModel.kt:17

+ ///
+ public sealed class RdCallResponse : IPrintable, IEquatable + { + //fields + //public fields + public int MyResult {get; private set;} + + //private fields + //primary constructor + public RdCallResponse( + int myResult + ) + { + MyResult = myResult; + } + //secondary constructor + //deconstruct trait + public void Deconstruct(out int myResult) + { + myResult = MyResult; + } + //statics + + public static CtxReadDelegate Read = (ctx, reader) => + { + var myResult = reader.ReadInt(); + var _result = new RdCallResponse(myResult); + return _result; + }; + + public static CtxWriteDelegate Write = (ctx, writer, value) => + { + writer.Write(value.MyResult); + }; + + //constants + + //custom body + //methods + //equals trait + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((RdCallResponse) obj); + } + public bool Equals(RdCallResponse other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return MyResult == other.MyResult; + } + //hash code trait + public override int GetHashCode() + { + unchecked { + var hash = 0; + hash = hash * 31 + MyResult.GetHashCode(); + return hash; + } + } + //pretty print + public void Print(PrettyPrinter printer) + { + printer.Println("RdCallResponse ("); + using (printer.IndentCookie()) { + printer.Print("myResult = "); MyResult.PrintEx(printer); printer.Println(); + } + printer.Print(")"); + } + //toString + public override string ToString() + { + var printer = new SingleLinePrettyPrinter(); + Print(printer); + return printer.ToString(); + } + } +} diff --git a/Codon.Plugin/src/dotnet/nuget.config b/Codon.Plugin/src/dotnet/nuget.config new file mode 100644 index 0000000..8a8f79f --- /dev/null +++ b/Codon.Plugin/src/dotnet/nuget.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Codon.Plugin/src/rider/generated/kotlin/com/jetbrains/rider/plugins/codonplugin/RdCodonPluginModel.Generated.kt b/Codon.Plugin/src/rider/generated/kotlin/com/jetbrains/rider/plugins/codonplugin/RdCodonPluginModel.Generated.kt new file mode 100644 index 0000000..710eac8 --- /dev/null +++ b/Codon.Plugin/src/rider/generated/kotlin/com/jetbrains/rider/plugins/codonplugin/RdCodonPluginModel.Generated.kt @@ -0,0 +1,219 @@ +@file:Suppress("EXPERIMENTAL_API_USAGE","EXPERIMENTAL_UNSIGNED_LITERALS","PackageDirectoryMismatch","UnusedImport","unused","LocalVariableName","CanBeVal","PropertyName","EnumEntryName","ClassName","ObjectPropertyName","UnnecessaryVariable","SpellCheckingInspection") +package com.jetbrains.rider.plugins.codonplugin.model + +import com.jetbrains.rd.framework.* +import com.jetbrains.rd.framework.base.* +import com.jetbrains.rd.framework.impl.* + +import com.jetbrains.rd.util.lifetime.* +import com.jetbrains.rd.util.reactive.* +import com.jetbrains.rd.util.string.* +import com.jetbrains.rd.util.* +import kotlin.time.Duration +import kotlin.reflect.KClass +import kotlin.jvm.JvmStatic + + + +/** + * #### Generated from [RdCodonPluginModel.kt:11] + */ +class RdCodonPluginModel private constructor( + private val _myCall: RdCall, + private val _myIconCall: RdCall +) : RdExtBase() { + //companion + + companion object : ISerializersOwner { + + override fun registerSerializersCore(serializers: ISerializers) { + val classLoader = javaClass.classLoader + serializers.register(LazyCompanionMarshaller(RdId(-3835427627873167508), classLoader, "com.jetbrains.rider.plugins.codonplugin.model.RdCallRequest")) + serializers.register(LazyCompanionMarshaller(RdId(-8217792021757949180), classLoader, "com.jetbrains.rider.plugins.codonplugin.model.RdCallResponse")) + } + + + + + + const val serializationHash = -2925658527367673754L + + } + override val serializersOwner: ISerializersOwner get() = RdCodonPluginModel + override val serializationHash: Long get() = RdCodonPluginModel.serializationHash + + //fields + + /** + * This is an example protocol call. + */ + val myCall: IRdCall get() = _myCall + + /** + * This is an example protocol call for getting a backend icon. + */ + val myIconCall: IRdCall get() = _myIconCall + //methods + //initializer + init { + bindableChildren.add("myCall" to _myCall) + bindableChildren.add("myIconCall" to _myIconCall) + } + + //secondary constructor + internal constructor( + ) : this( + RdCall(RdCallRequest, RdCallResponse), + RdCall(FrameworkMarshallers.Void, AbstractPolymorphic(com.jetbrains.rd.ide.model.IconModel)) + ) + + //equals trait + //hash code trait + //pretty print + override fun print(printer: PrettyPrinter) { + printer.println("RdCodonPluginModel (") + printer.indent { + print("myCall = "); _myCall.print(printer); println() + print("myIconCall = "); _myIconCall.print(printer); println() + } + printer.print(")") + } + //deepClone + override fun deepClone(): RdCodonPluginModel { + return RdCodonPluginModel( + _myCall.deepClonePolymorphic(), + _myIconCall.deepClonePolymorphic() + ) + } + //contexts + //threading + override val extThreading: ExtThreadingKind get() = ExtThreadingKind.Default +} +val com.jetbrains.rd.ide.model.Solution.rdCodonPluginModel get() = getOrCreateExtension("rdCodonPluginModel", ::RdCodonPluginModel) + + + +/** + * #### Generated from [RdCodonPluginModel.kt:13] + */ +data class RdCallRequest ( + val myField: String +) : IPrintable { + //write-marshaller + private fun write(ctx: SerializationCtx, buffer: AbstractBuffer) { + buffer.writeString(myField) + } + //companion + + companion object : IMarshaller { + override val _type: KClass = RdCallRequest::class + override val id: RdId get() = RdId(-3835427627873167508) + + @Suppress("UNCHECKED_CAST") + override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): RdCallRequest { + val myField = buffer.readString() + return RdCallRequest(myField) + } + + override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: RdCallRequest) { + value.write(ctx, buffer) + } + + + } + //fields + //methods + //initializer + //secondary constructor + //equals trait + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other == null || other::class != this::class) return false + + other as RdCallRequest + + if (myField != other.myField) return false + + return true + } + //hash code trait + override fun hashCode(): Int { + var __r = 0 + __r = __r*31 + myField.hashCode() + return __r + } + //pretty print + override fun print(printer: PrettyPrinter) { + printer.println("RdCallRequest (") + printer.indent { + print("myField = "); myField.print(printer); println() + } + printer.print(")") + } + //deepClone + //contexts + //threading +} + + +/** + * #### Generated from [RdCodonPluginModel.kt:17] + */ +data class RdCallResponse ( + val myResult: Int +) : IPrintable { + //write-marshaller + private fun write(ctx: SerializationCtx, buffer: AbstractBuffer) { + buffer.writeInt(myResult) + } + //companion + + companion object : IMarshaller { + override val _type: KClass = RdCallResponse::class + override val id: RdId get() = RdId(-8217792021757949180) + + @Suppress("UNCHECKED_CAST") + override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): RdCallResponse { + val myResult = buffer.readInt() + return RdCallResponse(myResult) + } + + override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: RdCallResponse) { + value.write(ctx, buffer) + } + + + } + //fields + //methods + //initializer + //secondary constructor + //equals trait + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other == null || other::class != this::class) return false + + other as RdCallResponse + + if (myResult != other.myResult) return false + + return true + } + //hash code trait + override fun hashCode(): Int { + var __r = 0 + __r = __r*31 + myResult.hashCode() + return __r + } + //pretty print + override fun print(printer: PrettyPrinter) { + printer.println("RdCallResponse (") + printer.indent { + print("myResult = "); myResult.print(printer); println() + } + printer.print(")") + } + //deepClone + //contexts + //threading +} diff --git a/Codon.Tests/BinaryCodecsTests.cs b/Codon.Tests/BinaryCodecsTests.cs index e959dc3..e2683a8 100644 --- a/Codon.Tests/BinaryCodecsTests.cs +++ b/Codon.Tests/BinaryCodecsTests.cs @@ -144,7 +144,7 @@ public void Optional_Codec_WritesPresenceAndValue() { var optionalInt = BinaryCodecs.INT.Optional(); - var some = Optional.Of(123); + var some = Optional.Of(123); var bufSome = Unpooled.Buffer(); optionalInt.Write(bufSome, some); var readSome = optionalInt.Read(bufSome); @@ -192,7 +192,7 @@ public void Transformative_Codec_RoundTrip() [Test] public void List_And_Dictionary_Codecs_RoundTrip() { - BinaryCodecDefinitions.ListBinaryCodec listCodec = BinaryCodecs.STRING.List(); + var listCodec = BinaryCodecs.STRING.List(); var list = new List { "a", "b", "c" }; Assert.That(roundTrip(listCodec, list), Is.EqualTo(list)); diff --git a/Codon.Tests/CodecTests.cs b/Codon.Tests/CodecTests.cs index 2c08a22..8391889 100644 --- a/Codon.Tests/CodecTests.cs +++ b/Codon.Tests/CodecTests.cs @@ -29,7 +29,7 @@ public record Car(string Model, List Passengers, Optional Driver [Test] public void TestCodec() { - var person = new Person("Silly Billy", 18, Optional.Of(true)); + var person = new Person("Silly Billy", 18, Optional.Of(true)); var encoded = Person.CODEC.Encode(JsonTranscoder.INSTANCE, person); Console.WriteLine(encoded.GetRawText()); // {"name":"Silly Billy","age":18,"is_awesome":true} diff --git a/Codon.Tests/EdgeCasesTests.cs b/Codon.Tests/EdgeCasesTests.cs index 75057b3..5d005f1 100644 --- a/Codon.Tests/EdgeCasesTests.cs +++ b/Codon.Tests/EdgeCasesTests.cs @@ -3,7 +3,7 @@ using Codon.Codec; using Codon.IniTranscoder.Elements; -using SynesthesiaDev.Synx; +using Codon.Optionals; using SynesthesiaDev.Synx.Codon; namespace Codon.Tests; @@ -11,12 +11,20 @@ namespace Codon.Tests; public class EdgeCasesTests { private readonly Codecs.OptionalCodec optionalString = new(Codecs.STRING); - private record TestingClass(string TestString, TestEnummm? Enuming) + private record TestingClass(string TestString, TestEnummm? Enuming, Thing? Thing) { public static readonly StructCodec CODEC = StructCodec.For() .Field("TestString", Codecs.STRING, t => t.TestString) .Field("Enuming", Codecs.Enum().Optional(), t => t.Enuming.ToOptional()) - .Build((s, e) => new TestingClass(s ,e.Value)); + .Field("Thing", Thing.CODEC.Optional(), t => t.Thing.ToOptional()) + .Build((s, e, t) => new TestingClass(s ,e.ToNullableStruct(), t.ToNullableClass())); + } + + public record Thing(string Name) + { + public static readonly Codec CODEC = StructCodec.For() + .Field("Name", Codecs.STRING, t => t.Name) + .Build(n => new Thing(n)); } private enum TestEnummm @@ -39,9 +47,10 @@ public void Test() [Test] public void TestEnum() { - var encoded = TestingClass.CODEC.Encode(SynxTranscoder.INSTANCE, new TestingClass("yo", null)); + var encoded = TestingClass.CODEC.Encode(SynxTranscoder.INSTANCE, new TestingClass("yo", null, null)); var decoded = TestingClass.CODEC.Decode(SynxTranscoder.INSTANCE, encoded); Assert.That(decoded.Enuming, Is.Null); + Assert.That(decoded.Thing, Is.Null); } } diff --git a/Codon.Tests/OptionalAndDefaultCodecTests.cs b/Codon.Tests/OptionalAndDefaultCodecTests.cs index a7e2a66..1f9e590 100644 --- a/Codon.Tests/OptionalAndDefaultCodecTests.cs +++ b/Codon.Tests/OptionalAndDefaultCodecTests.cs @@ -12,7 +12,7 @@ public class OptionalAndDefaultCodecTests public void Optional_Present_RoundTrip() { var codec = Codecs.INT.Optional(); - var value = Optional.Of(42); + var value = Optional.Of(42); var encoded = codec.Encode(t, value); var decoded = codec.Decode(t, encoded); Assert.That(decoded.IsPresent, Is.True); diff --git a/Codon.Tests/VersionCodecTests.cs b/Codon.Tests/VersionCodecTests.cs index fa623c2..ec45a71 100644 --- a/Codon.Tests/VersionCodecTests.cs +++ b/Codon.Tests/VersionCodecTests.cs @@ -117,7 +117,7 @@ public void Decode_WhenMigrationIsMissing_ThrowsKeyNotFoundException() [Test] public void Encode_AlwaysAddsSchemaVersion_AndRoundTripsWithDecode() { - var original = new Person("Synesthesia Dev", 123, Optional.Of(true)); + var original = new Person("Synesthesia Dev", 123, Optional.Of(true)); var encoded = Person.VERSIONED_CODEC.Encode(JsonTranscoder.INSTANCE, original);