codefori / vscode-rpgle

RPGLE language tools for VS Code
MIT License
39 stars 20 forks source link

Linter using the wrong procedure for linting #326

Closed EVLSDE closed 3 weeks ago

EVLSDE commented 1 month ago

Describe the bug If you use a copybook to define procedure prototypes, you'll most likely end up having "No reference to definition" errors on definitions in an rpg source using said copybook, even if the definitions are actually being used.

To Reproduce Create a copybook with a prototype definition on a specific line range (e.g. 8-12). Use said copybook in an rpg source, define a field and use it once. If either the definition or the usage of said field is in the line range of our prototype definition in the copybook, then the definition will be marked as unused. It's not important if the prototype is actually being used in the copybook/rpg source or not. If you move the prototype definition to another line range which doesn't interfere with the field definition and usage (e.g. 14-18), the "no reference" warning disappears.

Example copybook:

**free
// empty line
// empty line
// empty line
// empty line 
// empty line
// Some prototype
dcl-pr SomePrototype;
  Parameter1 char(1);
  Parameter2 char(1);
  Parameter3 char(1);
end-pr;

Example rpg source:

**free
ctl-opt main(Main);
/copy 'QCPYLESRC/somecopybook.rpgle'
// --
dcl-proc Main;
  dcl-pi *n;
  end-pi;

  dcl-s SomeFlag ind inz(*off);

  SomeFlag = *on; 
end-proc;

Expected behavior The linter should not be marking the definition as "No reference to definition." if it's actually being used.

Screenshots See example code given above

Environment

Additional context I found that while looping through statements, the linter assigns the wrong currentProcedure (it's using the prototype "SomePrototype" instead of the actual "Main" procedure). Similar to #323, the corresponding .find statement shoud be extended with "&& data.uri === proc.position.path". When trying to assign "defRef", you first check on currentProcedure scope and subItems before trying to check via globalScope. If currentProcedure isn't the procedure containing the actual definition, then you wont find the defRef there. And somehow globalScope never seems to find anything in my case. This leads the linter to not adding every reference to a definition.

As some of our (service) programs are using multiple copybooks with up to 2-3k lines, those rpg sources are flooded with "no reference" warnings and most of them are gone with this change.

worksofliam commented 4 weeks ago

@EVLSDE I just released 0.26.11 which might fix this problem.