From 1efee842d77d68b2ced5143d0f34d5d01add6637 Mon Sep 17 00:00:00 2001 From: wanglei Date: Sat, 5 Dec 2026 21:55:34 +0800 Subject: [PATCH] Resolve recipe-scoped vision function references in workflow scripts --- PLCSharp.Mcp/ProjectTools.cs | 2 +- PLCSharpWpf/Models/WorkflowReferences.cs | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/PLCSharp.Mcp/ProjectTools.cs b/PLCSharp.Mcp/ProjectTools.cs index 6dc8990..7317627 100644 --- a/PLCSharp.Mcp/ProjectTools.cs +++ b/PLCSharp.Mcp/ProjectTools.cs @@ -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.")] diff --git a/PLCSharpWpf/Models/WorkflowReferences.cs b/PLCSharpWpf/Models/WorkflowReferences.cs index b25d824..abc08b2 100644 --- a/PLCSharpWpf/Models/WorkflowReferences.cs +++ b/PLCSharpWpf/Models/WorkflowReferences.cs @@ -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()) { 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 &&