This is an automated email from the ASF dual-hosted git repository. jdaugherty pushed a commit to branch feature/scaffold-generated-actions in repository https://gitbox.apache.org/repos/asf/grails-intellij-plugin.git
commit 127ba1d04632c3b764b82e9ba530e9befe06adb0 Author: James Daugherty <[email protected]> AuthorDate: Mon Oct 12 15:51:07 2026 +0100 Label each scaffolded method hint with its annotation, one group per blank line The grey lines inside a scaffolded class now explain themselves: above each inherited method a comment names the annotation responsible, in the form it is written in the file (`// @Scaffold(Quest) - inherited from RestfulController<Quest>`), and clicking it goes to that annotation. A blank line separates the groups so they read like methods in the source. --- .../scaffold/ScaffoldInlayHintsProvider.java | 23 +++++++++++--- .../resources/messages/GrailsBundle.properties | 2 ++ .../scaffold/ScaffoldInlayHintsProviderTest.java | 36 +++++++++++++++++++--- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/plugin/src/main/java/org/apache/grails/intellij/plugin/feature/scaffold/ScaffoldInlayHintsProvider.java b/plugin/src/main/java/org/apache/grails/intellij/plugin/feature/scaffold/ScaffoldInlayHintsProvider.java index 03060ca..b0bc7fe 100644 --- a/plugin/src/main/java/org/apache/grails/intellij/plugin/feature/scaffold/ScaffoldInlayHintsProvider.java +++ b/plugin/src/main/java/org/apache/grails/intellij/plugin/feature/scaffold/ScaffoldInlayHintsProvider.java @@ -54,8 +54,9 @@ import java.util.List; * Shows what {@code @Scaffold} adds to a controller or service, since none of it is in the source: * {@code extends RestfulController<Quest>} after the class name, and the inherited methods as greyed * lines at the bottom of the class body - {@code def index(Integer max)}, {@code def show()}, ... - - * each a link to the method it inherits. A method the class declares itself is left out: it is in the - * source, with the platform's "overrides" marker in the gutter. + * each a link to the method it inherits, under a comment that names the annotation responsible and + * links back to it, with a blank line between methods. A method the class declares itself is left + * out: it is in the source, with the platform's "overrides" marker in the gutter. * * @see Scaffolding#inheritedMembers * @see ScaffoldStructureViewExtension @@ -105,12 +106,26 @@ public final class ScaffoldInlayHintsProvider implements InlayHintsProvider { int anchor = rBrace.getTextRange().getStartOffset(); String indent = indentUnit(clazz.getContainingFile()); String tooltip = GrailsBundle.message("inlay.scaffold.members.tooltip", baseText); + // A comment above each method names the annotation that put it there and links back to it. + String comment = indent + "// " + GrailsBundle.message("inlay.scaffold.members.comment", + info.anchor().getText(), baseText); + String commentTooltip = GrailsBundle.message("inlay.scaffold.members.comment.tooltip"); + InlayActionData annotationLink = navigateTo(info.anchor()); for (int i = 0; i < members.size(); i++) { PsiMethod member = members.get(i); String signature = indent + Scaffolding.signature(member, info); InlayActionData link = navigateTo(member); - // Higher vertical priority sits closer to the anchor line, so later members get higher values. - sink.addPresentation(new AboveLineIndentedPosition(anchor, i, 0), null, tooltip, FORMAT, builder -> { + // Higher vertical priority sits closer to the anchor line. Per method: a blank line, the + // comment, the method - so each group reads like a method in the source. + sink.addPresentation(new AboveLineIndentedPosition(anchor, 3 * i, 0), null, null, FORMAT, builder -> { + builder.text(" ", null); + return Unit.INSTANCE; + }); + sink.addPresentation(new AboveLineIndentedPosition(anchor, 3 * i + 1, 0), null, commentTooltip, FORMAT, builder -> { + builder.text(comment, annotationLink); + return Unit.INSTANCE; + }); + sink.addPresentation(new AboveLineIndentedPosition(anchor, 3 * i + 2, 0), null, tooltip, FORMAT, builder -> { builder.text(signature, link); return Unit.INSTANCE; }); diff --git a/plugin/src/main/resources/messages/GrailsBundle.properties b/plugin/src/main/resources/messages/GrailsBundle.properties index 3cc626b..30ac9e8 100644 --- a/plugin/src/main/resources/messages/GrailsBundle.properties +++ b/plugin/src/main/resources/messages/GrailsBundle.properties @@ -346,3 +346,5 @@ inlay.scaffold.name=Scaffolded members inlay.scaffold.description=Shows the superclass that @Scaffold gives a Grails controller or service, and the methods it inherits from it as greyed lines at the end of the class. inlay.scaffold.base.tooltip=Superclass set by @Scaffold at compile time inlay.scaffold.members.tooltip=Inherited from {0}. Declare a method with the same name to override it. +inlay.scaffold.members.comment={0} - inherited from {1} +inlay.scaffold.members.comment.tooltip=Go to the annotation that scaffolds this class diff --git a/plugin/src/test/java/org/apache/grails/intellij/plugin/feature/scaffold/ScaffoldInlayHintsProviderTest.java b/plugin/src/test/java/org/apache/grails/intellij/plugin/feature/scaffold/ScaffoldInlayHintsProviderTest.java index a12e9a3..a177d75 100644 --- a/plugin/src/test/java/org/apache/grails/intellij/plugin/feature/scaffold/ScaffoldInlayHintsProviderTest.java +++ b/plugin/src/test/java/org/apache/grails/intellij/plugin/feature/scaffold/ScaffoldInlayHintsProviderTest.java @@ -124,9 +124,22 @@ class Quest { """); } + /** The body hints come in threes per method - blank line, comment, method - after the inline "extends" hint. */ private static @NotNull List<String> bodyLines(@NotNull List<Hint> hints) { + return every(hints, 3); + } + + private static @NotNull List<String> commentLines(@NotNull List<Hint> hints) { + return every(hints, 2); + } + + private static @NotNull List<String> blankLines(@NotNull List<Hint> hints) { + return every(hints, 1); + } + + private static @NotNull List<String> every(@NotNull List<Hint> hints, int first) { List<String> lines = new ArrayList<>(); - for (Hint hint : hints.subList(1, hints.size())) lines.add(hint.text().strip()); + for (int i = first; i < hints.size(); i += 3) lines.add(hints.get(i).text().strip()); return lines; } @@ -157,15 +170,28 @@ class QuestController { "def patch()", "def update()", "def delete()"), bodyLines(hints)); - // One line per method, above the closing brace, in declaration order, indented like the class's own members + // Above every method, a comment naming the annotation that put it there, linking back to it, + // and a blank line separating it from what precedes + assertEquals(7, commentLines(hints).size()); + assertEquals("// @Scaffold(Quest) - inherited from RestfulController<Quest>", commentLines(hints).get(0)); + assertEquals("@Scaffold(Quest)", hints.get(2).targets().get(0).getText()); + assertEquals(List.of("", "", "", "", "", "", ""), blankLines(hints)); + + // Blank/comment/method triples above the closing brace, in declaration order, indented like the class's own members int rBrace = clazz.getBody().getRBrace().getTextRange().getStartOffset(); + assertEquals(1 + 3 * 7, hints.size()); for (int i = 1; i < hints.size(); i++) { AboveLineIndentedPosition position = (AboveLineIndentedPosition)hints.get(i).position(); assertEquals(rBrace, position.getOffset()); assertEquals(i - 1, position.getVerticalPriority()); - assertTrue(hints.get(i).text(), hints.get(i).text().startsWith(" def ")); + String expectedStart = switch (i % 3) { + case 1 -> " "; + case 2 -> " // "; + default -> " def "; + }; + assertTrue(hints.get(i).text(), hints.get(i).text().startsWith(expectedStart)); } - PsiMethod index = (PsiMethod)hints.get(1).targets().get(0); + PsiMethod index = (PsiMethod)hints.get(3).targets().get(0); assertEquals("index", index.getName()); assertEquals("grails.rest.RestfulController", index.getContainingClass().getQualifiedName()); } @@ -187,6 +213,8 @@ class QuestController { List<Hint> hints = hintsFor(controller); assertEquals(" extends RestfulServiceController<Quest>", hints.get(0).text()); + assertEquals("// @Scaffold(RestfulServiceController<Quest>) - inherited from RestfulServiceController<Quest>", + commentLines(hints).get(0)); assertEquals(List.of("def index(Integer max)", "def show()", "def create()", "def save()", "def edit()", "def patch()", "def update()", "def delete()"), bodyLines(hints));
