{"id":8180,"library":"fortls","title":"Fortran Language Server (fortls)","description":"fortls is an implementation of the Language Server Protocol (LSP) for Fortran, built with Python 3.7+. It provides rich editor features like code completion, diagnostics, hover information, and symbol navigation for Fortran code. The current version is 3.2.2. It maintains an active development pace with frequent updates and major releases, like v3.0.0 in May 2024, introducing significant changes and new features.","status":"active","version":"3.2.2","language":"en","source_language":"en","source_url":"https://github.com/fortran-lang/fortls","tags":["Fortran","Language Server Protocol","LSP","IDE","editor integration","code completion","diagnostics","linting"],"install":[{"cmd":"pip install fortls","lang":"bash","label":"PyPI"},{"cmd":"conda install -c conda-forge fortls","lang":"bash","label":"Anaconda"},{"cmd":"brew install fortls","lang":"bash","label":"Homebrew"}],"dependencies":[{"reason":"fortls is a Python application and requires Python >= 3.7.","package":"python","optional":false}],"imports":[{"note":"While 'fortls' is typically run as an executable, it can be imported for programmatic interaction or testing, although this is less common for end-users.","symbol":"fortls","correct":"import fortls"}],"quickstart":{"code":"# To run fortls as a language server, it's typically launched by a code editor.\n# From the command line, you can verify its installation and basic functionality:\n# Run the server directly (usually done by an LSP client):\n# fortls\n\n# Or check the version:\nimport subprocess\n\ntry:\n    result = subprocess.run(['fortls', '--version'], capture_output=True, text=True, check=True)\n    print(f\"fortls version: {result.stdout.strip()}\")\nexcept FileNotFoundError:\n    print(\"Error: 'fortls' executable not found. Ensure it's installed and in your PATH.\")\nexcept subprocess.CalledProcessError as e:\n    print(f\"Error running fortls: {e}\\n{e.stderr}\")\n\n# To integrate with VS Code, install the 'Modern Fortran' extension.\n# It will automatically prompt to install and use fortls.\n# For other editors, refer to the 'Editor Integration' section in fortls documentation.\n","lang":"python","description":"fortls is a language server and is primarily used by code editors that support the Language Server Protocol (LSP). The quickstart demonstrates how to verify the `fortls` executable is installed and accessible. For most users, integration involves installing an editor extension (e.g., 'Modern Fortran' for VS Code) which then manages `fortls` automatically."},"warnings":[{"fix":"Review the official fortls documentation and changelog on GitHub for v3.0.0 and subsequent releases. Update editor configurations if necessary. Consider clearing any old configuration files like `.fortlsrc` if encountering issues.","message":"Major release v3.0.0 (May 2024) introduced significant internal changes and new features, potentially affecting configurations or custom integrations that relied on older internal behaviors. Users are advised to review the changelog for detailed updates.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Uninstall `fortran-language-server` before installing `fortls` (e.g., `pip uninstall fortran-language-server`). If both are installed, uninstall `fortran-language-server` and then reinstall `fortls` to ensure proper setup.","message":"It is strongly NOT recommended to have both `fortls` and `fortran-language-server` installed simultaneously. They use the same executable name, leading to conflicts and unpredictable behavior.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Manually add the `pip` scripts directory (e.g., `C:\\Users\\<username>\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.<version>\\LocalCache\\local-packages\\Python<version>\\Scripts`) to your system's PATH environment variable, or explicitly configure the `fortls` executable path in your editor's settings (e.g., `\"fortran.fortls.path\": \"C:\\path\\to\\fortls.exe\"` for VS Code).","message":"On Windows, if `pip` install location is not in your system's PATH, editor integrations (like VS Code) may not find the `fortls.exe` executable.","severity":"gotcha","affected_versions":"All versions on Windows"},{"fix":"To disable auto-updating, use the `--disable_autoupdate` command-line option when running `fortls`, or add `\"disable_autoupdate\": true` to your `.fortlsrc` configuration file.","message":"fortls automatically checks PyPI for newer versions and attempts to update itself by default. While this ensures users generally run the latest version, it can be problematic if new versions introduce breaking changes or if a specific version needs to be pinned.","severity":"gotcha","affected_versions":"All versions with autoupdate enabled"},{"fix":"Configure `fortls` with the `--nthreads` option to limit the number of threads used during initialization (default is 4). Exclude unnecessary directories and file types from parsing using `--excl_paths` and `--excl_suffixes` in the command line or `.fortlsrc` configuration file. If possible, upgrade server hardware or test with smaller subsets of the codebase.","message":"For large or complex Fortran projects, `fortls` initialization can take a long time and consume significant system resources (CPU and RAM), potentially leading to editor unresponsiveness or server lag.","severity":"gotcha","affected_versions":"All versions, especially with large codebases"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure `fortls` is installed in the active Python environment. Add the Python scripts directory (where `fortls.exe` is located) to your system's PATH. Alternatively, configure your editor to explicitly point to the `fortls` executable's full path.","cause":"The 'fortls' executable is not in the system's PATH environment variable, or the Python environment where it was installed is not active. This is common on Windows or when using virtual environments.","error":"Error: 'fortls' executable not found."},{"fix":"First, ensure `fortran-language-server` is uninstalled. If the issue persists, try reinstalling `fortls` (`pip install fortls --upgrade`). Verify your project's `.fortlsrc` configuration file or editor settings (e.g., `source_dirs`, `include_dirs`, `pp_defs`) correctly point to your Fortran source files and necessary preprocessor definitions. Restart your code editor after making changes.","cause":"This can be caused by conflicts with the `fortran-language-server` package, an outdated `fortls` installation, or incorrect project configuration (e.g., missing source directories or preprocessor definitions).","error":"LSP feature (e.g., hover, autocompletion) not working or showing incorrect results."},{"fix":"Limit the number of threads `fortls` uses for initialization with the `--nthreads` command-line option. Configure `.fortlsrc` or command-line arguments to exclude unnecessary directories (`--excl_paths`) or file types (`--excl_suffixes`) from being parsed. If possible, identify and isolate the problematic Fortran files or directories.","cause":"The language server is likely parsing a very large codebase, potentially with complex or non-standard Fortran, or it may be stuck on a particular file. This can exhaust system memory and CPU.","error":"fortls initialization never ending / taking too long and consuming excessive resources."},{"fix":"Currently, there is no direct fix within `fortls` for this specific limitation. Users should refer to the full documentation for overloaded procedures if the basic hover/signature help is insufficient. Keep `fortls` updated, as future releases might improve support.","cause":"This is a known limitation of `fortls` due to the complexity of parsing overloaded functions in Fortran.","error":"Signature help and hover does not handle elegantly overloaded functions i.e. interfaces."}]}