Resolve recipe-scoped vision function references in workflow scripts

This commit is contained in:
wanglei 2026-12-05 21:55:34 +08:00
parent c8e14cb5af
commit 1efee842d7
2 changed files with 8 additions and 4 deletions

View File

@ -34,7 +34,7 @@ internal sealed class ProjectTools(ProjectGateway gateway)
[McpServerTool(Name = "get_change_status", ReadOnly = true), Description("Inspect a pending, rejected or saved draft.")]
public string GetChangeStatus(string draftId) => gateway.Call("status", new() { ["draftId"] = draftId });
[McpServerTool(Name = "find_references", ReadOnly = true), Description("Find C# references to a Variables, SystemVariables, Workflows, AxisPoints or RobotPoints ID within its recipe. Dynamic hits require human review.")]
[McpServerTool(Name = "find_references", ReadOnly = true), Description("Find C# references to a Variables, SystemVariables, Workflows, VisionFunctions, AxisPoints or RobotPoints ID within its recipe. Dynamic hits require human review.")]
public string FindReferences(string kind, string id) => gateway.Call("references", new() { ["kind"] = kind, ["id"] = id });
[McpServerTool(Name = "get_project_summary", ReadOnly = true), Description("Read the bound PLCSharp project, default recipe and available object kinds.")]

View File

@ -6,6 +6,7 @@ using PLCSharp.VVMs.MotionController;
using PLCSharp.VVMs.Robots;
using Microsoft.CodeAnalysis.Operations;
using PLCSharp.VVMs.Workflows;
using PLCSharp.VVMs.Vision;
using System.IO;
using System.Text.Json;
using System.Text.Json.Nodes;
@ -28,7 +29,7 @@ internal static class WorkflowReferences
internal static JsonNode Find(ProjectDirectory project, string kind, string id, bool forRename = false)
{
var targetType = kind switch { "Variables" => typeof(Variable), "SystemVariables" => typeof(SystemVariable),
"AxisPoints" => typeof(AxisPoint), "RobotPoints" => typeof(RobotPoint),
"VisionFunctions" => typeof(VisionFunction), "AxisPoints" => typeof(AxisPoint), "RobotPoints" => typeof(RobotPoint),
"Workflows" => typeof(Workflow), _ => throw new ArgumentException("Unsupported reference target.") };
var target = ProjectInspection.Query(project, "get", new() { ["kind"] = kind, ["id"] = id });
var recipeId = Guid.Parse((string)target["RecipeID"]);
@ -67,7 +68,8 @@ internal static class WorkflowReferences
return matches.Length == 1 ? matches[0].ID == robotId : null;
}
var lookup = kind switch { "Variables" => "GetVariable", "Workflows" => "GetTask", _ => null };
var lookup = kind switch { "Variables" => "GetVariable", "Workflows" => "GetTask",
"VisionFunctions" => nameof(GlobalModel.GetVisionFunction), _ => null };
foreach (var call in root.DescendantNodes().OfType<InvocationExpressionSyntax>())
{
var methodName = call.Expression switch { MemberAccessExpressionSyntax m => m.Name.Identifier.ValueText,
@ -102,7 +104,7 @@ internal static class WorkflowReferences
{
bool? bound = IsRecipePredicate(member, model, kind, IsTargetRobot);
if (bound != false || kind != "RobotPoints")
Record(value, comparison, bound == true || (!forRename && kind is not ("AxisPoints" or "RobotPoints")));
Record(value, comparison, bound == true || (!forRename && kind is not ("AxisPoints" or "RobotPoints" or "VisionFunctions")));
}
}
}
@ -122,6 +124,8 @@ internal static class WorkflowReferences
if (model.GetSymbolInfo(method.Expression).Symbol is not IPropertySymbol source) return null;
return kind switch
{
"VisionFunctions" => source.Name == nameof(VisionsModel.VisionFunctions) &&
source.ContainingType.ToDisplayString() == typeof(VisionsModel).FullName,
"AxisPoints" => source.Name == nameof(ControllersModel.AxisPoints) &&
source.ContainingType.ToDisplayString() == typeof(ControllersModel).FullName,
"RobotPoints" when source.Name == nameof(Robot.Points) && source.ContainingType.ToDisplayString() == typeof(Robot).FullName &&