What is fortls? A plain-English guide to the Fortran Language Server
If you write Fortran in a modern editor and get autocompletion, hover documentation and “go to definition”, there is a good chance a program called fortls is doing the work in the background. This guide explains what it is, why it matters and how it fits into a normal development workflow.
What fortls is
fortls is an open-source language server for Fortran. It is a separate program, written in Python and installed with pip, that reads your Fortran source files and answers the questions an editor asks: what does this name refer to, which members does this derived type have, which procedures start with these letters. It is developed in the open by the fortran-lang community on GitHub. This website is independent and has no connection with that project.
The Language Server Protocol in two minutes
Editor features such as completion and navigation used to be built separately for every language and every editor, so a language needed a new plugin for each editor it wanted to support. The Language Server Protocol (LSP) removes that duplication. It defines a common set of messages exchanged between an editor (the client) and a language-specific program (the server).
In practice the editor starts the server, opens your project folder, and sends small requests such as “the cursor is on line 40, column 12; what is here?”. The server analyses the code and replies with hover text, a list of completions or a file location. Any editor that speaks LSP can use any server that speaks LSP, which is why one Fortran server can serve many editors.
Why it matters for Fortran
Fortran projects are often long-lived and large. Code is split across many modules and files, derived types carry procedures, and legacy fixed-form files sit beside modern free-form ones. Finding where something is defined with plain text search is slow and error-prone. A language server understands the structure instead of matching text.
The features you typically get are:
- Autocompletion for variables, procedures, modules and type members.
- Hover information showing declarations and signatures.
- Go to definition and find references across files.
- Symbol outlines for the current file and the whole workspace.
- Signature help while you type the arguments of a call.
- Some diagnostics for common mistakes. For full compiler errors, pair it with a compiler-based linter.
Supported editors
Because fortls speaks LSP, it works with any editor that has an LSP client. Commonly used combinations include:
- Visual Studio Code through the Modern Fortran extension, which can also lint with a compiler.
- Neovim through the built-in LSP client with nvim-lspconfig.
- Vim, Emacs and Sublime Text through their respective LSP plugins.
Plugin names and setup steps change over time, so check each editor’s documentation. Our resources page lists official starting points.
A typical workflow
- Install fortls, for example with
pip install fortls, and confirm it runs withfortls --version. - Install the editor integration for your editor (see the next article for VS Code).
- Open the project folder, not a single file, so the server can index the whole workspace.
- Add a
.fortlsfile in the project root if the defaults do not suit your layout. It is a small JSON file, for example:
{
"source_dirs": ["src/**"],
"excl_paths": ["build"],
"lowercase_intrinsics": true
}
The source_dirs option says where your sources live, excl_paths keeps build output out of the index, and lowercase_intrinsics controls the case of completed intrinsic names. You can create and check such a file with our free generator and validator; both run in your browser.
Benefits
- Faster navigation in unfamiliar code, which is valuable when joining a research code base.
- Fewer typos and mismatched arguments thanks to completion and signature help.
- Editor choice: you keep the editor you like instead of being tied to one IDE.
- Free and open source, with settings kept in a plain text file you can commit to version control.
Limitations to know about
fortls is not a compiler. It analyses source text on its own, so unusual preprocessor use, generated sources or very dynamic build setups may need extra configuration, such as include directories or preprocessor definitions. It also cannot replace compiler diagnostics. Treat it as a navigation and productivity layer and keep building with your compiler.
Conclusion
fortls brings the everyday conveniences of modern editors to Fortran without locking you into one tool. Install it, connect your editor, add a small .fortls file when needed, and you get faster navigation and fewer mistakes. Ready to try it? Read how to install fortls in VS Code, or open the free tools.
FORTLS.com is an independent community resource, not the official fortls project. Verify commands against the official documentation for your versions.