Skip to content

Commit

Permalink
fix: Fix PERFORM node position
Browse files Browse the repository at this point in the history
  • Loading branch information
Nurkambay committed Aug 8, 2024
1 parent bf85ebd commit e19f56f
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.lsp.cobol.cfg.CFASTBuilder;
import org.eclipse.lsp.cobol.cli.di.CliModule;
import org.eclipse.lsp.cobol.common.dialects.CobolLanguageId;
import org.eclipse.lsp.cobol.common.model.Locality;
import org.eclipse.lsp.cobol.common.model.tree.Node;
import org.eclipse.lsp.cobol.common.pipeline.StageResult;
import org.eclipse.lsp.cobol.dialects.ibm.ProcessingResult;
Expand Down Expand Up @@ -80,6 +81,7 @@ private void generateCFAST(File file, CFASTBuilder builder, Gson gson, Injector
Cli.Result analysisResult = parent.runAnalysis(file.getCanonicalFile(), CobolLanguageId.COBOL, diCtx, true);
StageResult<ProcessingResult> result = (StageResult<ProcessingResult>) analysisResult.pipelineResult.getLastStageResult();
Node rootNode = result.getData().getRootNode();
rootNode.getDepthFirstStream().forEach(this::updateLocality);

String json = gson.toJson(builder.build(rootNode).getControlFlowAST());

Expand All @@ -93,6 +95,13 @@ private void generateCFAST(File file, CFASTBuilder builder, Gson gson, Injector
}
}

private void updateLocality(Node node) {
Locality locality = node.getLocality();
String uri = locality.getUri();
int index = Math.max(0, uri.lastIndexOf("/"));
locality.setUri(uri.substring(index));
}

private static boolean isCobolFile(File file) {
return "cbl".equals(Files.getFileExtension(file.getAbsolutePath()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,11 @@ public List<Node> visitPerformProcedureStatement(PerformProcedureStatementContex
final ProcedureName thruName = parseProcedureName(Optional.ofNullable(ctx.through())
.map(ThroughContext::procedureName)
.orElse(null));
return addTreeNode(ctx, locality -> new PerformNode(locality, targetName, thruName));

List<Node> children = visitChildren(ctx);
return retrieveLocality(ctx.getParent().getParent())
.map(constructNode(locality -> new PerformNode(locality, targetName, thruName), children))
.orElse(children);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ void testPerformThru() {
assertEquals("SEC1", perform.getTarget().getInSection());
assertEquals("EP", perform.getThru().getName());
assertEquals("SEC2", perform.getThru().getInSection());
assertEquals(3, perform.getLocality().getRange().getStart().getLine());
assertEquals(11, perform.getLocality().getRange().getStart().getCharacter());
assertEquals(45, perform.getLocality().getRange().getEnd().getCharacter());
}

}
2 changes: 1 addition & 1 deletion server/engine/src/test/resources/cfast/case4.result.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"uri": "fake/path",
"start": {
"line": 20,
"character": 20
"character": 12
},
"end": {
"line": 20,
Expand Down
2 changes: 1 addition & 1 deletion server/engine/src/test/resources/cfast/case46.result.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"uri": "fake/path",
"start": {
"line": 29,
"character": 29
"character": 21
},
"end": {
"line": 29,
Expand Down
2 changes: 1 addition & 1 deletion server/engine/src/test/resources/cfast/case5.result.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"uri": "fake/path",
"start": {
"line": 21,
"character": 20
"character": 12
},
"end": {
"line": 21,
Expand Down
2 changes: 1 addition & 1 deletion server/engine/src/test/resources/cfast/case7.result.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"uri": "fake/path",
"start": {
"line": 16,
"character": 20
"character": 12
},
"end": {
"line": 16,
Expand Down
2 changes: 1 addition & 1 deletion server/engine/src/test/resources/cfast/case8.result.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"uri": "fake/path",
"start": {
"line": 16,
"character": 20
"character": 12
},
"end": {
"line": 16,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"uri": "fake/path",
"start": {
"line": 29,
"character": 20
"character": 12
},
"end": {
"line": 29,
Expand Down
6 changes: 3 additions & 3 deletions server/engine/src/test/resources/cfast/case_merge.result.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
"uri": "fake/path",
"start": {
"line": 47,
"character": 20
"character": 12
},
"end": {
"line": 47,
Expand Down Expand Up @@ -226,7 +226,7 @@
"uri": "fake/path",
"start": {
"line": 50,
"character": 20
"character": 12
},
"end": {
"line": 50,
Expand Down Expand Up @@ -275,7 +275,7 @@
"uri": "fake/path",
"start": {
"line": 55,
"character": 20
"character": 12
},
"end": {
"line": 55,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"uri": "fake/path",
"start": {
"line": 16,
"character": 20
"character": 12
},
"end": {
"line": 16,
Expand Down
6 changes: 3 additions & 3 deletions server/engine/src/test/resources/cfast/case_sort.result.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
"uri": "fake/path",
"start": {
"line": 47,
"character": 20
"character": 12
},
"end": {
"line": 47,
Expand Down Expand Up @@ -246,7 +246,7 @@
"uri": "fake/path",
"start": {
"line": 50,
"character": 20
"character": 12
},
"end": {
"line": 50,
Expand Down Expand Up @@ -295,7 +295,7 @@
"uri": "fake/path",
"start": {
"line": 55,
"character": 20
"character": 12
},
"end": {
"line": 55,
Expand Down

0 comments on commit e19f56f

Please sign in to comment.