Skip to content

Detect COBOL variable in EXEC SQL, provides go to def, show refs and hover#375

Merged
nberth merged 7 commits intoOCamlPro:masterfrom
NeoKaios:feat/sql-exec-var-detection
May 23, 2025
Merged

Detect COBOL variable in EXEC SQL, provides go to def, show refs and hover#375
nberth merged 7 commits intoOCamlPro:masterfrom
NeoKaios:feat/sql-exec-var-detection

Conversation

@NeoKaios
Copy link
Copy Markdown
Contributor

@NeoKaios NeoKaios commented Oct 23, 2024

Add-on to #370,
reactivate Sql preproc in the LSP and add references and location to cobol vars in sql exec blocks

The completion seems to fails inside such exec blocks -> the parser needs to be more robust
The new completion test needs to pass before merging this

@NeoKaios NeoKaios changed the title Feat/sql exec var detection Detect COBOL variable in EXEC SQL, provides go to def, show refs and hover Oct 23, 2024
@nberth nberth marked this pull request as draft October 24, 2024 07:24
@nberth
Copy link
Copy Markdown
Collaborator

nberth commented Oct 24, 2024

Should be draft until #370 is merged.

@GitMensch
Copy link
Copy Markdown
Contributor

This seems to target #327, no? If yes I suggest to reference that in the commit message and/or in this PR as related issue.

@nberth
Copy link
Copy Markdown
Collaborator

nberth commented Jan 17, 2025

This PR introduces dependencies between libraries that I'd like to avoid as they would impair further extensibility of the LSP server. In addition the parser for SQL is not hardened against errors in SQL syntax. Those issues need to be fixed before this PR can be merged.

@GitMensch
Copy link
Copy Markdown
Contributor

I still wonder if it wouldn't be "simple" to not fully parse the SQL stuff (which can be quite useful if it provides completions and co) but just scan it for any doublecolon+word - and add those as a reference for "word"....

@nberth nberth marked this pull request as ready for review May 23, 2025 09:03
@nberth nberth merged commit 8de2307 into OCamlPro:master May 23, 2025
4 checks passed
@GitMensch
Copy link
Copy Markdown
Contributor

just checked with last CD build, CTRL+click does not work (so I guess references won't work either), tested on bind variables (:DB and defined cursors MYCUR)

           EXEC SQL AT :DB
               FETCH MYCUR
               INTO
                 :FLD1,
                 :FLD2
           END-EXEC.

and also not in the declaration

           EXEC SQL VAR TABFLD1            IS CHAR      END-EXEC.

Should it?

@nberth
Copy link
Copy Markdown
Collaborator

nberth commented May 26, 2025

Should it?

Implicitly declared variables are not supported yet: only references to COBOL variables for which there is a corresponding COBOL declaration can be navigated (and renamed) in this way. I guess this will be future work (and this limitation will need to be documented in the README.md — that does not even mention SQL yet).

@GitMensch
Copy link
Copy Markdown
Contributor

for the cursors, sure - but FL1 and FLD2 are indeed variables that are part of WORKING-STORAGE, even separate fields

           EXEC SQL BEGIN DECLARE SECTION END-EXEC.
      *
       01 DB                 PIC  X(010).
       01 FLD1               PIC  X(018).
       01 FLD2               PIC  X(026).
      * 
       01 MYTAB.
         03 MYKEY.
           05 FLD3           PIC  X(006).
           05 FLD4           PIC  X(008).
      *
         03 MYDATA.
            05 ...
      * 
           EXEC SQL VAR FLD3            IS CHAR      END-EXEC.
           EXEC SQL VAR FLD4            IS CHAR      END-EXEC.
      * 
           EXEC SQL END DECLARE SECTION END-EXEC.
           EXEC SQL INCLUDE SQLCA END-EXEC.
      *
           EXEC SQL AT :DBS
              DECLARE MYCUR CURSOR FOR
                 SELECT
                        FLD1, FLD2 FROM TAB
                 WHERE
                          TFL3
                       || TFL4
                 >=
                          :FLD3
                       || :FLD4
                 ORDER BY
                          TFL3
                       || TFL4
                 ASC
           END-EXEC.

@nberth
Copy link
Copy Markdown
Collaborator

nberth commented May 26, 2025

for the cursors, sure - but FL1 and FLD2 are indeed variables that are part of WORKING-STORAGE, even separate fields

           EXEC SQL BEGIN DECLARE SECTION END-EXEC.
      *
       01 DB                 PIC  X(010).
       01 FLD1               PIC  X(018).
       01 FLD2               PIC  X(026).
      * 
       01 MYTAB.
         03 MYKEY.
           05 FLD3           PIC  X(006).
           05 FLD4           PIC  X(008).
      *
         03 MYDATA.
            05 ...
      * 
           EXEC SQL VAR FLD3            IS CHAR      END-EXEC.
           EXEC SQL VAR FLD4            IS CHAR      END-EXEC.
      * 
           EXEC SQL END DECLARE SECTION END-EXEC.
           EXEC SQL INCLUDE SQLCA END-EXEC.
      *
           EXEC SQL AT :DBS
              DECLARE MYCUR CURSOR FOR
                 SELECT
                        FLD1, FLD2 FROM TAB
                 WHERE
                          TFL3
                       || TFL4
                 >=
                          :FLD3
                       || :FLD4
                 ORDER BY
                          TFL3
                       || TFL4
                 ASC
           END-EXEC.

All of this snippet is in WORKING-STORAGE section, right? It is quite possible that at the moment portions of SQL that appear in this section are only handled for variable declarations, but not for "use" references.

@GitMensch
Copy link
Copy Markdown
Contributor

yes (that's the place Pro*COB expects it; it possibly doesn't care and only searches for EXEC SQL ... END-EXEC and EXEC SQL DECLARE ... END DECLARE)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants