Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions language/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export default class Parser {

const scanScopeForReferences = () => {
for (const procedure in postProcessingStatements) {
const currentProcedure = scopes[0].procedures.find(proc => proc.name === procedure) ;
const currentProcedure = scopes[0].findDefinition(lineNumber, procedure);
const statements = postProcessingStatements[procedure];
for (const statement of statements) {
collectReferences(fileUri, statement, currentProcedure);
Expand Down Expand Up @@ -1743,7 +1743,7 @@ export default class Parser {
}

if (options.collectReferences && tokens.length > 0) {
const currentProc = scopes[0].procedures.find(proc => proc.name === currentProcName);
const currentProc = currentProcName ? scopes[0].findDefinition(lineNumber, currentProcName) : undefined;
collectReferences(fileUri, tokens, currentProc, currentItem);
addPostProcessingStatements(currentProcName, tokens);
}
Expand Down
22 changes: 22 additions & 0 deletions tests/rpgle/empdet.rpgleinc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
**free

dcl-ds employee_detail_t qualified template;
found ind;
name varchar(50);
netincome packed(9:2);
end-ds;

dcl-ds department_detail_t qualified template;
found ind;
deptname varchar(50);
location varchar(50);
totalsalaries packed(9:2);
end-ds;

dcl-pr getDeptDetail like(department_detail_t) extproc('GETDEPTDETAIL');
deptno char(3) const;
end-pr;

dcl-pr getEmployeeDetail like(employee_detail_t) extproc('GETEMPLOYEEDETAIL');
empno char(6) const;
end-pr;
48 changes: 48 additions & 0 deletions tests/suite/references.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1988,4 +1988,52 @@ test('references_prototype', async () => {
expect(protoTypeData).toBeDefined();
expect(protoTypeData.type).toMatchObject({name: `int`, value: `10`});
expect(protoTypeData.reference).toBeUndefined();
});

test('references in procedure', async () => {
const lines = [
`**free`,
``,
`/copy './rpgle/empdet.rpgleinc'`,
``,
`dcl-proc getDeptDetail export;`,
` dcl-pi *n like(department_detail_t);`,
` deptno char(3) const;`,
` end-pi;`,
``,
` dcl-ds department_detail likeds(department_detail_t);`,
``,
` exec sql`,
` select`,
` rtrim(deptname),`,
` coalesce(location, 'N/A'),`,
` (select sum(salary + bonus + comm)`,
` from employee`,
` where workdept = :deptno)`,
` into`,
` :department_detail.deptname,`,
` :department_detail.location,`,
` :department_detail.totalsalaries`,
` from`,
` department`,
` where`,
` deptno = :deptno;`,
``,
` if (sqlcode = 0);`,
` department_detail.found = *on;`,
` else;`,
` department_detail.found = *off;`,
` endif;`,
``,
` return department_detail;`,
`end-proc;`,
].join(`\n`);

const cache = await parser.getDocs(uri, lines, { ignoreCache: true, withIncludes: true, collectReferences: true });
const getDeptDetail = cache.find(`getDeptDetail`);
expect(getDeptDetail).toBeDefined();

const department_detail = getDeptDetail.scope.find(`department_detail`);
expect(department_detail).toBeDefined();
expect(department_detail.references.length).toBe(7);
});