fortran-lang / fprettify

auto-formatter for modern fortran source code
https://pypi.python.org/pypi/fprettify
Other
370 stars 76 forks source link

Warning output is written inside the script #123

Closed Koushikphy closed 2 years ago

Koushikphy commented 2 years ago

I'm using fprettify in VS Code with the Modern Fortran VS Code extension. I have this VS Code setting for fprettify

    "fortran.formatting.formatter": "fprettify",
    "fortran.formatting.fprettifyArgs": [
        "-i 4",
        "-w 2",
        "--enable-replacements",
        "--c-relations",
        "--enable-decl",
        "--whitespace-intrinsics=False",
        "--whitespace-print=False"
    ],

And I have this sample code (for test purpose) with a very long line

program demo

    write(*, "('Just a very long line. Just a very long line. Just a very long line. Just a very long line. Just a very long line. Just a very long line. ',i0)") 100

endprogram

Now, when I run the format document from the right click menu. This code is formatted as

WARNING: File -, line 3
    auto indentation failed due to chars limit, line should be split (limit: 132)
WARNING: File -, line 3
    auto indentation failed due to chars limit, line should be split (limit: 132)
program demo

    write(*, "('Just a very long line. Just a very long line. Just a very long line. Just a very long line. Just a very long line. Just a very long line. ',i0)") 100

endprogram

i.e. the warnings are written inside the code itself. This is certainly wrong. What is going on here and how to fix it.

nbehrnd commented 2 years ago

Since the string is so long, the command including its definition is too long. As far as I know, fprettify is not able to split long strings into smaller bits. Thus, a manual intervention (i.e., an edit by you) is requested. For one, Fortran concatenates individual strings into a larger one by two forward slashes, //. For two, if there is an overly long line of instruction, use a trailing & to indicate that the command extends to the next line.

As an illustration for the concepts above with Fortran 90+:

program demo

   implicit none

   write (*, '(a)') "Just a very long line. Just a very long line." &
      //"Just a very long line. Just a very long line. Just a very" &
      //"long line. Just a very long line."

end program demo

Compared to FORTRAN 77 (character 73 [including] and beyond on a line is considered as comment irrelevant to the compiler), use the flexibility of up to 132 chars per line in the free form of contemporary Fortran with a grain of salt.*) Though we no longer use punch cards (this often) and now have computers with (on occasion multiple) wider screen(s) attached, you / your colleagues will welcome if the lines are not overly long: then, a difference view (displaying two codes side by side in separate tabs/terminals) and managing revisions e.g., in git tend to be easier. (And using GitHub to learn by the examples by others, I prefer to read the code blocks without need to use the horizontal scroll bar, too.)

(In FORTRAN 77/fixed format, the next line continuing an (ongoing) instruction already starts with char 6, instead of 7.)

*) Right of the tip of my hat, I don't recall the maximum number of times you are allowed to use the & to extend a command over multiple lines.

Koushikphy commented 2 years ago

Since the string is so long, the command including its definition is too long. As far as I know, fprettify is not able to split long strings into smaller bits. Thus, a manual intervention (i.e., an edit by you) is requested. For one, Fortran concatenates individual strings into a larger one by two forward slashes, //. For two, if there is an overly long line of instruction, use a trailing & to indicate that the command extends to the next line.

As an illustration for the concepts above with Fortran 90+:

program demo

   implicit none

   write (*, '(a)') "Just a very long line. Just a very long line." &
      //"Just a very long line. Just a very long line. Just a very" &
      //"long line. Just a very long line."

end program demo

Compared to FORTRAN 77 (character 73 [including] and beyond on a line is considered as comment irrelevant to the compiler), use the flexibility of up to 132 chars per line in the free form of contemporary Fortran with a grain of salt.*) Though we no longer use punch cards (this often) and now have computers with (on occasion multiple) wider screen(s) attached, you / your colleagues will welcome if the lines are not overly long: then, a difference view (displaying two codes side by side in separate tabs/terminals) and managing revisions e.g., in git tend to be easier. (And using GitHub to learn by the examples by others, I prefer to read the code blocks without need to use the horizontal scroll bar, too.)

(In FORTRAN 77/fixed format, the next line continuing an (ongoing) instruction already starts with char 6, instead of 7.)

*) Right of the tip of my hat, I don't recall the maximum number of times you are allowed to use the & to extend a command over multiple lines.

Your comment does nothing to address the problem I posted. I know the line is too long. I did it intentionally. The problem is fprettify is doing something here that it should not be doing, i.e. dumping the errors/warning inside the source code itself. I don't know, maybe it's the problem with the VS Code extension itself.

Koushikphy commented 2 years ago

Refer to this https://github.com/fortran-lang/vscode-fortran-support/discussions/508#discussioncomment-2898400