Error launching fortls popping up when opening an f90 file

Since recently, I think it coincided with the upgrade to vscode 1.73.0, but I’m not 100% sure, I get this message upon opening f90 files:

Error launching fortls: Please check that all selected options are supported by your language server version.

fortls --version from the command line reports 2.13.0 and the Modern Fortran extension is v3.2.0. I tried the pre-release version v3.4.0 but the error pop-up kept continuously popping up with no chance to close it permanently so I reverted to v3.2.0.
I’m using it on linux; when I enter fortls on the command line and then hit enter, I get this error:
fortls.jsonrpc.JSONRPC2ProtocolError: Line endings must be \r\n
which seems strange to me as these are Window line endings but I’m not sure whether this is related.

Hi @elseifthen welcome to Fortran-lang Discourse.

The user is not meant to interact with fortls directly, unless you are trying to debug something, therefore you shouldn’t be calling fortls from the command line.

See relevant discussion on GitHub Configing `fortls` failed · Discussion #148 · gnikit/fortls · GitHub


Having that said the first error you mentioned can be occurring either because:

  1. you are passing invalid options to fortls via vscode or a configuration file
  2. your PYTHONPATH is not correctly setup and hence binaries, like fortls, cannot run.

Is the root installation location of fortls in your PYTHONPATH?

How would I see whether invalid options are passed to fortls?
I do not have PYTHONPATH set at all, yet I can just call fortls from the command line (although that’s not meant to be done, but it runs anyway, that’s my point).
I installed fortls via pip3 install fortls. It seems it was put to /work/usr/lib/python3.7/site-packages/fortls. I also tried to manually export PYTHONPATH to /work/usr/lib/python3.7/site-packages:/work/usr/lib/python3.7/site-packages/fortls and call vscode from that shell. No change. When I deliberately set a wrong path to the fortls binary in the vscode settings, I get:

Modern Fortran Error starting fortls: Check that fortls is in your PATH or that “fortran.fortls.path” is pointing to a fortls binary.

so that seems to indicate that the fortls binary is actually used when I have the path correctly set up, yet something is triggering an error. Do you have fortls 2.13.0 running with Modern Fortran v3.2.0 in vscode 1.73.0 (possibly even on Linux) without any problems? Or which versions are you running?

Yes, I do. We also have integration tests in the vscode extension that check for this.

Can you post your vscode settings (settings.json both global and workspace if you have them) and if any the fortls config file?

Also any other details that would be relevant, to your case to help us narrow down the issue. For example the shell that you’re using to call vscode, is that the system default shell?

My shell is zsh. Usually I call vscode from a python script that generates workspace files etc. via

return_code = subprocess.call(filter(None, [‘vscode’, workspace_file]))

but it does not make a difference if I call it from a shell, I also get that error.

settings.json:

