Skip to content

Commit

Permalink
fix: Fix node position for implicit dialects
Browse files Browse the repository at this point in the history
  • Loading branch information
Nurkambay committed Jul 3, 2024
1 parent 0cbeb42 commit 7f7c21a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ private void addDialectsNode(AnalysisContext context, Node rootNode) {
dialectNode.getLocality().getUri(),
dialectNode.getLocality().getRange().getStart());

Node node = nodeByPosition.orElse(rootNode);
addChild(node, dialectNode);
addChild(nodeByPosition.orElse(rootNode), dialectNode);
}
}

Expand All @@ -109,6 +108,7 @@ private void addChild(Node node, Node dialectNode) {
}
index++;
}
dialectNode.setParent(node);
node.getChildren().add(index, dialectNode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.lsp.cobol.common.model.NodeType;
import org.eclipse.lsp.cobol.common.model.tree.Node;
import org.eclipse.lsp.cobol.implicitDialects.cics.nodes.ExecCicsHandleNode;
import org.eclipse.lsp.cobol.test.CobolText;
import org.eclipse.lsp.cobol.test.engine.UseCaseEngine;
import org.junit.jupiter.api.Test;

Expand All @@ -32,12 +33,24 @@ class TestImplicitDialectsPosition {
+ " PROGRAM-ID. CBACT01C.\n"
+ " PROCEDURE DIVISION.\n"
+ " IF 2 > 1 THEN\n"
+ " EXEC CICS HANDLE ABEND LABEL(HANDLE-ABEND)\n"
+ " EXEC CICS HANDLE ABEND LABEL({#HANDLE-ABEND})\n"
+ " END-EXEC.\n"
+ " GO TO {#HANDLE-ABEND}\n"
+ " END-IF.\n"
+ " {#*HANDLE-ABEND}.\n";

private static final String TEXT_WITH_COPY = " IDENTIFICATION DIVISION.\n"
+ " PROGRAM-ID. CBACT01C.\n"
+ " PROCEDURE DIVISION.\n"
+ " IF 2 > 1 \n"
+ " PERFORM {#HANDLE-ABEND}\n"
+ " COPY {~COPY1}.\n"
+ " DISPLAY '1'\n"
+ " END-IF.\n"
+ " {#*HANDLE-ABEND}.\n";

private static final String COPY1 = " EXEC CICS HANDLE ABEND LABEL({#HANDLE-ABEND}) END-EXEC\n";

@Test
void test() {
AnalysisResult result = UseCaseEngine.runTest(TEXT, ImmutableList.of(), ImmutableMap.of());
Expand All @@ -50,4 +63,20 @@ void test() {
Node execCicsNode = ifNode.getChildren().get(2);
assertTrue(execCicsNode instanceof ExecCicsHandleNode);
}

@Test
void testCopy() {
AnalysisResult result = UseCaseEngine.runTest(TEXT_WITH_COPY,
ImmutableList.of(new CobolText("COPY1", COPY1)),
ImmutableMap.of());
Node ifNode = result.getRootNode().getDepthFirstStream()
.filter(n -> n.getNodeType() == NodeType.IF)
.findFirst()
.orElse(null);

assertNotNull(ifNode);
Node execCicsNode = ifNode.getChildren().get(3);
assertTrue(execCicsNode instanceof ExecCicsHandleNode);
}

}

0 comments on commit 7f7c21a

Please sign in to comment.