I am trying to play with gtk-fortran. Since it is a huge library, I’d like to take advantage of VS Code + Modern Fortran’s nice features for autocomplete, jump-to-definition, etc. I am using gtk-fortran as an fpm dependency and am able to run some of the simple examples that come with gtk-fortran.
The problem I am having is that VS Code cannot locate the gtk-fortran modules. For example, the linter flags the line use gtk and complains that there is no “gtk.mod” file. I confirmed that when I build the application, fpm puts all the gtk-fortran module files in one of the “build/gfortran_…” directories. So I set up a workspace “settings.json” as follows:
However, VS Code still cannot find “gtk.mod” or any other gtk-fortran module.
Now, if I copy all the module files into the project directory, then VS Code does find them and provides autocomplete, etc. for symbols provided by those modules. But I prefer not to copy these module over. I would think the search paths I provided should be able to detect modules in any fpm build subdirectory. Am I mistaken?
I’m on the go so I’ll edit my response later, but if you use
"${workspaceFolder}/build/**"
It should include all directories under build.
I can probably provide you with a task that installs things locally under workspace/build and you can point the linter to that, otherwise you won’t be fetching consistently the correct mod files of your project
Hm, I tried that too and it does not seem to help. I thought ${workspaceFolder}/build/** should recursively search all directories. For completeness, here is the workspace directory structure
Perhaps not the elegant solution you’re looking for, but, would it make sense that you install gtk-fortran somewhere and then point to the installation directory? Something like
fpm install --prefix=/to/gtk/fortran
will install all .mod files in /to/gtk/fortran/include
(you could customize include with --includedir "custom_mod_dir").
That would create a stable folder at least for the dependencies in your project.
PS I’m no VS code user so I may be suggesting something silly.
If not in pre-release version please install it, set the logging level to Debug, and post the OUTPUT of Modern Fortran. That will help clarify what’s going on under the hood.
Updated fortls to the latest version on PyPI (3.1.2)
Toggled to the pre-release version of the Modern Fortran extension (v3.4.2024090901)
Added a .fortls.json to enable “debug_log”: true
I’ve attached both the fortls log and the VS Code extension log generated from a fresh session. I opened VS Code in the project workspace, gave the extension some time to load, saved “main.f90” to let the linter run, and hovered over a “use gtk” statement to get the problem tooltip.
From the vscode logs I can tell that the linter paths are not properly resolved, only the manually specified modOutpout directory is present. On Windows, I think the separator is \\ so your settings should look something like this: