Modern Fortran Subroutine Arguments in continuation lines

Hello fellow Fortran devs,
I am new in a forum but relatively experienced in fortran. My development environment seems to be working fine however, whenever I continue my subroutine arguments in the next line, argument color highlights are gone. As you can see, when I start typing the arguments after opening the paranthesis they are italicized and colored properly. However, when I continue the arguments in the continuation lines the highlighting gones. This affects modern fortran suggestions as well. I mean, when compile this module and use it in another code following happens. Modern Fortran autocompletes “call ED” as call EDINIT(). But it cannot show me the arguments of the subroutine. However, when I remove continuation lines and write them one after another without caring about the line length then autocompletion shows me all of the arguments. Any ideas about why? Please feel free to ask me any related or missing information. Thanks in advance.
image

Hi @ygtshn
I think this is a bug with the Modern Fortran VS Code extension. From what I understand, comment lines and white space lines can be ignored between continuation lines, but the Modern Fortran extension is not ignoring them.

I tested this behaviour with free-form source code as well, and the behaviour is the same - white space/comment lines between continuation lines cause the syntax highlighting to break. As far as I can tell, this behaviour only occurs for the argument list when declaring a procedure - not when calling. It might also be related to this syntax highlighting bug.

1 Like

From what I understand you stumbled into the bug @jaiken pointed out:

For the autocompletions I am not sure I understand.

Could you please assemble two Minimal Working Examples (MWEs), the first one reproducing the syntax highlighting bug, and the second the autocompletion bug. The smaller the code the better.

When trying to create the MWEs, could you install the pre-Release of Modern Fortran and the pre-release of fortls (python3 -m pip install fortls --pre). If you are struggling with this step you can skip it. I will try your MWE and if I can’t reproduce it with the pre-release that most likely means that it was one of the line continuation bugs I resolved during the last year or so.

Please also post any relevant VS Code settings you are using.

1 Like

Thank you very much @gnikit . I have prepared the mwes. But I cannot attach any .txt files since I am a new member. How can I share the mwes with you? In case you can work with plain text here you go:
This is my module code. Please do not forget to format the code for fortran77 fixed form.

      MODULE MWE1
          CONTAINS
          SUBROUTINE FOO(ARG1,
     &    ARG2,
C     SOME COMMENTS
     &    ARG3,
     &    ARG4)
               IMPLICIT NONE
               integer ARG1, ARG2, ARG3, ARG4
               ARG4 = ARG1 + ARG2+ARG3+ARG4
          END SUBROUTINE

          SUBROUTINE FOO2(ARG1, ARG2, ARG3, ARG4)
               IMPLICIT NONE
               integer ARG1, ARG2, ARG3, ARG4
               ARG4 = ARG1 + ARG2+ARG3+ARG4
          END SUBROUTINE
      END MODULE

And the main to illustrate autocomplete bug:

      PROGRAM MWE1_MAIN
          USE MWE1
          IMPLICIT NONE
          INTEGER ARG1, ARG2, ARG3, ARG4
          CALL FOO
          CALL FOO2
      END PROGRAM.

Unfortunately, I am working on a company laptop and cannot install pre-release. Sorry for that.
Whenever you compile to module and go to the main code, you should be able to see the autocomplete bug. That is, when you hover over FOO, or ctrl+space on it to get suggestions you should not be able to see the arguments. However, if you do the same for FOO2, it everything should be fine. Hovering will show the types and dimensions of the arguments and ctrl+space will show you arguments etc. Finally here is my settings.json for VS code:

    "fortran.fortls.path": "C:\\Users\\ac71911\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python312\\Scripts\\fortls",
    "fortran.linter.compilerPath": "C:\\msys64\\ucrt64\\bin\\gfortran",
    "fortran.fortls.sortKeywords": true,
    "fortran.formatting.path": "c:\\users\\ac71911\\appdata\\local\\packages\\pythonsoftwarefoundation.python.3.12_qbz5n2kfra8p0\\localcache\\local-packages\\scripts\\",
    "workbench.colorCustomizations": {
        "editor.selectionBackground": "#670b75",
        "editor.selectionHighlightBackground": "#670b75"
    },
    "fortran.linter.extraArgs": [
        "-std=legacy",
        "-Wall",
        "-Wextra",
        "-g",
        "-ffixed-line-length-none",
        "-Wcompare-reals"
    ],
    "files.associations": {
        "*.ext": "FortranFixedForm",
        "*.df": "FortranFixedForm"
    },
    "github.copilot.enable": {
        "FortranFixedForm": "true"
    },
    "fortran.linter.includePaths": [
        "${workspaceFolder}"
    ],
    "evenBetterToml.formatter.alignComments": true,

}

I am sorry if I did anything wrong in terms of formatting, replying or quoting. I am pretty rookie in forums :sweat_smile:

Cheers,
Yigit

I think I dug up something:

image

@jaiken. @gnikit I think above bug that is mentioned is related to parantheses. Whenever the comment is inserted with “C” instead of “!” inside the open parantheses, it breaks modern fortran it seems. However, I could not reproduce the behaviour with the subroutine declaration. There must be some kind of precendence over which comes first: subroutine declaration or line continuation.

Cheers,
Yigit

I’ll have a look at this and get back to you, hopefully today.

So I got some time to look into this.
For the syntax highlighting the bug seems to be related with similar difficulties that the Fixed Form grammar has. Since Fixed Form syntax is defined on top of Free Form changing certain parts of it is hard. Editing those TextMate grammar files is in general hard which is why we are moving to semantics driven highlighting.

For the completions in fortls, that’s definitely a bug. Fixed form support has been of a lesser importance, so things like this tend to happen (I didn’t even remember you could have Fixed Form multi-lines without some line continuation character).