{
    "telemetry.enableTelemetry": false,
    "telemetry.enableCrashReporter": false,
    "http.proxyAuthorization": null,
    "http.proxyStrictSSL": false,
    "workbench.colorTheme": "Quiet Light",
    "debug.allowBreakpointsEverywhere": true,
    "debug.console.fontSize": 18,
    "files.trimTrailingWhitespace": true,
    "window.zoomLevel": 2,
    "fortran-ls.enableCodeActions": true,
    "fortran-ls.hoverSignature": true,
    "fortran-ls.variableHover": true,
    "C_Cpp.default.intelliSenseMode": "gcc-x64",
    "workbench.colorCustomizations": {

        "[Quiet Light]": {
            "foreground": "#000000",
            "badge.foreground": "#000000",
            "badge.background": "#d7c8e6",
            "breadcrumb.foreground": "#222222",
            "tab.activeBackground": "#e6fd73",
            "tab.activeForeground": "#000000",
            "tab.activeBorder": "#0000ff",
            "tab.inactiveForeground": "#000000",
            "tab.border": "#4b5029",
            "tab.hoverBorder": "#2f00ff",
            "editorHoverWidget.border": "#1D76EA",
            "list.filterMatchBackground": "#dbd86a",
            "list.warningForeground": "#000000ff",
            "gitDecoration.untrackedResourceForeground": "#000000",
            "sideBar.foreground": "#000000",
            "editor.foreground": "#000000",
            "editorLineNumber.foreground": "#444444",
            "editorLineNumber.activeForeground": "#ff3bf2",
            "editorCursor.foreground": "#000000",
            "minimap.selectionHighlight": "#0000ff",
            "editorBracketMatch.border": "#7b8200",
            "list.errorForeground": "#000000",
            },
        "gitDecoration.modifiedResourceForeground": "#303500",
        "toolbar.hoverOutline": "#ff00ff",
        "inputOption.activeBorder": "#ff00ff",
        "icon.foreground": "#ff05d1",
        "selection.background": "#f8a57f",
        "editor.selectionHighlightBackground": "#fab08549",
        "editor.selectionBackground": "#eeec9c",
        "editor.findMatchBackground": "#ed4cb76f",
        "editor.findMatchBorder": "#f828ff",
        //"editor.findMatchBorder": "#d4540ab4",
        "editor.findMatchHighlightBackground": "#ffc19d",
        "editorBracketHighlight.foreground1": "#642193",
        "editorBracketHighlight.foreground2": "#1300e3"
    },
    "editor.tokenColorCustomizations": {
        "textMateRules": [
            {
                "scope": [ "comment", "comment.block.documentation"
                         , "punctuation.definition.comment", "punctuation.definition.comment.begin"
                         , "punctuation.definition.comment.end"  ],
                "settings": { "foreground": "#ce4223", "fontStyle": "", },
            },
            {
                "scope": [ "entity.name.type", ],
                "settings": { "foreground": "#015132", },
            },
            {
                "scope": [ "storage.type", ],
                "settings": { "foreground": "#D11392", },
            },
            {
                "scope": [ "keyword.operator.assignment",
                           "source.fortran.free keyword.other",
                           "keyword.operator",
                         ],
                "settings": { "foreground": "#920369", "fontStyle": "bold", },
            },
            {
                "scope": [ "source.fortran.free keyword.control",
                           "variable.other.property",
                           "storage.modifier",
                           "source.fortran.free keyword.logical",
                           "source.fortran.free storage.type",
                           "source.fortran.free storage.modifier",
                           "source.fortran.free constant.language.logical",
                           "source.fortran.free keyword.other",
                        ],
                "settings": { "foreground": "#0404BC", "fontStyle": "bold", },
            },
            {
                "scope": [ "source.fortran.free entity.name.type", ],
                "settings": { "foreground": "#000000", "fontStyle": "" },
            },
            {
                "scope": [ "source.c keyword.control",
                           "source.cpp keyword.control",
                        ],
                "settings": { "foreground": "#3a24fa", "fontStyle": "bold"},
            },
            {
                "scope": [ "variable.other.property.c",
                           "variable.other.property.cpp",
                            ],
                "settings": { "foreground": "#1815fb", "fontStyle": ""},
            },
            {
                "scope": [ "punctuation.parentheses", "punctuation.bracket", "constant.numeric",
                           "keyword.other.selector.fortran", "keyword.operator.line-continuation",
                           "meta.attribute-list.type-specification-statements"],
                "settings": { "foreground": "#920269", },
            },
            {
                "scope": [ "string", "punctuation.definition.string" ],
                "settings": { "foreground": "#CA2F7C", },
            },
            {
                "scope": [ "entity.name.function",
                           "variable.other",
                           "keyword.operator.double-colon",
                           "punctuation.comma",
                           "punctuation.definition.parameters",
                           "storage.modifier.intent.in",
                           "storage.modifier.intent.in-out",
                           "storage.modifier.intent.out" ],
                "settings": { "foreground": "#383838", },
            },
            {
                "scope": [ "support.function.intrinsic",
                           "variable.parameter.dummy-variable" ],
                "settings": { "foreground": "#f65c28", "fontStyle":"italic", },
            },
        ]
    },
    "git.path": "/work/usr/bin/git",
    "gitlens.advanced.externalDiffTool": "kdiff3",
    "gitlens.hovers.currentLine.over": "line",
    "search.collapseResults": "alwaysCollapse",
    "search.exclude": {
        "**/*.html": true,
        "**/*.js": true,
        "**/*.mod": true,
        "**/*.mod.*": true,
        "**/*.o": true,
        "**/*.o.*": true,
        "**/*.orig": true,
        "**/*.swp": true,
        "**/*BACKUP*": true,
        "**/*BASE*": true,
        "**/*LOCAL*": true,
        "**/*REMOTE*": true,
        "**/build*/**": true,
        "**/exe/**": true,
        "**/html/**": true,
        "**/latex/**": true
    },
    "search.quickOpen.history.filterSortOrder": "recency",
    "search.searchEditor.reusePriorSearchConfiguration": true,
    "editor.fontSize": 12,
    "editor.fontFamily": "'Source Code Pro', 'DejaVu Sans Mono',  'Droid Sans Mono', 'monospace', monospace",
    "gitlens.currentLine.enabled": false,
    "C_Cpp.default.includePath": [
        "/work/user/eclipseWS/censored1/inc",_
        "/work/user/eclipseWS/censored2/inc",
        "/work/user/eclipseWS/censored3/sub",
        "/work/user/eclipseWS/censored4/inc",
        "/work/user/eclipseWS/censored5/inc",
        "/work/user/eclipseWS/censored6/dll",
        "/work/user/eclipseWS/censored6/main"
    ],
    "editor.minimap.size": "fit",
    "files.exclude": {
        "{dir1,dir2,dir3,dir4}": true,
        "{comm_link,setup,,documentation,doxygen_cfg,fortran_unit_tests}": true,
        "{dir6,dir7,dir8}": true,
        "**/*.f90.*": true,
        "**/*.pyc": true,
        "**/build*/**": true,
        "**/CMakeFiles": true,
        "**/exe": true,
        "**/generated-sources": true,
        "**/Packages": true,
        "dir9/documentation": true,
        "dir10/examples": true,
    },
    "files.watcherExclude": {
        "**/.*": true,
        "**/.git/**": true,
        "**/.git/objects/**": false,
        "**/.git/subtree-cache/**": false,
        "**/.hg/**": true,
        "**/.hg/store/**": false,
        "**/build*/**": true,
        "**/documentation/**": true,
        "**/html/**": true,
        "**/node_modules/**": true,
        "**/node_modules/*/**": false,
        "**/Packages/**": true
    },
    "explorer.confirmDelete": false,
    "files.enableTrash": false,
    "fortran.preferredCase": "uppercase",
    "fortran.linter.compilerPath": "/bin/gfortran"
}

