I’m new with coding in Fortran and I have just installed VS code. I’m not an experienced computer user so bear with me. When I first installed the Modern Fortran package and started writing some code, a prompt appeared stating " It is highly recommended to install fortls to have all the features" so I tried to do so and got an error message stating “Unable to install fortls, try manually”. Being a total newbie I didn’t know how to install it manually until today (I installed it with Pypi), however I haven’t seen the prompt of installing fortls never again after the 4th time launching VS code (I pressed the other button opposite to “install”). So basically what I want to know is:
How do I know fortls is being used by VS code?
Also, I have a problem with the autocomplete suggestions (It might be caused by not having fortls but I don’t know). Basically VS code suggests me words written inside comments. If I turn off the option of having words suggested then variables are not suggested anymore (in reality it is like VS studio does not consider variables as variable). Finally, it doesn’t suggest for command like “REAL” or “Print” (considers them as words as well). Is there a fix?
Thank you in advanced and sorry if it sounds confusing or if I didn’t label things correctly in the title.
Welcome to the Discourse @OnlyGiulio.
From the looks of it, your
fortls installation is not being picked up by VS Code. You can tell if
fortls is working in a couple of ways:
- Look in the log Channel for the Modern Fortran extension and see if something like this shows up
- In your VS Code
settings.json set the option
"fortran.fortls.notifyInit": true, and when
fortls finishes its initialisation step a notification will pop up.
- Alternatively, you can open a terminal and check pip installs packages by default,
pip show fortls will show you where the Location of the Python package e.g.
/home/gn/.local/lib/python3.8/site-packages and a couple directories up in
/home/gn/.local/bin, is where
fortls is installed. Use that path to set
"fortran.fortls.path": "" in your
Thank you very much @gnikit for the reply.
I think my knowledge is way under the level needed to use VS code effectively. I don’t know what a .json file is and what it is supposed to do.
In any case:
For the first point, I don’t have the initialization of the language server.
I tried setting the option
fortran.fortls.notifyInit and no pop up appeared.
I have a lot of directories and I don’t really understand under what criteria the bin voice was put after
I don’t think VS code is for me (I might go back to geany), but if you have any recommendation on how to start with it while using Fortran I would really appreciate it.
In any case thank you again!
Okay, that’s fine. So firstly, for changing settings, including those of any extensions in VS Code you should read this Visual Studio Code User and Workspace Settings
It covers all you need to know about the settings User Interface and the equivalent but less user friendly
Now in terms of gettings the Modern Fortran extension to work you only need a couple of things:
- VS Code version 1.63 or higher
pip to install
The experience for most users tends to be plug-n-play, but I understand that there are numerous system configurations so our default options might not cover your specific setup. To get
fortls to work either:
- need to find where pip installs its packages and add it to your PATH variable. This is normally done automatically but from the looks of it in your system it does not. e.g. for Unix
export PATH=$HOME/.local/bin:$PATH, restart vscode once you do that
- or find where pip installs its packages and point VS Code to it in the settings, see screenshot
In general, to install fortls in a terminal do
python3 -m pip install fortls --upgrade
Then follow either 1. or 2. to set it up in VS Code.
I made it!!! I don’t know why but a restart was the thing preventing the initialization! By the way my system is a Windows 10.
Thank you very much @gnikit, truly! It will probably not be the last time I ask things in this discourse since the next step is to have a debugger for fortran. If you have any suggestion on which one to use, I am open to suggestions.
No worries, glad you were able to get it to work!
For debuggers, GDB works well, might need to check how to get that on Windows. For the extension gfortran + GDB gives the best results for most users (the extension has a built-in interface with GDB).