Hi all, I have a problem when I try to configure fortran in vscode on the remote server. I have already installed gfortran, fortls and correctly input the path to fortls in vscode. But the code only have variable highlight but I cannot use the go to definition/implementation function of the Modern fortran and I cannot run fortran code either. Can you help me? Thanks so much.
Hi @Zifan welcome. After installing fortls on the remote server and the pre-release version of the VS Code Modern Fortran extension,
- open vscode with your Fortran project,
- go the the OUTPUT pane on the bottom of vscode, select Modern Fortran
- copy paste the contents of the pane here.
My result is different to your response to other discussion. I don’t know the reason. And may I ask the difference between fortran-language-server and fortls? Will they conflict with each other and which one should I choose for modern fortran extension in Vscode. I downloaded them and uninstall the fortran-language-server while keeping the fortls. I don;t whether this can cause the issue. Morover, when you say fortran project, do I need to init the project by my self or I can just git clone the project from some github repository and open some fortran file in it to open the modern fortran extension.
This is the settings.json in the remote server. It seems automatically disable the modern fortran but when I set it to by false, it shows other issues.
Our tools are Modern Fortran and fortls. All other tools (e.g. fortran-language-server) I am aware of are deprecated and hence won’t work with the above.
You need to enable fortls
for it to work in vscode (this is the default option)
{
"fortran.fortls.disabled": false,
}
After I enable the fortls, it shows following error.
And the output channel also shows a lot error message.
Can you set the logging level to Debug, relaunch VSCode and post the OUTPUT messages.
The second image you posted is cut too narrow and the ERROR message is not complete, but in summary what causes the error message are invalid arguments passed to fortls
. Please post the full messages and not screenshots.
May I ask how to set the logging level to debug? And there are really a lot of message in the output since this project is a very large project that contains about 3000 files. If I want to use a small project to test the configuration can I just git clone some sample project from github or I need to initialize the whole project by my self.
In the VS Code settings, see
or equivalently in JSON
{
"fortran.logging.level": "Debug"
}
Now the Output should look like this:
[INFO - 15:57:41] Extension Name: Modern Fortran
[INFO - 15:57:41] Extension Version: 3.4.0
[INFO - 15:57:41] Linter set to: "gfortran"
[INFO - 15:57:41] Formatter set to: "findent"
[INFO - 15:57:41] Autocomplete set to: "fortls"
[INFO - 15:57:41] Hover set to: "fortls"
[INFO - 15:57:41] Symbols set to: "fortls"
[INFO - 15:57:42] [lint] Found GNU Fortran version 13.2.0
[DEBUG - 15:57:42] [lint] Using Modern GNU Fortran diagnostics: true
[DEBUG - 15:57:42] [lint] arguments:
[
"-ffree-line-length-none",
"-ffixed-line-length-none",
"-Wall"
]
[DEBUG - 15:57:42] [lint] moduleOutput: -J /Users/gn/Library/Application Support/Code - Insiders/User/workspaceStorage/a2a6f6e75aba276aa97969e903ca0a7d/fortran-lang.linter-gfortran/include
[DEBUG - 15:57:42] [lint] Initialising cache for linter.includePaths
[DEBUG - 15:57:42] [lint] glob paths:
[]
[DEBUG - 15:57:42] [lint] resolved paths:
[]
[DEBUG - 15:57:42] [build.single] compiler: "gfortran" located in: "/opt/homebrew/bin/gfortran"
[INFO - 15:57:42] [build.single] Compiler query command line: /opt/homebrew/bin/gfortran -fsyntax-only -cpp -fdiagnostics-plain-output -ffree-line-length-none -ffixed-line-length-none -Wall -J /Users/gn/Library/Application Support/Code - Insiders/User/workspaceStorage/a2a6f6e75aba276aa97969e903ca0a7d/fortran-lang.linter-gfortran/include -ffree-form -o /Users/gn/Code/fortls/test/test_source/test.f90.o /Users/gn/Code/fortls/test/test_source/test.f90
[DEBUG - 15:57:42] [lsp.client] Fortran Language Server -- constructor
[DEBUG - 15:57:42] [lsp.client] Language Server arguments:
[
"--enable_code_actions",
"--hover_signature",
"--use_signature_help",
"--lowercase_intrinsics",
"--nthreads=4",
"--incremental_sync"
]
[DEBUG - 15:57:42] [lsp.client] Language Server version: 2.13.1.dev162+gb604730.d20230612
[INFO - 15:57:42] [lsp.client] Initialising Language Server for workspace: file:///Users/gn/Code/fortls/test/test_source
[INFO - 15:57:42] [lsp.client] Language Server arguments: --enable_code_actions --hover_signature --use_signature_help --lowercase_intrinsics --nthreads=4 --incremental_sync
[INFO - 15:57:42] fortls - Fortran Language Server 2.13.1.dev162+gb604730.d20230612 Initialized
[DEBUG - 15:57:42] [build.single] Compiler output:
/Users/gn/Code/fortls/test/test_source/test.f90:2:5: Fatal Error: Cannot open module file 'test_free.mod' for reading at (1): No such file or directory
compilation terminated.
[DEBUG - 15:57:42] [lint] Parsing output to vscode.Diagnostics
[
{
"severity": "Error",
"message": "Cannot open module file 'test_free.mod' for reading at (1): No such file or directory",
"range": [
{
"line": 1,
"character": 5
},
{
"line": 1,
"character": 5
}
]
}
]
[DEBUG - 15:57:42] [lint] Removing duplicates. vscode.Diagnostics are now:
[
{
"severity": "Error",
"message": "Cannot open module file 'test_free.mod' for reading at (1): No such file or directory",
"range": [
{
"line": 1,
"character": 5
},
{
"line": 1,
"character": 5
}
]
}
]
The results are served for only the opened Fortran files, so that means that you have a lot of tabs open. Just close all but one before restarting VS Code to reduce the output size.
This is part of the result.
[INFO - 10:38:07 AM] Extension Name: Modern Fortran
[INFO - 10:38:07 AM] Extension Version: 3.4.0
[INFO - 10:38:07 AM] Linter set to: “gfortran”
[INFO - 10:38:07 AM] Formatter set to: “findent”
[INFO - 10:38:07 AM] Autocomplete set to: “fortls”
[INFO - 10:38:07 AM] Hover set to: “fortls”
[INFO - 10:38:07 AM] Symbols set to: “fortls”
[INFO - 10:38:07 AM] [lint] Found GNU Fortran version 4.8.5
[DEBUG - 10:38:07 AM] [lint] Using Modern GNU Fortran diagnostics: false
[DEBUG - 10:38:07 AM] [lint] arguments:
[
“-ffree-line-length-none”,
“-ffixed-line-length-none”,
“-Wall”
]
[DEBUG - 10:38:07 AM] [lint] moduleOutput: -J /home/w.zifan1/.vscode-server/data/User/workspaceStorage/5cf0f7638d773a0b30f6c136ceddeb8d/fortran-lang.linter-gfortran/include
[DEBUG - 10:38:07 AM] [lint] Initialising cache for linter.includePaths
[DEBUG - 10:38:07 AM] [lint] glob paths:
[
“/usr/bin/gfortran”,
“/home/w.zifan1/.local/bin/fortls”,
“/home/w.zifan1”
]
[DEBUG - 10:38:07 AM] [lint] resolved paths:
[DEBUG - 10:38:07 AM] [build.single] compiler: “gfortran” located in: “/usr/bin/gfortran”
[INFO - 10:38:07 AM] [build.single] Compiler query command line: /usr/bin/gfortran -fsyntax-only -cpp -ffree-line-length-none -ffixed-line-length-none -Wall -J /home/w.zifan1/.vscode-server/data/User/workspaceStorage/5cf0f7638d773a0b30f6c136ceddeb8d/fortran-lang.linter-gfortran/include -ffree-form -o /home/w.zifan1/test.f90.o /home/w.zifan1/test.f90
[DEBUG - 10:38:07 AM] [lsp.client] Fortran Language Server – constructor
[DEBUG - 10:38:07 AM] [lsp.client] Language Server arguments:
[
“–enable_code_actions”,
“–hover_signature”,
“–use_signature_help”,
“–lowercase_intrinsics”,
“–nthreads=4”,
“–incremental_sync”
]
[ERROR - 10:38:07 AM] [lsp.client] Unable to verify input arguments with LS:
[DEBUG - 10:38:07 AM] [lsp.client] Language Server version: null
[DEBUG - 10:38:07 AM] [build.single] Compiler output:
[DEBUG - 10:38:07 AM] [lint] No linting diagnostics to show
[DEBUG - 10:38:16 AM] [lint] arguments:
[
“-ffree-line-length-none”,
“-ffixed-line-length-none”,
“-Wall”
]
[DEBUG - 10:38:16 AM] [lint] moduleOutput: -J /home/w.zifan1/.vscode-server/data/User/workspaceStorage/5cf0f7638d773a0b30f6c136ceddeb8d/fortran-lang.linter-gfortran/include
[DEBUG - 10:38:16 AM] [lint] glob paths:
[
“/usr/bin/gfortran”,
“/home/w.zifan1/.local/bin/fortls”,
“/home/w.zifan1”
]
[DEBUG - 10:38:16 AM] [lint] resolved paths:
[DEBUG - 10:38:16 AM] [build.single] compiler: “gfortran” located in: “/usr/bin/gfortran”
[INFO - 10:38:16 AM] [build.single] Compiler query command line: /usr/bin/gfortran -fsyntax-only -cpp -ffree-line-length-none -ffixed-line-length-none -Wall -J /home/w.zifan1/.vscode-server/data/User/workspaceStorage/5cf0f7638d773a0b30f6c136ceddeb8d/fortran-lang.linter-gfortran/include -ffree-form -o /home/w.zifan1/.vscode-server/data/User/History/-2a5b76d4/70by.F90.o /home/w.zifan1/.vscode-server/data/User/History/-2a5b76d4/70by.F90
[DEBUG - 10:38:16 AM] [lsp.client] Language Server arguments:
[
“–enable_code_actions”,
“–hover_signature”,
“–use_signature_help”,
“–lowercase_intrinsics”,
“–nthreads=4”,
“–incremental_sync”
]
[ERROR - 10:38:16 AM] [lsp.client] Unable to verify input arguments with LS:
[DEBUG - 10:38:16 AM] [lsp.client] Language Server version: null
[DEBUG - 10:38:16 AM] [lint] arguments:
[
“-ffree-line-length-none”,
“-ffixed-line-length-none”,
“-Wall”
]
[DEBUG - 10:38:16 AM] [lint] moduleOutput: -J /home/w.zifan1/.vscode-server/data/User/workspaceStorage/5cf0f7638d773a0b30f6c136ceddeb8d/fortran-lang.linter-gfortran/include
[DEBUG - 10:38:16 AM] [lint] glob paths:
[
“/usr/bin/gfortran”,
“/home/w.zifan1/.local/bin/fortls”,
This is the output result of a smaller project contains only one file.
[INFO - 10:47:20 AM] Extension Name: Modern Fortran
[INFO - 10:47:20 AM] Extension Version: 3.4.0
[INFO - 10:47:20 AM] Linter set to: “gfortran”
[INFO - 10:47:20 AM] Formatter set to: “findent”
[INFO - 10:47:20 AM] Autocomplete set to: “fortls”
[INFO - 10:47:20 AM] Hover set to: “fortls”
[INFO - 10:47:20 AM] Symbols set to: “fortls”
[INFO - 10:47:20 AM] [lint] Found GNU Fortran version 4.8.5
[DEBUG - 10:47:20 AM] [lint] Using Modern GNU Fortran diagnostics: false
[DEBUG - 10:47:20 AM] [lint] arguments:
[
“-ffree-line-length-none”,
“-ffixed-line-length-none”,
“-Wall”
]
[DEBUG - 10:47:20 AM] [lint] moduleOutput: -J /home/w.zifan1/.vscode-server/data/User/workspaceStorage/9ddb7715e7c71c8eaf64406ef507c128/fortran-lang.linter-gfortran/include
[DEBUG - 10:47:20 AM] [lint] Initialising cache for linter.includePaths
[DEBUG - 10:47:20 AM] [lint] glob paths:
[
“/usr/bin/gfortran”,
“/home/w.zifan1/.local/bin/fortls”,
“/home/w.zifan1”
]
[DEBUG - 10:47:20 AM] [lint] resolved paths:
[DEBUG - 10:47:20 AM] [build.single] compiler: “gfortran” located in: “/usr/bin/gfortran”
[INFO - 10:47:20 AM] [build.single] Compiler query command line: /usr/bin/gfortran -fsyntax-only -cpp -ffree-line-length-none -ffixed-line-length-none -Wall -J /home/w.zifan1/.vscode-server/data/User/workspaceStorage/9ddb7715e7c71c8eaf64406ef507c128/fortran-lang.linter-gfortran/include -ffree-form -o /cache1/fs1/home1/Active/home/w.zifan1/test_folder/test.f90.o /cache1/fs1/home1/Active/home/w.zifan1/test_folder/test.f90
[DEBUG - 10:47:20 AM] [lsp.client] Fortran Language Server – constructor
[DEBUG - 10:47:20 AM] [lsp.client] Language Server arguments:
[
“–enable_code_actions”,
“–hover_signature”,
“–use_signature_help”,
“–lowercase_intrinsics”,
“–nthreads=4”,
“–incremental_sync”
]
[ERROR - 10:47:20 AM] [lsp.client] Unable to verify input arguments with LS:
[DEBUG - 10:47:20 AM] [lsp.client] Language Server version: null
[DEBUG - 10:47:20 AM] [build.single] Compiler output:
[DEBUG - 10:47:20 AM] [lint] No linting diagnostics to show
[DEBUG - 10:47:20 AM] [lint] arguments:
[
“-ffree-line-length-none”,
“-ffixed-line-length-none”,
“-Wall”
]
[DEBUG - 10:47:20 AM] [lint] moduleOutput: -J /home/w.zifan1/.vscode-server/data/User/workspaceStorage/9ddb7715e7c71c8eaf64406ef507c128/fortran-lang.linter-gfortran/include
[DEBUG - 10:47:20 AM] [lint] glob paths:
[
“/usr/bin/gfortran”,
“/home/w.zifan1/.local/bin/fortls”,
“/home/w.zifan1”
]
[DEBUG - 10:47:20 AM] [lint] resolved paths:
[DEBUG - 10:47:20 AM] [build.single] compiler: “gfortran” located in: “/usr/bin/gfortran”
[INFO - 10:47:20 AM] [build.single] Compiler query command line: /usr/bin/gfortran -fsyntax-only -cpp -ffree-line-length-none -ffixed-line-length-none -Wall -J /home/w.zifan1/.vscode-server/data/User/workspaceStorage/9ddb7715e7c71c8eaf64406ef507c128/fortran-lang.linter-gfortran/include -ffree-form -o /cache1/fs1/home1/Active/home/w.zifan1/test_folder/test.f90.o /cache1/fs1/home1/Active/home/w.zifan1/test_folder/test.f90
[DEBUG - 10:47:20 AM] [build.single] Compiler output:
[DEBUG - 10:47:20 AM] [lint] No linting diagnostics to show
The logs say that there is no fortls installed.
What is the output of fortls --version
?
This is th result of fortls --version. It shows some error but when I try to install the fortls again to sais the requirements are already satisfied
e
You might want to try and installing some older fortls version since v2.1.2 appears to contain incompatible code with Python 3.6.
Try the following and start working backwards in versions until it works (available fortls versions)
pip install fortls==2.1.1
The underlying issue is that Python 3.6 has reached End Of Life in 2021-12-23 so developers (like us) have stopped writing code using only Python 3.6 feature. The only real solution is to use a version of Python (and an operating system) that is actively supported.
I have also been hit by this problem. I actually knew the cause of your problem already in the morning, but could not reply due to not having the forum password filled in on my mobile phone.
It can be quite difficult to diagnose and fix. At least it certainly was for me.
You can press Ctrl + Shift + P and search for Python: Select Interpreter. From the Python versions you have installed select a version that is recent enough. Restart VS Code. The correct version should now be used for the extensions as well. For me that manifests itself by having a #!/usr/bin/python3.11
shebang in the /home/username/.local/bin/fortls
file. Theoretically, you could try to insert there manually, but it could become overwritten by something else.