superbol-studio-oss icon indicating copy to clipboard operation
superbol-studio-oss copied to clipboard

exceptions on unsaved files

Open GitMensch opened this issue 1 year ago • 7 comments

It seems the extension tries to do something on the file system, while the active editor should get the content from the editor window (= also handles unsaved changes).

The easiest way to reproduce:

  • [CTRL]+[N] to create a new editor, as expected it is set to "Plain Text"
  • manually change to COBOL
  • see errors
[Error - 20:24:27] Request textDocument/semanticTokens/full failed.
  Message: Caught exception: Not parsing copybook at untitled:Untitled-4
  Code: -32603 
[Error - 20:24:27] Request textDocument/foldingRange failed.
  Message: Caught exception: Not parsing copybook at untitled:Untitled-4
  Code: -32603 

GitMensch avatar Mar 05 '24 19:03 GitMensch

I think the Document_not_found is misleading here. Those messages indicate the LSP server assumes that such a file is a copybook, and those are not yet fully handled by the server.

So the issue here should be that we assume any filename whose extension does not belong to some given set is a copybook. Maybe that should be the other way round, with a given set of extensions that are always copybooks, and other files being "main" programs. Another possibility could be to look whether the file belongs to the copybook search path, and only decide based on that. @GitMensch what do you suggest regarding this issue?

nberth avatar Mar 06 '24 07:03 nberth

As GnuCOBOL can handle missing divisions "in general" (for the relaxed syntax checks) I guess that this is the same for the LSP. In this case many copybooks should pass, even when internally raising a "user-name not defined" scenario.

Copybook paths will very often also include programs (there are some installations with a strict separation, while others separate by "scope"/"area"/"topic"), this one should definitely not be used to decide on "likely copybook". Copybooks may also have a "program" extension - but not the other way around.

Therefore I suggest to assume a program until:

  • the file extension says otherwise (cpy, copy and their upper case variants + configured copybook extensions), keeping in mind that unsaved editors (and even saved ones) may not have an extension
  • the code starts (after possible comments and empty lines) with an integer + separator + word - this should nearly always be a copybook within DATA DIVISION

And even for a file that the LSP cannot handle - there should be a fallback to "basic syntax highlighting" (the tm syntax?).

GitMensch avatar Mar 06 '24 08:03 GitMensch

@nberth I think this needs to be re-opened. Just tested with a fresh window, inserting the following COBOL program, resulting in the following two error messages

[Warn  - 21:04:07] Failed to read cache ./_superbol/lsp-cache: End_of_file
[Error - 21:04:07] Request textDocument/documentSymbol failed.
  Message: Lsp_server.Document_not_found { uri = 'untitled:Untitled-1' }
  Code: -32603 
[Error - 21:04:07] Request textDocument/semanticTokens/full failed.
  Message: Lsp_server.Document_not_found { uri = 'untitled:Untitled-1' }
  Code: -32603 
[Info  - 21:04:07] Received client configuration: [ { "dialect": "default", "source-format": "auto", "copybooks": [ { "dir": "." } ], "copyexts": [ "cpy", "cbl", "cob" ] } ]
[Info  - 21:04:08] Getting configuration for project of untitled:Untitled-1
Reply: { "cobol.dialect": "default", "cobol.source-format": "auto", "cobol.copybooks": [ { "dir": "." } ], "cobol.copyexts": [ "cpy", "cbl", "cob" ] }

