This is an automated email from the ASF dual-hosted git repository.
jdaugherty pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/grails-intellij-plugin.git
The following commit(s) were added to refs/heads/main by this push:
new 73363d7 Correct node-label comments and pin the postprocess hook with
a decorator test (#439)
73363d7 is described below
commit 73363d7d413988cc6662677e7b22dff569e84197
Author: Aaron <[email protected]>
AuthorDate: Sun Oct 11 04:30:11 2026 -0400
Correct node-label comments and pin the postprocess hook with a decorator
test (#439)
Correct node-label comments and pin the postprocess hook with a decorator
test (#439)
Follow-up to #432. Corrects the comments, javadoc and AGENTS.md text that
describe how GrailsPsiDirectoryNode titles a directory, and adds a
regression test for the hook order.
- postprocess runs only on the updated presentation, from
PresentableNodeDescriptor.getUpdatedPresentation. It never labels the
template: PresentationData.applyFrom fills only null or empty fields.
- PsiDirectoryNode.updateImpl adds coloured fragments only when the
directory is a module content root and the file resolves to at least
one module. The no-modules fall-through needs
CodeInsightContexts.isSharedSourceSupportEnabled. Every other directory
gets setPresentableText from ProjectViewDirectoryHelper.getNodeName and
no fragments.
- The title write must stay in postprocess. AbstractPsiBasedNode.doUpdate
runs updateImpl, then the ProjectViewNodeDecorators, and postprocess
only afterwards. GradleModuleDirectoryDecorator rewrites content-root
fragments, so a title written in updateImpl would be restyled or
suffixed with [module].
testTitleSurvivesProjectViewDecorators registers a decorator shaped like
GradleModuleDirectoryDecorator's appendModuleName branch and asserts that
update() draws only the title. It fails if the write moves into
updateImpl.
Comments, documentation and tests only; no behavior change.
---
AGENTS.md | 20 ++++++++---
.../projectView/nodes/GrailsPsiDirectoryNode.java | 28 ++++++++++-----
.../impl/GrailsNodeProviderTestSupport.java | 16 ++++++---
.../nodes/GrailsPsiDirectoryNodeTest.java | 42 +++++++++++++++++++---
4 files changed, 84 insertions(+), 22 deletions(-)
diff --git a/AGENTS.md b/AGENTS.md
index 77fe0db..aaf689b 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -162,16 +162,26 @@ both ordinary directories and module content roots, which
the platform presents
**Module content-root labels use coloured fragments; ordinary directories use
`presentableText`.**
In platform 262.10315.125, `PsiDirectoryNode.updateImpl` adds coloured
fragments only when
-`ProjectRootsUtil.isModuleContentRoot` is true. For other directories it calls
`setPresentableText`
-with the name from `ProjectViewDirectoryHelper.getNodeName`, which can be
qualified (`grails-app.i18n`).
+`ProjectRootsUtil.isModuleContentRoot` is true *and* the file resolves to at
least one module; a content
+root that resolves to none falls through to the `presentableText` path too.
That fall-through needs shared
+source support (`CodeInsightContexts.isSharedSourceSupportEnabled`) to be
possible, because without it
+`modules` is the singleton list of `fi.getModuleForFile(file)` and can never
be empty. For those
+directories it calls `setPresentableText` with the name from
`ProjectViewDirectoryHelper.getNodeName`,
+which can be qualified (`grails-app.i18n`).
Gradle's per-source-set modules make `src/test` a module content root, so its
label can be
`test [app.test]` in fragments. The renderer prefers a non-empty fragment list
over `presentableText`;
setting only the latter to `Tests:unit` leaves the content-root label visible.
-`GrailsPsiDirectoryNode.postprocess` replaces any fragments and sets
`presentableText` on both
-the updated presentation and the template, keeping custom titles consistent
for both kinds of directory.
+`GrailsPsiDirectoryNode.postprocess` replaces any fragments and sets
`presentableText`, keeping custom
+titles consistent for both kinds of directory. `postprocess` is required, not
optional: every
+`ProjectViewNodeDecorator` runs between `updateImpl` and `postprocess`, and in
Gradle projects
+`GradleModuleDirectoryDecorator` rewrites content-root fragments (bolding the
first fragment for a
+source-set module, and relabelling to `"<presentableText> [moduleName]"` when
the source-set name
+differs from the directory name), so a title written in `updateImpl` would be
restyled or suffixed.
**Tests must include `postprocess` and inspect the fragments when present.**
Run `update()` then
-read `getPresentation()` — or call `updateImpl` and then `postprocess` — to
see the final custom title.
+read `getPresentation()` to see the final custom title. Calling `updateImpl`
and then `postprocess`
+directly skips the decorators that run between them, so use that only to
assert the platform's
+fragments before the title replaces them, as
`testTitleReplacesTheModuleContentRootFragments` does.
Asserting only `presentableText` misses a stale fragment list that the
renderer would prefer.
A test that passes both with and without a labelling fix is not covering it:
verify by reverting
the fix and watching the test fail.
diff --git
a/plugin/src/main/java/org/apache/grails/intellij/plugin/projectView/nodes/GrailsPsiDirectoryNode.java
b/plugin/src/main/java/org/apache/grails/intellij/plugin/projectView/nodes/GrailsPsiDirectoryNode.java
index bf35281..d507169 100644
---
a/plugin/src/main/java/org/apache/grails/intellij/plugin/projectView/nodes/GrailsPsiDirectoryNode.java
+++
b/plugin/src/main/java/org/apache/grails/intellij/plugin/projectView/nodes/GrailsPsiDirectoryNode.java
@@ -104,15 +104,27 @@ public class GrailsPsiDirectoryNode extends
PsiDirectoryNode {
}
/**
- * {@code PsiDirectoryNode.updateImpl} adds coloured fragments for module
content roots; ordinary
- * directories use {@code setPresentableText}, including qualified names
such as {@code grails-app.i18n}.
- * Gradle's per-source-set modules make {@code src/test} a content root,
whose fragments can render as
- * {@code test [app.test]}. The renderer prefers those fragments over {@code
presentableText}, so
- * setting only the latter to {@code Tests:unit} does not change that
content-root label.
+ * {@code PsiDirectoryNode.updateImpl} adds coloured fragments only when the
directory is a module
+ * content root ({@code ProjectRootsUtil.isModuleContentRoot}) and the file
resolves to at least one
+ * module. Gradle's per-source-set modules make {@code src/test} one, so it
arrives carrying fragments
+ * that can render as {@code test [app.test]}, and the renderer prefers
those over
+ * {@code presentableText} — setting only the latter to {@code Tests:unit}
leaves the content-root
+ * label visible.
*
- * <p>{@code postprocess} applies the custom title to both the updated
presentation and the template.
- * Replacing any platform fragments and setting {@code presentableText}
keeps the title consistent
- * for both content roots and ordinary directories.
+ * <p>For every other directory the platform calls {@code
setPresentableText} and adds no fragments at
+ * all, so the qualified name such as {@code grails-app.i18n} comes from
+ * {@code ProjectViewDirectoryHelper.getNodeName} through that field, not
from a fragment. That is why
+ * the Views, Configuration and Initialization titles always rendered
without this hook. Do not go
+ * looking for directory-name fragments on a nested directory: there are
none.
+ *
+ * <p>Replacing any platform fragments and setting {@code presentableText}
keeps the title consistent
+ * for both content roots and ordinary directories. The write has to stay in
{@code postprocess} and
+ * cannot move into {@code updateImpl}: every {@code
ProjectViewNodeDecorator} runs in between, and in
+ * a Gradle project {@code GradleModuleDirectoryDecorator} rewrites
content-root fragments — bolding
+ * the first fragment for a source-set module, and relabelling to
+ * {@code "<presentableText> [moduleName]"} when the source-set name differs
from the directory name. A
+ * title written in {@code updateImpl} would come out restyled or suffixed,
so only this hook, which
+ * runs after the decorators, leaves the label final.
*/
@Override
protected void postprocess(@NotNull PresentationData data) {
diff --git
a/plugin/src/test/java/org/apache/grails/intellij/plugin/projectView/impl/GrailsNodeProviderTestSupport.java
b/plugin/src/test/java/org/apache/grails/intellij/plugin/projectView/impl/GrailsNodeProviderTestSupport.java
index 46dd95a..833f3da 100644
---
a/plugin/src/test/java/org/apache/grails/intellij/plugin/projectView/impl/GrailsNodeProviderTestSupport.java
+++
b/plugin/src/test/java/org/apache/grails/intellij/plugin/projectView/impl/GrailsNodeProviderTestSupport.java
@@ -98,13 +98,19 @@ public abstract class GrailsNodeProviderTestSupport extends
GrailsTestCase {
}
/**
- * Reads a node the way the renderer does: {@code updateImpl} then {@code
postprocess}. The second call
- * matters, because {@code PsiDirectoryNode} writes the directory name into
the presentation during
- * {@code updateImpl} and {@code GrailsPsiDirectoryNode} only replaces it
afterwards.
+ * Reads a node the way the renderer does: {@code updateImpl}, then the
project-view decorators, then
+ * {@code postprocess}. Going through {@code update()} matters for both
steps, not just the last one,
+ * because the decorators sit between the two hooks and can rewrite what
{@code updateImpl} wrote. The
+ * {@code postprocess} call matters too, because {@code PsiDirectoryNode}
writes the directory name into
+ * the presentation during {@code updateImpl} — as coloured fragments when
the directory is a module
+ * content root, and otherwise via {@code setPresentableText}, taking the
qualified name from
+ * {@code ProjectViewDirectoryHelper.getNodeName} — and {@code
GrailsPsiDirectoryNode} only replaces it
+ * afterwards.
*/
protected static @NotNull PresentationData rendered(@NotNull
GrailsPsiDirectoryNode node) {
- // update() runs updateImpl and then postprocess, which is the sequence
the renderer sees; getPresentation()
- // then returns that result. postprocess is protected, so it cannot be
called from this package directly.
+ // update() runs updateImpl, then the project-view decorators, then
postprocess, which is the sequence the
+ // renderer sees; getPresentation() then returns that result. postprocess
is protected, so it cannot be
+ // called from this package directly.
node.update();
return node.getPresentation();
}
diff --git
a/plugin/src/test/java/org/apache/grails/intellij/plugin/projectView/nodes/GrailsPsiDirectoryNodeTest.java
b/plugin/src/test/java/org/apache/grails/intellij/plugin/projectView/nodes/GrailsPsiDirectoryNodeTest.java
index d91d742..27ae57e 100644
---
a/plugin/src/test/java/org/apache/grails/intellij/plugin/projectView/nodes/GrailsPsiDirectoryNodeTest.java
+++
b/plugin/src/test/java/org/apache/grails/intellij/plugin/projectView/nodes/GrailsPsiDirectoryNodeTest.java
@@ -21,11 +21,13 @@ package org.apache.grails.intellij.plugin.projectView.nodes;
import com.intellij.icons.AllIcons;
import com.intellij.ide.projectView.PresentationData;
+import com.intellij.ide.projectView.ProjectViewNodeDecorator;
import com.intellij.ide.projectView.ViewSettings;
import com.intellij.openapi.roots.ModuleRootModificationUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiManager;
+import com.intellij.ui.SimpleTextAttributes;
import org.jetbrains.annotations.NotNull;
import org.apache.grails.intellij.lib.testFramework.GrailsTestCase;
import org.apache.grails.intellij.plugin.projectView.NodeWeights;
@@ -47,10 +49,16 @@ public class GrailsPsiDirectoryNodeTest extends
GrailsTestCase {
}
/**
- * Gradle's per-source-set modules make test directories module content
roots. Only content roots
- * receive the platform's coloured fragments, which take precedence over
{@code presentableText}.
- * Register the directory accordingly and verify that the platform adds
fragments before our title
- * replaces them, reproducing the case where a test root failed to render as
{@code Tests:unit}.
+ * Gradle's per-source-set modules make test directories module content
roots, and only content roots
+ * receive the platform's coloured fragments, which take precedence over
{@code presentableText}. Every
+ * other directory is labelled by {@code setPresentableText} from
+ * {@code ProjectViewDirectoryHelper.getNodeName} and gets no fragments,
which is why a nested directory
+ * like {@code grails-app/i18n} has nothing for this hook to replace.
+ *
+ * <p>So the directory is registered as a content entry: that is what makes
the platform write its
+ * fragments first, reproducing the case where a test root failed to render
as {@code Tests:unit}. The
+ * assertions below cover both halves — that the platform's own fragments
are present beforehand, and
+ * that the title replaces them.
*/
public void testTitleReplacesTheModuleContentRootFragments() {
PsiDirectory directory =
findDirectoryCreatedBy("src/test/ExampleSpec.groovy");
@@ -74,6 +82,32 @@ public class GrailsPsiDirectoryNodeTest extends
GrailsTestCase {
assertEquals("src/test", data.getLocationString());
}
+ /**
+ * The point of the decorator is to prove the title survives the decorator
pass, since the write happens
+ * after it. This one is shaped like {@code
GradleModuleDirectoryDecorator}'s {@code appendModuleName}
+ * branch, which rewrites a module content root's label to {@code
"<presentableText> [moduleName]"} with
+ * the suffix in bold. A title written in {@code updateImpl} would be
restyled that way and render as
+ * {@code "Tests:unit [app.test]"}, so this catches a later refactor moving
the write earlier.
+ */
+ public void testTitleSurvivesProjectViewDecorators() {
+ PsiDirectory directory =
findDirectoryCreatedBy("src/test/ExampleSpec.groovy");
+ ModuleRootModificationUtil.updateModel(getModule(), model ->
model.addContentEntry(directory.getVirtualFile()));
+ ProjectViewNodeDecorator gradleLike = (node, data) -> {
+ String name = data.getPresentableText();
+ data.clearText();
+ data.addText(name + " ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
+ data.addText("[app.test]", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
+ };
+
getProject().getExtensionArea().getExtensionPoint("com.intellij.projectViewNodeDecorator")
+ .registerExtension(gradleLike, getTestRootDisposable());
+ GrailsPsiDirectoryNode node = new GrailsPsiDirectoryNode(directory,
ViewSettings.DEFAULT, null,
+
NodeWeights.TESTS_FOLDER, "Tests:unit", null, "src/test");
+
+ node.update();
+
+ assertEquals(List.of("Tests:unit"),
drawnFragments(node.getPresentation()));
+ }
+
/** An untitled node keeps the platform's own fragments, so nothing is lost
by not clearing them. */
public void testWithoutCustomPresentationKeepsPlatformFragments() {
PsiDirectory directory =
findDirectoryCreatedBy("src/test/ExampleSpec.groovy");