Skip to content

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

Closed

Description

@hheinzer

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.

Activity

  1. Act0r1 commented on Jun 6, 2023

    @Act0r1

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

  2. hheinzer commented on Jun 7, 2023

    @hheinzer
    Author

    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',
        },
    })
    
  3. Act0r1 commented on Jun 7, 2023

    @Act0r1

    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

  4. hheinzer commented on Jun 7, 2023

    @hheinzer
    Author

    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.

  5. Act0r1 commented on Jun 7, 2023

    @Act0r1

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

  6. hheinzer commented on Jun 7, 2023

    @hheinzer
    Author

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

  7. added 2 commits that reference this issue on Jul 9, 2023
  8. folk85 commented on Jul 16, 2023

    @folk85
    Contributor

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

  9. gnikit commented on Jul 16, 2023

    @gnikit
    Member

    @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

  10. gnikit commented on Jul 16, 2023

    @gnikit
    Member

    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

  11. Act0r1 commented on Jul 16, 2023

    @Act0r1

    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

  12. folk85 commented on Jul 16, 2023

    @folk85
    Contributor

    @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

  13. added a commit that references this issue on Jul 22, 2023
  14. added a commit that references this issue on Jul 23, 2023
    1873065
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions