diff --git a/PLCSharp.Mcp/ProjectTools.cs b/PLCSharp.Mcp/ProjectTools.cs index 28dfbe9..0cd6fdb 100644 --- a/PLCSharp.Mcp/ProjectTools.cs +++ b/PLCSharp.Mcp/ProjectTools.cs @@ -38,7 +38,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, VisionFunctions, 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, or an Axes ID across recipes. 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 abc08b2..bc2da15 100644 --- a/PLCSharpWpf/Models/WorkflowReferences.cs +++ b/PLCSharpWpf/Models/WorkflowReferences.cs @@ -29,21 +29,22 @@ 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), - "VisionFunctions" => typeof(VisionFunction), "AxisPoints" => typeof(AxisPoint), "RobotPoints" => typeof(RobotPoint), + "VisionFunctions" => typeof(VisionFunction), "Axes" => typeof(Axis), "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"]); + var recipeId = kind == "Axes" ? Guid.Empty : Guid.Parse((string)target["RecipeID"]); var name = (string)target["Name"]; var robotId = kind == "RobotPoints" ? Guid.Parse((string)target["RobotID"]) : Guid.Empty; var robots = kind == "RobotPoints" ? project.Data.Robots.Select(r => new { r.ID, r.Name }).ToList() : []; var hits = new List(); var diagnostics = new List(); - foreach (var workflow in project.Flows(recipeId)) + foreach (var recipe in project.Recipes.Where(r => kind == "Axes" || r.ID == recipeId)) + foreach (var workflow in project.Flows(recipe.ID)) { var tree = CSharpSyntaxTree.ParseText(workflow.Code ?? ""); var root = tree.GetRoot(); var model = CSharpCompilation.Create("Inspect", [tree], References.Value).GetSemanticModel(tree); - var path = $"recipes/{recipeId:D}/workflows/{workflow.ID:D}.cs"; + var path = $"recipes/{recipe.ID:D}/workflows/{workflow.ID:D}.cs"; foreach (var error in tree.GetDiagnostics().Where(d => d.Severity == DiagnosticSeverity.Error)) diagnostics.Add(new { path, line = error.Location.GetLineSpan().StartLinePosition.Line + 1, message = error.GetMessage() }); @@ -52,7 +53,7 @@ internal static class WorkflowReferences var constant = model.GetConstantValue(value); if (constant.HasValue && !Equals(constant.Value, name)) return; var position = location.GetLocation().GetLineSpan().StartLinePosition; - hits.Add(new { workflowId = workflow.ID, workflow.Name, path, line = position.Line + 1, + hits.Add(new { recipeId = recipe.ID, workflowId = workflow.ID, workflow.Name, path, line = position.Line + 1, column = position.Character + 1, start = value.SpanStart, length = value.Span.Length, expression = location.ToString(), confidence = !constant.HasValue ? "dynamic" : bound ? "confirmed" : "possible" }); } @@ -104,7 +105,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" or "VisionFunctions"))); + Record(value, comparison, bound == true || (!forRename && kind is not ("Axes" or "AxisPoints" or "RobotPoints" or "VisionFunctions"))); } } } @@ -126,6 +127,13 @@ internal static class WorkflowReferences { "VisionFunctions" => source.Name == nameof(VisionsModel.VisionFunctions) && source.ContainingType.ToDisplayString() == typeof(VisionsModel).FullName, + "Axes" => source.Name == nameof(ControllersModel.Axes) && + (source.ContainingType.ToDisplayString() == typeof(ControllersModel).FullName || + source.ContainingType.ToDisplayString() == typeof(Controller).FullName && + method.Expression is MemberAccessExpressionSyntax axes && + model.GetSymbolInfo(axes.Expression).Symbol is IPropertySymbol controller && + controller.Name == nameof(ControllersModel.Controller) && + controller.ContainingType.ToDisplayString() == typeof(ControllersModel).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 &&