Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exact instructions how to setup fortls with neovim #426

Open
certik opened this issue Aug 20, 2024 · 5 comments
Open

Exact instructions how to setup fortls with neovim #426

certik opened this issue Aug 20, 2024 · 5 comments

Comments

@certik
Copy link
Member

certik commented Aug 20, 2024

I tried several times and always failed to get (any) LSP working with neovim, and I just figured it out specifically for fortls. I am documenting here the exact steps before I forget. We can later move this into fortls documentation.

The setup below does not destroy your current neovim setup. It makes it completely optional. You can use the NVIM_APPNAME environment variable to choose between setups.

  1. First install lazyvim:
# check that ~/.config/lazyvim does not exist. If it does, archive it, or change the directory below
git clone https://github.com/LazyVim/starter ~/.config/lazyvim
export NVIM_APPNAME=lazyvim
nvim some_file.f90

The first time you start neovim with this setup, it will load all plugins and install itself. The subsequent time will be quite fast (although not as fast as vanilla neovim unfortunately and there are other issues, such as flicker at startup, sometimes the cursor movement is lagging; so I do not have lazyvim on by default due to these issues).

  1. Install conda: Use https://github.com/conda-forge/miniforge and follow the instructions there.

  2. Install fortls:

mamba create -n fortls python
conda activate fortls
pip install fortls
echo 'require("lspconfig").fortls.setup({})' >> ~/.config/lazyvim/init.lua
nvim some_file.f90

Check that fortls is loaded using :checkhealth lsp. Now you can use the commands listed at https://dev.to/vonheikemen/getting-started-with-neovims-native-lsp-client-in-the-year-of-2022-the-easy-way-bp3. I found that the following three commands work: K, gd, gr. Here is an example of K:

image

Also TAB completion works in insert mode:

image

@certik
Copy link
Member Author

certik commented Aug 20, 2024

I think I figured out how to make it work without lazyvim.

git clone https://github.com/neovim/nvim-lspconfig ~/.config/nvim/pack/nvim/start/nvim-lspconfig

Add this into init.vim:

lua << EOF
require'lspconfig'.fortls.setup{}
EOF

(or just the middle line into init.lua)

Only K and gd works for me, here is K:

image

Yes, colors are not the best, but I am sure that can be fixed.

gd only finds the symbol in the current file, it doesn't seem to go to another file for some reason.

Tab completion does not work (maybe I don't know how to use it).

@gnikit
Copy link
Member

gnikit commented Sep 18, 2024

Just saw this @certik (sorry...). I use the native LSP implementation of neovim, to configure fortls and don't pass it through lazyvim since the language server will not activate unless a Fortran file is opened.
I add only a little stub to my init.lua

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

I added it to the docs when I switched from vim to neovim.

I will try and setup it up on my new mac and update the instructions if they are out of date.

@brucechan1123
Copy link

I don't understand why I can't get fortls attached with my f90 files when editing with neovim,
the LspInfo shows that there's no clients attached to the buffer, can you help me figure it out?
thanks.
Image

@certik
Copy link
Member Author

certik commented Nov 3, 2024

@brucechan1123 you are on Windows directly. Here is one way how to find the problem:

  • Try it in WSL first, using my instructions above. Verify that it works.
  • Then do it using your setup, but in WSL, ensure things still work
  • Then redo it in Windows directly

I haven't tried this in Windows directly yet.

@brucechan1123
Copy link

@brucechan1123 you are on Windows directly. Here is one way how to find the problem:

  • Try it in WSL first, using my instructions above. Verify that it works.
  • Then do it using your setup, but in WSL, ensure things still work
  • Then redo it in Windows directly

I haven't tried this in Windows directly yet.

Thanks a lot for offering advice!

I'm not so good at Operation systems, that I'm not sure the 'WSL' denotes windows subsystem linux or something.

However, accidently I tried to call Mason to uninstall forlts and re-install it, and the problem was just solved.

And Thank you anyway for offering advice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants