Editor Integration

Visual Studio Code

The Language Server is natively supported through the Modern Fortran extension. Install fortls then install the extension and all the server’s features should be instantly available.

Important

Make sure that fortls is reachable in your $PATH. If not you can specify the option "fortran.fortls.path": "/custom/path/to/fortls"

Atom

Firstly fortls then install the language-fortran plugin by @dparkins to get Fortran syntax highlighting. Finally, install either fortran-lsp by @gnikit or ide-fortran by @hansec

Warning

fortran-lsp has been created solely for the fortls Language Server, hence it natively interfaces with fortls. ide-fortran was created for an older, now deprecated, Fortran Language Server hence the options available through the extension are not representative of fortls’s interface.

Sublime Text

Firstly, install fortls then install the LSP package from package control. Finally, install the Fortran package and add the following in your configuration

{
    "clients": {
        "fortls": {
            "enabled": true,
            "command": ["fortls", "--notify_init"],
            "selector": "source.modern-fortran | source.fixedform-fortran"
        }
    }
}

For more details see the LSP documentation.

neovim

Warning

For neovim versions < 0.5.0 follow the instructions in the Vim section.

Neovim version >= 0.5.0 natively supports LSP. To enable the native LSP functionality install the lspconfig plugin with your favourite plugin manager.

Then in your configuration file (i.e. init.lua) add the following:

require'lspconfig'.fortls.setup{}

If additional fortls options need to be passed to you can do that through the cmd option in setup{}

require'lspconfig'.fortls.setup{
    cmd = {
        'fortls',
        '--lowercase_intrisics',
        '--hover_signature',
        '--hover_language=fortran',
        '--use_signature_help'
    }
}

Important

If you are just starting with neovim it is strongly recommended using the Suggested configuration from lspconfig for keybingings and server attaching. Remember to attach the server during setup{}

Vim

Vim does not support LSP natively, so a 3rd party extensions need to be installed. A few options are available:

YouCompleteMe

YouCompleteMe is a popular Vim plugin and code-completion engine that also provides an LSP interface. You can therefore use it to register Language Servers like fortls.

For more information about configuring an arbitrary Language Server in YouCompleteMe, see here.

" YouCompleteMe configuration options
let g:ycm_language_server =
    \[
    \   {
    \       'name': 'fortls',
    \       'cmdline': ['fortls', '--hover_language', 'fortran', '--notify_init', '--hover_signature', '--use_signature_help'],
    \       'filetypes': ['fortran'],
    \       'project_root_files': ['.fortls'],
    \   },
    \]
nmap <leader>yfw <Plug>(YCMFindSymbolInWorkspace)
nmap <leader>yfd <Plug>(YCMFindSymbolInDocument)

LanguageClient-neovim

Firstly install the plugin LanguageClient-neovim. Then edit your ~/.vimrc settings file to set fortls for Fortran files

" Required for operations modifying multiple buffers like rename. set hidden
let g:LanguageClient_serverCommands = {
    " Add any default arguments you want fortls to have inside []
    \ 'fortran': ['fortls', '--hover_signature', '--hover_language', 'fortran', '--use_signature_help'],
    \ }

" note that if you are using Plug mapping you should not use `noremap` mappings.
nmap <F5> <Plug>(lcn-menu)
" Or map each action separately
nmap <silent>K <Plug>(lcn-hover)
nmap <silent> gd <Plug>(lcn-definition)
nmap <silent> <F2> <Plug>(lcn-rename)

EMACS

LSP Mode

Install the lsp-mode plugin. This should then allow for the variables lsp-clients-fortls-args and lsp-clients-fortls-executable to be defined in the ~/.emacs configuration file.

Eglot

Install the eglot package which supports fortls out of the box. This can be done in emacs version > 26.1 via M-x package-install RET eglot RET. Arguments to fortls can be provided in the form

(add-to-list 'eglot-server-programs '(f90-mode . ("fortls" "--notify_init" "--nthreads=4")))

Visual Studio 2017

Installing this VS17 extension should enable fortls features in Visual Studio

Kakoune

Install kak-lsp.

Edit the kak-lsp.toml config file to include:

[language.fortran]
filetypes = ["fortran"]
roots = [".git", ".fortls"]
command = "fortls"
args = ["--symbol_skip_mem", "--incremental_sync", "--autocomplete_no_prefix", "--lowercase_intrisics"]

Edit your kakrc config to enable kak-lsp, adding fortran as a filetype:

eval %sh{kak-lsp --kakoune -s $kak_session}
# lsp-enable
hook global WinSetOption filetype=(fortran) %{
  lsp-enable-window
}