Workspace settings.json:

{
    "editor.accessibilityPageSize": 9,
    "cmake.configureOnOpen": false,
    "files.exclude": {
        "**/.waf*": true,
        "**/*.swp": true,
        "**/*proj": true,
        "**/wscript": true
    }
}

How can I get more verbose debug output from Modern Fortran such that I can identify what the actual problem with fortls is?

Thanks, I don’t see anything wrong with your settings. You should also check in VS Code the OUTPUT channel for Modern Fortran. It should show you exactly what command is attempted to be run in fortls.

I would recommend installing the pre-release for debugging purposes and setting the option
"fortran.logging.level": "Debug" and posting the logs from the Output channel
(You can revert to your old version after)

To me this sounds like a PYTHONPATH issue, fortls is being detected but it cannot execute because it fails to resolve the relative module imports. I had the exact same issue on my Mac with zsh.

You can test if fortls works in your environment (obviously for this to be meaningful it needs to be the same environment that vscode is running in) by doing something simple in the command line:

fortls --debug_filepath yourfile.f90 --debug_parser

I would just add that VS Code might not necessarily have access to the same environmental variables as the shell that launched it. There is an open issue for example where CMake installed via virtual environments does not get detected in VS Code regardless of what the user does to initialise the environment that VS Code gets launched in.

This worked without any obvious problem.

I added "fortran.logging.level": "Debug" to the end of my settings.json, installed Modern Fortran v3.4.0 and opened an f90 file. While I got the popup with the error message again it seems I don’t understand what you mean by “the OUTPUT channel for Modern Fortran”; I looked at the content of the OUTPUT tab but I didn’t get any output that seemed to stem from Modern Fortran:

[11/8/2022, 12:06:28 PM] For C++ source files, IntelliSenseMode was changed from "linux-gcc-x64" to "linux-clang-x64" based on compiler args and querying compilerPath: "/share/compilers/x86_64-unknown-linux/intel/compiler196/compilers_and_libraries_2019.6.324/linux/bin/clang"
[11/8/2022, 12:06:28 PM] IntelliSenseMode was changed because it didn't match the detected compiler.  Consider setting "compilerPath" instead.  Set "compilerPath" to "" to disable detection of system includes and defines.
[11/8/2022, 12:06:28 PM] For C source files, IntelliSenseMode was changed from "linux-gcc-x64" to "linux-clang-x64" based on compiler args and querying compilerPath: "/share/compilers/x86_64-unknown-linux/intel/compiler196/compilers_and_libraries_2019.6.324/linux/bin/clang"
[11/8/2022, 12:06:28 PM] IntelliSenseMode was changed because it didn't match the detected compiler.  Consider setting "compilerPath" instead.  Set "compilerPath" to "" to disable detection of system includes and defines.

So how do I get the debug output from the Modern Fortran extension?

This one
image

Each extension can register an output channel where it logs things. Choose Modern Fortran from the dropdown

OK, thanks! This is the output:

[DEBUG - 1:43:25 PM] [lsp.client] Language Server arguments:
[
  "--enable_code_actions",
  "--hover_signature",
  "--use_signature_help",
  "--nthreads=4",
  "--incremental_sync"
]
[ERROR - 1:43:25 PM] [lsp.client] Unable to verify input arguments with LS:
[DEBUG - 1:43:25 PM] [lsp.client] Language Server version: null

I don’t understand why the language server version would be null. I set the path to fortls as /work/usr/bin/fortls which is what which fortls reports. It works on the command line.

Ah, now I got it! I entered fortls from the TERMINAL tab in vscode and there I saw that it had problems importing importlib_metadata. So I added /home/user/.local/lib/python3.7/site-packages to the PYTHONPATH and now the error is gone.
Thanks for your support!

1 Like

Great, glad you were able to resolve this.