[go] GO-19392 add an assertion to tests for the Go parser that validates the structural identity between the light AST and PSI

This check is important to be sure that the Go parser produces same AST structure (`ASTNode`) in PSI as in case of light AST structure (`LigherASTNode`). It defends us against the theoretical inconsistency when a lazy element is mishandled: for example, the light tree stores flat state, but PSI tree parses deeper. Some other cases also possible.


(cherry picked from commit 9a869a2a8cb8aef9a3b9442e9522cdd351d1295f)

IJ-MR-181621

GitOrigin-RevId: 84c3edcc9b659c93df711640bdae9441f1462faa
This commit is contained in:
Maksim Chechulnikov
2025-11-08 01:04:24 +00:00
committed by intellij-monorepo-bot
parent 5b99de873e
commit 4a2ccaeefa
2 changed files with 30 additions and 6 deletions
+2
View File
@@ -168,6 +168,8 @@ f:com.intellij.psi.ExternalChangeActionUtil
com.intellij.psi.impl.AnyPsiChangeListener
- afterPsiChanged(Z):V
- beforePsiChanged(Z):V
f:com.intellij.psi.impl.DebugUtil
- s:lightTreeAsElementTypeToString(com.intellij.util.diff.FlyweightCapableTreeStructure,Z):java.lang.String
com.intellij.psi.impl.PsiDocumentTransactionListener
- sf:TOPIC:com.intellij.util.messages.Topic
- transactionCompleted(com.intellij.openapi.editor.Document,com.intellij.psi.PsiFile):V
@@ -221,7 +221,13 @@ public final class DebugUtil {
public static @NotNull String lightTreeToString(@NotNull FlyweightCapableTreeStructure<LighterASTNode> tree, boolean showWhitespaces) {
StringBuilder buffer = new StringBuilder();
lightTreeToBuffer(tree, tree.getRoot(), buffer, 0, showWhitespaces);
lightTreeToBuffer(tree, tree.getRoot(), buffer, 0, showWhitespaces, true);
return buffer.toString();
}
public static @NotNull String lightTreeAsElementTypeToString(@NotNull FlyweightCapableTreeStructure<LighterASTNode> tree, boolean showWhitespaces) {
StringBuilder buffer = new StringBuilder();
lightTreeToBuffer(tree, tree.getRoot(), buffer, 0, showWhitespaces, false);
return buffer.toString();
}
@@ -229,7 +235,8 @@ public final class DebugUtil {
@NotNull LighterASTNode node,
Appendable buffer,
int indent,
boolean showWhitespaces) {
boolean showWhitespaces,
boolean showPsiElements) {
IElementType tokenType = node.getTokenType();
if (!showWhitespaces && tokenType == TokenType.WHITE_SPACE) return;
@@ -238,13 +245,28 @@ public final class DebugUtil {
StringUtil.repeatSymbol(buffer, ' ', indent);
try {
if (tokenType == TokenType.ERROR_ELEMENT) {
buffer.append("PsiErrorElement:").append(PsiBuilderImpl.getErrorMessage(node));
if (showPsiElements) {
buffer.append("PsiErrorElement:").append(PsiBuilderImpl.getErrorMessage(node));
}
else {
buffer.append(tokenType.toString()).append(":").append(PsiBuilderImpl.getErrorMessage(node));
}
}
else if (tokenType == TokenType.WHITE_SPACE) {
buffer.append("PsiWhiteSpace");
if (showPsiElements) {
buffer.append("PsiWhiteSpace");
}
else {
buffer.append(tokenType.toString());
}
}
else {
buffer.append(isLeaf ? "PsiElement" : "Element").append('(').append(tokenType.toString()).append(')');
if (showPsiElements) {
buffer.append(isLeaf ? "PsiElement" : "Element").append('(').append(tokenType.toString()).append(')');
}
else {
buffer.append(tokenType.toString());
}
}
if (isLeaf) {
@@ -262,7 +284,7 @@ public final class DebugUtil {
}
else {
for (int i = 0; i < numKids; i++) {
lightTreeToBuffer(tree, kids.get()[i], buffer, indent + 2, showWhitespaces);
lightTreeToBuffer(tree, kids.get()[i], buffer, indent + 2, showWhitespaces, showPsiElements);
}
}
}