File: editor_integration.rst

package info (click to toggle)
fortran-language-server 3.2.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,268 kB
  • sloc: python: 9,688; f90: 1,195; fortran: 30; makefile: 28; ansic: 20
file content (217 lines) | stat: -rw-r--r-- 7,768 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
Editor Integration
===================

`Visual Studio Code <https://code.visualstudio.com/>`__
-------------------------------------------------------

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.

.. _Modern Fortran: https://marketplace.visualstudio.com/items?itemName=fortran-lang.linter-gfortran

.. 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 <https://atom.io/>`__
---------------------------

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.

.. _language-fortran: https://atom.io/packages/language-fortran
.. _@dparkins: https://github.com/dparkins
.. _fortran-lsp: https://atom.io/packages/fortran-lsp
.. _@gnikit: https://github.com/gnikit
.. _ide-fortran: https://atom.io/packages/ide-fortran
.. _@hansec: https://github.com/hansec

`Sublime Text <https://www.sublimetext.com/>`__
-----------------------------------------------

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

.. code-block:: json

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

For more details see the LSP `documentation`_.

.. _LSP: https://github.com/sublimelsp/LSP
.. _Fortran: https://packagecontrol.io/packages/Fortran
.. _documentation: https://lsp.sublimetext.io/language_servers/#fortran


`neovim <https://neovim.io/>`__
-------------------------------

.. warning::
    For neovim versions < 0.5.0 follow the instructions in the :ref:`vim` section.

Neovim version >= 0.5.0 `natively supports LSP <https://neovim.io/doc/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:

.. code-block:: lua

    require'lspconfig'.fortls.setup{}


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


.. code-block:: lua

    require'lspconfig'.fortls.setup{
        cmd = {
            'fortls',
            '--lowercase_intrinsics',
            '--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{}**

.. _lspconfig: https://github.com/neovim/nvim-lspconfig
.. _Suggested configuration: https://github.com/neovim/nvim-lspconfig#suggested-configuration


.. _vim:

`Vim <https://www.vim.org/>`__
------------------------------

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

`YouCompleteMe <https://ycm-core.github.io/YouCompleteMe/>`__
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

`YouCompleteMe <https://github.com/ycm-core/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 <https://ycm-core.github.io/YouCompleteMe/#plugging-an-arbitrary-lsp-server>`__.

.. code-block:: vim

    " 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 <https://github.com/autozimu/LanguageClient-neovim>`__
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

.. code-block:: vim

    " 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)

.. _LanguageClient-neovim: https://github.com/autozimu/LanguageClient-neovim


`EMACS <https://www.gnu.org/software/emacs/>`__
-----------------------------------------------

`LSP Mode <https://emacs-lsp.github.io/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.

.. _lsp-mode: https://emacs-lsp.github.io/lsp-mode/page/installation
.. _lsp-clients-fortls-args: https://emacs-lsp.github.io/lsp-mode/page/lsp-fortran/#lsp-clients-fortls-args
.. _lsp-clients-fortls-executable: https://emacs-lsp.github.io/lsp-mode/page/lsp-fortran/#lsp-clients-fortls-executable


`Eglot <https://github.com/joaotavora/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

.. code-block:: elisp

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

.. _eglot: https://github.com/joaotavora/eglot


Visual Studio 2017
------------------

Installing this `VS17 extension`_ should enable ``fortls`` features in Visual Studio

.. _VS17 extension: https://github.com/michaelkonecny/vs-fortran-ls-client

`Kakoune <https://kakoune.org/>`__
----------------------------------

Install `kak-lsp <https://github.com/kak-lsp/>`_.

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

.. code-block:: sh

  [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:

.. code-block:: sh

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