Skip to content

Commit ecb7aaf

Browse files
committed
Added return description to the generated ysls file
1 parent 04dbc47 commit ecb7aaf

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

Editor/Analysis/Action.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ public Action(string name, ActionType type, IMethodSymbol methodSymbol)
226226
/// </summary>
227227
public List<Parameter> Parameters = new List<Parameter>();
228228

229+
public string? ReturnDescription;
229230
public string? YarnReturnTypeString => this.MethodSymbol.ReturnType.GetYarnTypeString();
230231

231232
public string ToJSON()
@@ -307,7 +308,14 @@ public string ToJSON()
307308

308309
if (this.Type == ActionType.Function)
309310
{
310-
result["ReturnType"] = this.YarnReturnTypeString;
311+
var retvrn = new Dictionary<string, string>();
312+
retvrn["Type"] = this.YarnReturnTypeString ?? "error";
313+
314+
if (!string.IsNullOrWhiteSpace(this.ReturnDescription))
315+
{
316+
retvrn["Description"] = this.ReturnDescription;
317+
}
318+
result["Return"] = retvrn;
311319
}
312320

313321
return Yarn.Unity.Editor.Json.Serialize(result);

Editor/Analysis/Analyser.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,16 @@ private static IEnumerable<Action> GetRuntimeDefinedActions(CompilationUnitSynta
565565

566566
var declaringSyntax = targetSymbol.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax();
567567

568-
TryGetDocumentation(targetSymbol, logger, out XElement? documentationXML, out string? summary);
568+
string? ReturnDescription = null;
569+
if (TryGetDocumentation(targetSymbol, logger, out XElement? documentationXML, out string? summary))
570+
{
571+
var returnNode = documentationXML?.Element("returns");
572+
if (returnNode != null)
573+
{
574+
ReturnDescription = string.Join("", returnNode.DescendantNodes().OfType<XText>().Select(n => n.ToString())).Trim();
575+
logger?.WriteLine($"\tFound a return: {ReturnDescription}");
576+
}
577+
}
569578

570579
yield return new Action(name, methodCall.Type, targetSymbol)
571580
{
@@ -577,6 +586,7 @@ private static IEnumerable<Action> GetRuntimeDefinedActions(CompilationUnitSynta
577586
Parameters = GetParams(targetSymbol, documentationXML, logger),
578587
SourceFileName = root.SyntaxTree.FilePath,
579588
DeclarationType = DeclarationType.DirectRegistration,
589+
ReturnDescription = ReturnDescription,
580590
};
581591
}
582592
}
@@ -647,6 +657,7 @@ private static bool TryGetDocumentation(IMethodSymbol targetSymbol, ILogger? log
647657

648658
// 3. This is not doc XML and just happens to be a comment above a command/function
649659
summary = documentationComments;
660+
documentationXML = null;
650661
logger?.WriteLine("Unable to determine XML, returning the comment as is");
651662
return true;
652663
}
@@ -741,7 +752,16 @@ private static IEnumerable<Action> GetAttributeActions(CompilationUnitSyntax roo
741752
continue;
742753
}
743754

744-
TryGetDocumentation(methodSymbol, logger, out XElement? documentationXML, out string? summary);
755+
string? ReturnDescription = null;
756+
if (TryGetDocumentation(methodSymbol, logger, out XElement? documentationXML, out string? summary))
757+
{
758+
var returnNode = documentationXML?.Element("returns");
759+
if (returnNode != null)
760+
{
761+
ReturnDescription = string.Join("", returnNode.DescendantNodes().OfType<XText>().Select(n => n.ToString())).Trim();
762+
logger.WriteLine($"\tFound a return: {ReturnDescription}");
763+
}
764+
}
745765

746766
var containerName = container?.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) ?? "<unknown>";
747767

@@ -761,6 +781,7 @@ private static IEnumerable<Action> GetAttributeActions(CompilationUnitSyntax roo
761781
Description = summary,
762782
SourceFileName = root.SyntaxTree.FilePath,
763783
DeclarationType = DeclarationType.Attribute,
784+
ReturnDescription = ReturnDescription,
764785
};
765786
}
766787
}
1 KB
Binary file not shown.

0 commit comments

Comments
 (0)