codefori / vscode-ibmi

🌍 IBM i development extension for VS Code
https://codefori.github.io/docs/#/
MIT License
279 stars 93 forks source link

Event file no longer being retrieved #576

Closed fathert closed 2 years ago

fathert commented 2 years ago

Describe the bug After compilation the event file is not being copied back so no compilation feedback is displayed. There seems to be a rogue RPGPPOPT option in the CPYTOIMPF command.

To Reproduce Steps to reproduce the behavior:

  1. Compile a program
  2. Look at the OUTPUT console for Code for i

/home/PGMR85: system "QSYS/CPYTOIMPF FROMFILE(LSP_03G9/EVFEVENT ) RPGPPOPT() TOSTMF('/tmp/vscodetemp-O_N4eShc1X') MBROPT(REPLACE) STMFCCSID(1208) RCDDLM(CRLF) DTAFMT(DLM) RMVBLANK(TRAILING) ADDCOLNAM(SQL) FLDDLM(',') DECPNT(PERIOD) " { "code": 255, "signal": null, "stdout": "", "stderr": "CPD0043: Schlüsselwort RPGPPOPT für diesen Befehl ungültig.\nCPF0006: Im Befehl ist ein Fehler aufgetreten." }


The RPGPPOPT should not be a parameter of CPYTOIMPF.

**Expected behavior**
The event file should be copied.

**Screenshots**
![image](https://user-images.githubusercontent.com/8808151/156752200-3b872f2d-5d7d-4518-a536-3108dbf16fa2.png)

**Environment (please complete the following information):**
 - Extension version 1.2.0
 - IBM i OS version 7.2

**Additional context**
None
worksofliam commented 2 years ago

I have no idea where you're getting RPGPPOPT from.

/home/alan3/eog_demo/: system "QSYS/CPYTOIMPF FROMFILE(CMPSYS/EVFEVENT DEPTS_WEB) TOSTMF('/tmp/vscodetemp-O_h3KCyUdl') MBROPT(*REPLACE) STMFCCSID(1208) RCDDLM(*CRLF) DTAFMT(*DLM) RMVBLANK(*TRAILING) ADDCOLNAM(*SQL) FLDDLM(',') DECPNT(*PERIOD) "
{
    "code": 0,
    "signal": null,
    "stdout": "CPC2958: All records copied from file EVFEVENT in CMPSYS.",
    "stderr": ""
}

We don't even have any record of it in the codebase.

image

But I can also see the name of the member is missing on your CPYTOIMPF command.

Can you share the compile command that you're running and the result? (it's usually above that CPYTOIMPF in that same output)

fathert commented 2 years ago

Hi Liam,

I debugged the code and found the issue. There's a problem when compiling SQLRPGLE types of *MODULE because the function below scans the command...

CRTSQLRPGI OBJ(LSP_03G9/SNDXMLTOQ) SRCFILE(LSP_03G9/QRPGLESRC) CLOSQLCSR(*ENDMOD) OPTION(*EVENTF) DBGVIEW(*SOURCE) TGTRLS(*CURRENT) OBJTYPE(*MODULE) RPGPPOPT(*LVL2)

...and finds the string "*MODULE" in the command and assumes it's the position of the MODULE parameter, when in fact it's not.

  /**
   * 
   * @param {string} baseCommand 
   * @returns {{lib?: string, object: string}}
   */
  static getObjectFromCommand(baseCommand) {
    const possibleParms = [`MODULE`, `PNLGRP`, `OBJ`, `PGM`];
    const command = baseCommand.toUpperCase();

    for (const parm of possibleParms) {
      const idx = command.indexOf(parm);
      if (idx >= 0) {
        const firstBracket = command.indexOf(`(`, idx);
        const lastBracket = command.indexOf(`)`, idx);
        if (firstBracket >= 0 && lastBracket >= 0) {
          const value = command
            .substring(firstBracket+1, lastBracket)
            .split(`/`)
            .map(v => v.trim());

          if (value.length === 2) {
            return {
              lib: value[0],
              object: value[1],
            };
          } else {
            return {
              object: value[0],
            };
          }
        }

        break;
      }
    }

    return null;
  }

I can also break it by trying to compile a member with the word "OBJ" in the name. So doing a CRTPGM against QRPGLESRC/SAVEOBJ also fails.

I have experimented with using a regular expression instead of a string scanner, which seems to work. Here's the code:

  static getObjectFromCommand(baseCommand) {
    const command = baseCommand.toUpperCase();

    const parmRegex = /(PNLGRP|OBJ|PGM|MODULE)\((?<object>.+?)\)/g;
    const object = parmRegex.exec(baseCommand).groups.object.split('/');

    if (object.length === 2) {
      return {
        lib: object[0],
        object: object[1],
      };
    } else {
      return {
        object: object[0],
      };
    }
  }

If the fix is of interest then I could try to create a pull request for you.

Cheers,

Tim.

worksofliam commented 2 years ago

@fathert Nice find and a great change. Please do make a PR.

fathert commented 2 years ago

Thanks, it's my first, so glad it was ok. Happy to contribute, I use the editor full time now - thanks for all your hard work!

worksofliam commented 2 years ago

@fathert that is so awesome to hear!! Thanks a bunch

worksofliam commented 2 years ago

@fathert may I ask you to reply to this thread if you haven't already?

https://github.com/halcyon-tech/vscode-ibmi/discussions/350