Note: there is a possibly related issue - when using [CTRL]+[S], the name of the suggested file is IDENTIFICATION DIVISION. (first line), while the extension normally provides the name (it is possibly derived from the symbols, but those are not available until save (neither breadcrumbs nor outline).

       IDENTIFICATION DIVISION.
       PROGRAM-ID. xdamcnt.
       AUTHOR.       Elmar Klausmeier.
       DATE-WRITTEN. 03-Oct-2021.
      *
      * entworfen am 31.03.1985
      * geschrieben am 02.04.1985
      * revidiert am 18.04.1985
      * Umgeschrieben auf COBOL: 03.10.2021
      *
      *     2   4    6     8      10         12           14
      *   1 0 0 2 10 4 40 92 352 724 2680 14200 73712 365596 
      *
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 i             pic 9(8) comp-5.
       77 j             pic 9(8) comp-5.
       77 k             pic 9(8) comp-5.
       77 N             pic 9(8) comp-5.
       77 N2            pic 9(8) comp-5.
       77 l             pic s9(8) comp-5.
       77 z             pic 9(8) comp-5.
       77 configOKret   pic 9(8) comp-5.
       01 A_vector.
          10  A         pic 9(8) comp-5 occurs 100 value 0.
       77 istart        pic 9(8) comp-5 VALUE 1.
       77 iend          pic 9(8) comp-5 VALUE 0.
       77 cnt           pic 9(8) comp-5 VALUE 0.
       77 slen          pic 9(8) comp-5 value 0.
       77 argc          pic 9(8) comp-5 VALUE 0.
       77 argv          PIC X(100) VALUE SPACES.

       LINKAGE SECTION.
      *01 argc          pic s9(8) comp-5.
      *01 argv.
      *   02 argvTable OCCURS 1 TO 100 TIMES DEPENDING ON argc.
      *      03 pargv   pointer.
      *01 argviStr      pic x(8). 

       PROCEDURE DIVISION.
      *PROCEDURE DIVISION USING BY VALUE argc BY REFERENCE argv.
       Pmain section.
           DISPLAY "N-Queens Problem in COBOL".
           display '  2   4    6     8      10         12           14'.
           display '1 0 0 2 10 4 40 92 352 724 2680 14200 73712 365596'. 

      *    GnuCOBOL command line handling
           ACCEPT argc from ARGUMENT-NUMBER.
           display "argc=", argc.
           if argc >= 1 then
               ACCEPT iend FROM ARGUMENT-VALUE.
               if iend <= 0  or  iend > 14 then
                   move 10 to iend
               end-if.
           if argc >= 2 then
               move iend to istart
               accept iend from argument-value
           end-if.

      *    IBM COBOL command line handling
      *    display "argc=", argc.
      *    if argc > 1 then
      *        set address of argviStr to pargv(2)
      *        move zero to slen
      *        inspect argviStr tallying slen for characters
      *            before initial X"00"
      *        move argviStr(1:slen) to iend
      *        if iend <= 0  or  iend > 14 then
      *            move 10 to iend
      *        end-if.
      *    if argc > 2 then
      *        move iend to istart
      *        set address of argviStr to pargv(3)
      *        move zero to slen
      *        inspect argviStr tallying slen for characters
      *            before initial X"00"
      *        move argviStr(1:slen) to iend
      *    end-if.

           display "istart=", istart, " iend=", iend.
                   
           PERFORM VARYING i FROM istart BY 1 UNTIL i > iend
               perform nqsolve
               DISPLAY "D(", i, ") = ", cnt
           END-PERFORM.

           STOP RUN.



      * Return number of positions for N queens.
       nqsolve section.
           move zero to cnt.
           move 1 to k.
           move 1 to A(1).
           move i to N.
           move i to N2.

       lloop.
           perform configOK.
           if configOKret = 1 then
               if k < N then
                   add 1 to k
                   move 1 to A(k)
                   go to lloop
                else
                   add 1 to cnt
                end-if
           end-if.

           perform with test after varying k from k by -1 until k <= 1
              if A(k) < N then
                  add 1 to A(k)
                  go to lloop
               end-if
           end-perform.

           add 1 to A(1).
           if A(1) > N2 then
               exit section
           end-if.
           move 2 to k.
           move 1 to A(2).
           go to lloop

           exit.



      * Check if k-th queen is attacked by any other prior queen.
      * Return nonzero if configuration is OK, zero otherwise.
       configOK section.
           move zero to configOKret.
           move A(k) to z.

           perform varying j from 1 by 1 until j >= k
               compute l = z - A(j)
               if l = 0 then
                   exit section
               end-if
               if l < 0 then
                   compute l = 0 - l
               end-if
               if l = k - j then
                   exit section
               end-if
           end-perform.

           move 1 to configOKret.
           
           exit.

GitMensch avatar Nov 28 '24 20:11 GitMensch

ping @nberth for reopening

GitMensch avatar Dec 13 '24 12:12 GitMensch

friendly ping - @nberth ?

GitMensch avatar Jan 22 '25 07:01 GitMensch

friendly ping - @nberth ?

I have just re-tested pasting the program above as you did (with current version 1.4.0 and current master), and I am not observing any error message in the logs (I may try on a windows machine later, in case). (Still, I'll quickly add a change to report some LSP server version information in logs — so we can always double-check that at least).

Even without these errors I acknowledge the issue with identification division as default program name (not yet sure how that can be fixed). I will open a dedicated issue for that.

nberth avatar Jan 22 '25 10:01 nberth

That sounds like this may be solved; providing a new release (or nightly vsix) enables a final check before we can close this issue.

GitMensch avatar Jan 22 '25 11:01 GitMensch

I'd say this one is finished, for the autofill we have a separate issue.

GitMensch avatar May 26 '25 10:05 GitMensch