anzwdev / al-code-outline

AL Code Outline for Visual Studio Code
MIT License
51 stars 13 forks source link

Code Cleanup issue #546

Open fvet opened 5 months ago

fvet commented 5 months ago

When I ran the code cleanup on below sample code, the file was wrongfully (?) replacing the global variable with Rec.PK, resulting in invalid code.

image

I could easily solve above case by renaming the global variable, but I'm not sure if this was the only file impacted.

Is this something that can be improved in the cleanup actions? Or maybe this could be a valid scenario for @arthurvdv to include in https://github.com/StefanMaron/BusinessCentral.LinterCop as possible new rule?

anzwdev commented 5 months ago

It is caused by RemoveWithStatements command. It removes both implicit and explicit cases, but to be able to do it, it needs to compile project with "NoImplicitWith" "feature" disabled. Only this way compiler can detect variables that are Rec fields, but unfortunately this setting changes priorities and Rec fields are hiding variables of the same name.

With disabled "NoImplicitWith" feature compiler pretends that every function and trigger in a table/page starts with invisible "with Rec do begin....". I am thinking about splitting this functionality into 2 separate sets of commands - remove implicit with and remove explicit with. Explicit version will use current settings from app.json and will work correctly, but for "implicit" version it will always run with "NoImplicitWith" feature disabled.