fortran-lang / fortls

fortls - Fortran Language Server
https://fortls.fortran-lang.org/
MIT License
257 stars 41 forks source link

Type fields or methods are not detected if spaces are used around % #286

Closed hheinzer closed 1 year ago

hheinzer commented 1 year ago

Describe the bug To gfortran, it does not make a difference, if I use spaces around the % operator. However, if I use them, fortls is unable to find the symbol (jump to it's definition).

To Reproduce In the following program, if you try to jump to the definition of a, it works. If you try to jump to the definition of b, it does not work. The code compiles and runs find, without any error or warnings under gfortran 13.1.1.

program test

    type :: some_type
        integer :: a
        real :: b
    end type some_type

    type(some_type) :: t

    t = some_type(1, 2.0)

    print *, t%a, t % b

end program test

I am using fortls 2.13.0 through neovim lsp. My configuration is

require('lspconfig').fortls.setup({
    on_attach = on_attach,
    flags = lsp_flags,
    capabilities = capabilities,
    cmd = {
        'fortls',
        '--notify_init',
        '--sort_keywords',
        '--lowercase_intrinsics',
        '--hover_signature',
        '--use_signature_help',
    },
})

Expected behavior The cursor should jump to the definition of b, the same way it does for a.

Act0r1 commented 1 year ago

hi, can you show your nvim lspconfig? I just can't install lsp servers

hheinzer commented 1 year ago

Sure:

local on_attach = function(client, bufnr)
    vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
    local bufopts = { noremap = true, silent = true, buffer = bufnr }
    vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
    vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
    vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
    vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
    vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
    vim.keymap.set('n', '<leader>r', vim.lsp.buf.rename, bufopts)
    vim.keymap.set('n', '<leader>F', vim.lsp.buf.format, bufopts)
end
local lsp_flags = {
    debounce_text_changes = 150,
}
local capabilities = require('cmp_nvim_lsp').default_capabilities({
    vim.lsp.protocol.make_client_capabilities()
})
require('lspconfig').fortls.setup({
    on_attach = on_attach,
    flags = lsp_flags,
    capabilities = capabilities,
    cmd = {
        'fortls',
        '--notify_init',
        '--sort_keywords',
        '--lowercase_intrinsics',
        '--hover_signature',
        '--use_signature_help',
    },
})
Act0r1 commented 1 year ago

Yeah, thank you very much, last night I did take it and installed, but without attach, say pls, it is necessary use attach in installation?) Thank you

hheinzer commented 1 year ago

As I understand it, the on_attach function defines the key mappings to interact with lsp. So when you press gd, for example, you jump to the definition of the symbol under the cursor.

Act0r1 commented 1 year ago

Yeah, but I install another lsp servers like pyright and rust_analyzer, there are work, but I don't don't attach it

hheinzer commented 1 year ago

They might come with default key bindings. Doing it this way allows you to have the same key bindings across all lsp servers.

folk85 commented 1 year ago

@gnikit , I updated the code tests. Could you review the changes?

gnikit commented 1 year ago

@gnikit , I updated the code tests. Could you review the changes?

@folk85 Your Pull request is out of date, can you please rebase to master. I will have a look again

gnikit commented 1 year ago

hi, can you show your nvim lspconfig? I just can't install lsp servers

@Act0r1 maybe this can be of help https://fortls.fortran-lang.org/editor_integration.html#neovim

Act0r1 commented 1 year ago

hi, can you show your nvim lspconfig? I just can't install lsp servers

@Act0r1 maybe this can be of help https://fortls.fortran-lang.org/editor_integration.html#neovim

I already solved, thank you

folk85 commented 1 year ago

@gnikit , I updated the code tests. Could you review the changes?

@folk85 Your Pull request is out of date, can you please rebase to master. I will have a look again

Done