Fortran language server (fortls) error in VSCode (Windows)
Asked Answered
U

3

5

VSCode keeps showing the error notification,

Error launching fortls: Please check that all selected options are supported by your language server version. Source: FORTRAN IntelliSense (Extension)

I have fortls installed and provided the path in settings.json as,

"fortran-ls.executablePath": "C:\\Users\\xxxxx\\Anaconda3\\Scripts\\fortls.exe"

I am not sure what options are not supported by the fortran language server version or how to change the version. Also, most of the features of Modern Fortran and Fortran IntelliSense extensions are not working, is this for not being able to use fortran language server? Sorry, I'm new to VSCode. Here's my full settings.json file in case you want to have a look for what options are not being compatible,

       "python.defaultInterpreterPath": "C:\\Users\\xxxxx\\Anaconda3\\python.exe",
  "fortran-ls.executablePath": "C:\\Users\\xxxxx\\Anaconda3\\Scripts\\fortls.exe",
  "editor.codeLens": false,
  "editor.formatOnSave": true,
  "editor.formatOnType": true,
  "diffEditor.codeLens": true,
  "editor.formatOnPaste": true,
  "editor.quickSuggestionsDelay": 1000,
  "workbench.colorTheme": "Visual Studio Dark - C++",
  "editor.minimap.maxColumn": 200,
  "editor.fontSize": 16,
  "terminal.integrated.defaultProfile.windows": "Git Bash",
  "editor.rulers": [
    132
  ],
  "workbench.colorCustomizations": {
    "editorRuler.foreground": "#458cff"
  },
  "workbench.iconTheme": "vscode-icons",
  "fortran.formatting.formatter": "fprettify",
  "editor.quickSuggestions": {
    "other": "on",
    "comments": "on",
    "strings": "on"
  },
  "fortran.linter.compiler": "gfortran"

Thank you so much!

Ugly answered 7/5, 2022 at 14:48 Comment(0)
U
3

I have found a temporary solution to this problem but I don't clearly understand it. I believe the problem was occurring because I had both fortran-language-server (LSP using Python (2.7+ or 3.0+)) and fortls (LSP using Python (3.7+).) installed. For some reason, uninstalling fortls (i.e., keeping fortran-language-server) works only, not the other way around. They both create the same named executable and somehow that was causing trouble for Fortran IntelliSense extension. My guess is Fortran IntelliSense only works with fortran-language-server, not the updated fortls. Please let me know if anyone has some explanation on why's this happening/if my guess is correct. Thank you!

Update: My guess seems to be correct, the author of fortls says Fortran IntelliSense was made to work with only fortran-language-server. And Modern Fortran in conjunction with fortls should be enough to provide IntelliSense features. Here is his original post.

Ugly answered 9/5, 2022 at 17:40 Comment(1)
For any future readers. Modern Fortran for VS Code does not require any additional Fortran extensions like Fortran Intellisense to work. Installing Fortran IntelliSense or any of the other deprecated extensions will raise an error.Kutzenco
R
3

I confirmed what mo_sal observed in his case.

I installed Modern-Fortran extension (v3.4.2022111811) on my vscode, which requires a path pointing to the executable fortls. I need to make Modern-Fortran work by installing

pip3 install fortran-language-server --user

An executable named fortls appears in ~/.local/bin/ folder. If I did

pip3 install fortls --user

then the same executable appears in the same folder but my vscode keeps popping out the "error lauching fortls" message.

Routh answered 18/11, 2022 at 13:13 Comment(1)
The two executables are not the same! fortls and fortran-language-server are very clearly different projects. I cannot exactly tell you why fortls is not working for you but a lucky guess would be because you are passing deprecated options through VS Code. Have a look at Modern Fortran's options and fortls' optionsKutzenco
K
2

I am the author of fortls and Modern Fortran and as you pointed out fortls can work with Modern Fortran without FORTRAN Intellisense, so you can go ahead and uninstall that from VS Code.

As for fortls vs fortran-language-server, basically fortls is the continuation of the project.

For more info check out the fortls + VS Code documentation: https://fortls.fortran-lang.org/editor_integration.html#visual-studio-code

Kutzenco answered 22/5, 2022 at 10:39 Comment(8)
the link you mentioned is not working. For some reason this is still a problem fortls from fortls package does not work with vscode and python3.6.8, but fortran-language-server does. I tried fortls-2.1.2 and fortran-language-server-1.12.0.Waylen
The project moved under fortran-lang. I have updated the link. You need to update your Python version. Python 3.6 has reached End Of Life and is not supported, not just by fortls but by anyoneKutzenco
This is the curse of fast developing languages. There is stil loads of code around (actively used and worked on) that was written for Python 2. And Linux distributions with Python 3.6 are still around (RHEL8). Fortunately, one can install another Python locally, but it is a complication.Clunk
The decision to drop support for Python 3.6 did not come lightly, but it was necessary in order to make the parser easier to develop and more deterministic. In general, I don't think it's too much to ask from the user to have an OS with an actively supported Python version. Alternatively, one can always roll-back to an older version of vscode, the Modern Fortran extension and fortls, that supports Python 3.6, but probably they will struggle receiving support from the community.Kutzenco
I tried writing a script and naming it fortls, where I first source a conda environment and call fortls from that environment: conda activate py39 > /dev/null; fortls "$@", did not work maybe I have to define conda as well..Waylen
@Waylen in theory you can use an arbitrary named script, you're not bound to name it fortls, and probably you shouldn't since the Python interpreter might think you are overwriting the fortls module. conda activate fortls-venv; python3 -m fortls should do the trick.Kutzenco
Thanks so the above worked when I source conda first before conda activate. I thought $@ required to pass through the arguments.. Just to let you now that I get the following when trying your command No module named fortls.__main__; 'fortls' is a package and cannot be directly executedWaylen
my bad, then just use fortls, we added __main__.py on the dev version of fortls but I have yet to issue a new release (there are some bugs I need to iron out before I do that)Kutzenco

© 2022 - 2025 — McMap. All rights reserved.