Hello, sorry to bother you with what must be the 50th request for help on this topic you’ve seen in the past week. However, our computer system was upgraded to a new version of Linux yesterday, and I have been unable to get Modern Fortran (version 3.2.0) able to work correctly in Visual Studio Code (version 1.90.2) on my new OS (AlmaLinux 9.4). Linting appears to work correctly, since gfortran is included in /usr/bin/gfortran, which can be detected by Modern Fortran. However, the natural language operations (go to/peek/find definitions/references) are not available when right clicking on variables or subroutines. I have read through and attempted to follow the steps in the applicable posts which were recommended as solutions to this post, to no avail.
I have installed fortls, fident, and fprettify with pip (using python version 3.10). I currently have fortls version 3.1.2 installed.
fortls and a dependency, pyjson5, are located within my $HOME:/.local/bin folder. I have added fortls to my $PATH variable in my .bashrc file. Just to be sure, doing fortls -h within a fresh terminal window returns the help page, while removing the line in my bashrc extending $PATH results in a “fortls: command not found error” when doing fortls -h. So I’m pretty sure I have $PATH set up correctly.
Within the Modern Fortran settings of Visual Studio itself, I have only changed the “Notify Init” setting, as suggested here. However, within the “Output” window, the “Modern Fortran” tab shows the successful setup of the linter, but nothing about the initialization of fortls. I am also not getting any popup notifications within VSCode about missing fortls, or that Modern Fortran is unable to access it. Obviously, I have restarted VSCode multiple times in case that would solve something (which it didn’t).
I’m at a loss as to what to try next. Please let me know if there is any more information I should provide which would be helpful for solving this problem. It’s quite frustrating not to be able to use the find/peek tools for fortran, so I would very much like to get to the bottom of this as quickly as possible! Thanks for your help @gnikit !
Can I get you to use this template and check if that fixes it? It should work out-of-the-box.
The reasoning is that you’ll hide the packages inside a Virtual Environment in your project folder, once created and activated. At the very least, that way you isolate where the problem could be.
@MattAl Thanks for sharing your repository. I tried to set it up according to the directions on the github page (it’s very possible I made a mistake; I’m a relative novice with this sort of thing). When initializing VSCode within the repository, I still am unable to use the fortls features. I’ve attached a screenshot showing the terminal window with the repository.
We don’t have uv installed on our system and I was unfamiliar with it, so I used pip and the builtin python venv functionality as outlined on the github page. Please let me know if there’s any other information about the repository, python environment, or VSCode settings that would be helpful.
Just to confirm, you have installed all packages with:
pip install -r pyproject.toml
pip install -r requirements-dev.txt # this one installs "fortls" and "fprettify"
correct?
Then opened VS Code with code . (or manually opening the specific folder from File → Open Folder) and installed/enabled “Modern Fortran” for the repository project folder?
Try installing the pre-release. The v3.2.0 version did not have the log channel integrated for fortls in the OUtPUT pane. Also in the Modern Fortran vscode settings set the logging to Debug and post the logs in OUtPUT here.
You not getting errors, with fortls not being detected or failing are positive signs.
FYI you can think of the pre-release as v4 for all intents and purposes. I just need to find some time to update (non-code) parts of the repo which is why it’s been held back.
@MattAl I was unable to install pyproject.toml. When trying to do this, I got the following:
(.venv) (base) bash-5.1$ pip install -r pyproject.toml
ERROR: Invalid requirement: ‘[project]’: Expected package name at the start of dependency specifier
[project]
^ (from line 1 of pyproject.toml)
And yes, Modern Fortran is installed and enabled for the project folder. I still see linting corrections, but nothing for peek/find definitions/implementations.
I installed the pre-release version. It’s possible I missed it, but I looked through the Modern Fortran settings page and didn’t see anything for logging options. Is this something I need to change through the user settings.json file, and if so, is there documentation on what I should add there? For what it’s worth, here’s the output with the default logging settings.
Incidentally, since downloading and activating the template, I am now getting the warning about Modern Fortran not being able to detect fortls, and getting a prompt to install it. However, clicking “install” leads to an error:
I don’t know what the template is or does. So yes, please do.
Whatever you did between the first post and now has resulted into a broken python env and/or fortls. In your original post fortls seemed to be working.
I’ve restored the python environment to how it was previously using conda install -rev 1, which for some reason hasn’t solved the problem. I’m now extremely confused, because switching back and forth between the release version and pre-release version of Modern Fortran, I now get two different issues. Using the pre-release version, I have the issue shown above, which doesn’t make sense to me given that I have virtualenv installed (I did see something about the virtualenv.ini config file missing; I don’t know if that has anything to do with it). Using the release version, however, I don’t get the error of it being unable to install fortls, but it still can’t find the location of it. I’ve attached a screenshot of vscode, showing both the installation error, and, in the fortls:path setting, the path that fortls is in according to pip show fortls.
I don’t think that fortls itself is broken, since doing $ fortls -h shows me the help page (so it’s definitely installed).
I’m still extremely lost. I’m sorry if I made things worse by following the instructions for the template; I didn’t realize that wasn’t a tested and recommended solution to this problem.
Don’t sweat it, it was just a small mixup between replies.
So from the screenshot you posted I can see that you have specified the path to fortls incorrectly. Using the Pre-Release version try the following path
NOTE: obviously you will have to have installed fortls via pip or whatever first
The "fortan.fortls.path" by default is fortls and fortls.exe on Windows. As a rule of thumb if you cannot copy-past the "fortan.fortls.path" you have defined, in a new terminal and run /your/fortls/path/to/the/binary --version then you have set the option incorrectly and VS Code will complain.
The path option is meant to point the the binary itself. This is because we allow for users to high-jack the language server support implemented in Modern Fortran with an arbitrary language server, (I do this quite a bit when testing multiple development versions/features of fortls).
Anyway, if this doesn’t work we will take the issue from the top and run through the usual diagnostic list. Please remember to always use the latest version of Modern Fortran and fortls, and a relatively updated VS Code.
You were exactly right: it was the incorrect path! That solved the problem. I’m so sorry for being so obtuse with this; I obviously don’t know what I’m doing with all of these settings. That’s great advice to know for the future: that I should be able to paste the fortls.path into the terminal and call --version.
Happy this is resolved and we didn’t break anything!!
The default path is fortls, which works very well with Virtual Environments because they get automatically added to $PATH, and because that’s just a relative path system call (ie, $ fortls), it can be generalized for Unix (+WSL2) setups.