Skip to content

Commit

Permalink
Include array access in extract subroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusAmshove committed Sep 7, 2023
1 parent a75a428 commit f2934c0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.amshove.natls.DiagnosticOriginalUri;
import org.amshove.natparse.IDiagnostic;
import org.amshove.natparse.IPosition;
import org.amshove.natparse.NodeUtil;
import org.amshove.natparse.lexing.SyntaxToken;
import org.amshove.natparse.natural.INaturalModule;
import org.amshove.natparse.natural.ISyntaxNode;
Expand Down Expand Up @@ -102,7 +103,7 @@ public static Range toRange(SyntaxToken token)
public static Range toRange(ISyntaxNode node)
{
var firstNode = node.descendants().first();
var lastNode = node.descendants().last();
var lastNode = NodeUtil.deepFindLeaf(node.descendants().last());
return new Range(
new Position(firstNode.position().line(), firstNode.position().offsetInLine()),
new Position(lastNode.position().line(), lastNode.position().offsetInLine() + lastNode.position().length())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,37 @@ void extractASubroutineFromASingleStatementWhenCursorIsNotOnWholeStatement()
""");
}

@Test
void notForgetToExtractArrayAccesses()
{
assertCodeActionWithTitle(
"Extract inline subroutine", "LIBONE", "SUBN.NSN",
"""
DEFINE DATA LOCAL
1 #ARR (A10/*)
END-DEFINE
#A${R}$R(2) := #ARR(1)
END
"""
)
.resultsApplied("""
DEFINE DATA LOCAL
1 #ARR (A10/*)
END-DEFINE
PERFORM EXTRACTED
/***********************************************************************
DEFINE SUBROUTINE EXTRACTED
/***********************************************************************
#ARR(2) := #ARR(1)
END-SUBROUTINE
END
""");
}

@Test
void extractASubroutineFromMultipleStatements()
{
Expand Down

0 comments on commit f2934c0

Please sign in to comment.