DavidFeldhoff / al-codeactions

MIT License
17 stars 8 forks source link

Randomly get variant parameters when creating procedures or events #136

Closed jwikman closed 2 years ago

jwikman commented 2 years ago

Hi David,

I really love the feature for creating stubs for missing events and procedures!

But sometimes I get Variant parameters instead of the actual datatype, and I just cannot get my head around when this happens. It feels random, but I assume that it is not...

Instead of this: internal procedure OnAfterMyEvent(pMyRecord Record "My Table"; pMyOtherRecord Record "My Other Table"; FirstBool: Boolean; SecondBool: Boolean)

I get this: internal procedure OnAfterMyEvent(arg1: Variant; arg2: Variant; arg3: Variant; arg4: Variant)

Sometimes I even get internal procedure OnAfterMyEvent(pMyRecord Record "My Table"; arg1: Variant; arg2: Variant; arg3: Variant)

One procedure did not work yesterday, so I just uncommented the line to dive into later. Today the very same procedure worked one time, but when I deleted the created procedure and recreated it I got arg1: Variant parameters again 😕

Any idea on what is happening?

DavidFeldhoff commented 2 years ago

Hi Johannes, "nice seeing you here (again) and thanks for contributing" - to quote a good developer ;)

Honestly I don't know at the first moment why that could happen. I have to dig a bit deeper into the code. Maybe I can make it on Sunday, but no promises. Furthermore I don't know if I can find the issue by just guessing what could happen..

Maybe another approach could be that I'm going to focus on activating application insights instead and track the procedure call together with the declared variables everytime a parameter was recognized as variant (which shouldn't happen). Just to find out what's going on. Thats a thing I wanted to do anyway a long time ago and it could save you and me a bit of research (besides other advantages). After I saw your issue I've already put some effort into getting AppInsights ready and after a first successful prototype I guess I will continue going this way. If you then encounter these "random issues" I hope I have you covered and can see what's going wrong.

jwikman commented 2 years ago

Good evening David,

That sounds as a very good approach. That’s a nice thing to have implemented anyway. 👍

I’ll see if I get the time to debug this myself later, probably next week. Let’s see who figures out the cause first! 😜

I hope you’ll get a great weekend!

jwikman commented 2 years ago

Now I found out what caused this!

After some digging I noticed that you are parsing the hover text to figure out the datatypes and that gave me a clue... I changed my GitLens settings the other night and that caused this issue.

I had this configured in my settings:

    "gitlens.hovers.currentLine.over": "line",
    "gitlens.hovers.currentLine.enabled": true,

And I had some new, not implemented, events commented out and committed to Git. So when I uncommented the events and used CodeActions to create the events, the hover contained some git history info - confusing your parsing of the hover text. The "randomness" I experienced was a parameter that was added just before I used CodeActions, the hover did not contain any git info first, but after a few seconds it did appear giving the same strange behavior again. 😂

So as a workaround I just need to reconfigure GitLens to either

    "gitlens.hovers.currentLine.over": "annotation",
    "gitlens.hovers.currentLine.enabled": true,

or

    "gitlens.hovers.currentLine.enabled": false,

The permanent fix is to improve the TypeDetective's parsing of the hover message. I'll see if I could do a proposal, or at least get some more samples on what kind of hover messages that could be encountered.