Skip to content

Commit a5d46f4

Browse files
committed
Handle procedure out of scope
Signed-off-by: Liam Barry Allan <mrliamallan@live.co.uk>
1 parent 2c770df commit a5d46f4

File tree

2 files changed

+65
-12
lines changed

2 files changed

+65
-12
lines changed

server/src/language/parser.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -690,12 +690,14 @@ export default class Parser {
690690

691691
case `END-PROC`:
692692
//Procedures can only exist in the global scope.
693-
currentItem = scopes[0].procedures.find(proc => proc.name === currentProcName);
693+
if (scopes.length > 1) {
694+
currentItem = scopes[0].procedures.find(proc => proc.name === currentProcName);
694695

695-
if (currentItem && currentItem.type === `procedure`) {
696-
currentItem.scope = scopes.pop();
697-
currentItem.range.end = lineNumber;
698-
resetDefinition = true;
696+
if (currentItem && currentItem.type === `procedure`) {
697+
currentItem.scope = scopes.pop();
698+
currentItem.range.end = lineNumber;
699+
resetDefinition = true;
700+
}
699701
}
700702
break;
701703

@@ -956,13 +958,15 @@ export default class Parser {
956958
scopes.push(new Cache());
957959
}
958960
} else {
959-
//Procedures can only exist in the global scope.
960-
currentItem = scopes[0].procedures.find(proc => proc.name === currentProcName);
961+
if (scopes.length > 1) {
962+
//Procedures can only exist in the global scope.
963+
currentItem = scopes[0].procedures.find(proc => proc.name === currentProcName);
961964

962-
if (currentItem && currentItem.type === `procedure`) {
963-
currentItem.scope = scopes.pop();
964-
currentItem.range.end = lineNumber;
965-
resetDefinition = true;
965+
if (currentItem && currentItem.type === `procedure`) {
966+
currentItem.scope = scopes.pop();
967+
currentItem.range.end = lineNumber;
968+
resetDefinition = true;
969+
}
966970
}
967971
}
968972
}
@@ -1150,7 +1154,9 @@ export default class Parser {
11501154
}
11511155
}
11521156

1153-
scopes[0].keyword = Parser.expandKeywords(keywords);
1157+
if (scopes.length > 0) {
1158+
scopes[0].keyword = Parser.expandKeywords(keywords);
1159+
}
11541160

11551161
const parsedData = scopes[0];
11561162

tests/suite/basics.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,53 @@ exports.issue_168 = async () => {
620620
`Return; `,
621621
].join(`\n`);
622622

623+
const parser = await parserSetup();
624+
const cache = await parser.getDocs(uri, lines);
625+
}
626+
627+
exports.issues_168a = async () => {
628+
const lines = [
629+
`**free`,
630+
`Ctl-opt datfmt(*iso) timfmt(*iso) alwnull(*usrctl) debug;`,
631+
``,
632+
`Dcl-F TESTFILE3 Keyed Usage(*Update :*Delete);`,
633+
``,
634+
`Dcl-Pr TESTCHAIN1 ExtPgm('TESTCHAIN1');`,
635+
`Parm1 Char(1);`,
636+
`End-Pr TESTCHAIN1;`,
637+
``,
638+
`Dcl-Pi TESTCHAIN1;`,
639+
`Parm1 Char(1);`,
640+
`End-Pi TESTCHAIN1;`,
641+
``,
642+
`Dcl-DS AAA;`,
643+
`a Char(10);`,
644+
`Dcl-ds a;`,
645+
`End-ds a;`,
646+
`End-Ds AAA;`,
647+
``,
648+
`If (Parm1 = 'N');`,
649+
`Chain ('CHIAVE' :1) TESTFILE3;`,
650+
`Else;`,
651+
`Chain ('CHIAVE' :1) TESTFILE3;`,
652+
`EndIf;`,
653+
``,
654+
`job_name = 'TESTFILE1';`,
655+
``,
656+
`Update TESTREC;`,
657+
``,
658+
`Return;`,
659+
``,
660+
`// ____________________________________________________________________________`,
661+
`Dcl-Proc aaa;`,
662+
``,
663+
`Dcl-Pi aaa;`,
664+
`end-proc;`,
665+
`End-Pi aaa;`,
666+
`// ____________________________________________________________________________`,
667+
``,
668+
`End-Proc aaa;`,
669+
].join(`\n`);
623670

624671
const parser = await parserSetup();
625672
const cache = await parser.getDocs(uri, lines);

0 commit comments

Comments
 (0)