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

Procedure argument completion #112

Closed
mcocdawc opened this issue May 21, 2019 · 7 comments
Closed

Procedure argument completion #112

mcocdawc opened this issue May 21, 2019 · 7 comments

Comments

@mcocdawc
Copy link
Contributor

mcocdawc commented May 21, 2019

I am using:
Neovim: 0.3.5
fortls: 1.8.2

and have a similar issue like here

Simply, when I complete a function which has arguments I get explicit placeholders and I couldn't find a way to rewind through them e.g.:

subroutine incr(a)                                                              
    integer, intent(inout) :: a(:)
    a = a + 1                                                                     
end subroutine

call incr(${1:a})

I would expect either no placeholders like in vanilla deoplete or some way to jump through various arguments until all placeholders are gone without leaving Insert mode.

@hansec
Copy link
Owner

hansec commented May 21, 2019

So it looks like the Neovim LS plugin doesn't support snippets with placeholders well. The solution from that issue seemed to be disabling snippets in autocomplete. I will work on adding support for this.

@mcocdawc
Copy link
Contributor Author

mcocdawc commented May 22, 2019

Thank you for the fast work on it! (And for this great program in general. ;-) )

I think it makes more sense if the snippet is:

                  if self.autocomplete_no_snippets:                                    
                      snippet = ''  

instead of snippet = call_sig.
At the moment It completes the whole signature which usually requires to delete it.
and this is not what I expect from an option --autocomplete_no_snippets.

If one does this change, then

  call plug#begin('~/.local/share/nvim/plugged')
  
  Plug 'autozimu/LanguageClient-neovim', {
                  \ 'branch': 'next',
                  \ 'do': 'bash install.sh',
                  \ }
          let g:LanguageClient_autoStart = 1
          let g:LanguageClient_autoStop = 0
          let g:LanguageClient_hasSnippetSupport = 0
          let g:LanguageClient_serverCommands = {
                          \ 'python': ['pyls'],
                          \ 'fortran': ['fortls', '--symbol_skip_mem', '--incremental_sync',
                          \             '--lowercase_intrinsics', '--autocomplete_no_snippets']
                          \ }
  
  Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
    let g:deoplete#enable_at_startup = 1
  Plug 'Shougo/neosnippet.vim'
    " Plugin key-mappings.
    " Note: It must be "imap" and "smap".  It uses <Plug> mappings.
    imap <C-k>     <Plug>(neosnippet_expand_or_jump)
    smap <C-k>     <Plug>(neosnippet_expand_or_jump)
    xmap <C-k>     <Plug>(neosnippet_expand_target)
  
    " SuperTab like snippets behavior.
    " Note: It must be "imap" and "smap".  It uses <Plug> mappings.
    imap <expr><TAB>
     \ pumvisible() ? "\<C-n>" :
     \ neosnippet#expandable_or_jumpable() ?
     \    "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
    smap <expr><TAB> neosnippet#expandable_or_jumpable() ?
    \ "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
  
    " For conceal markers.
    if has('conceal')
      set conceallevel=2 concealcursor=niv
    endif
  Plug 'Shougo/neosnippet-snippets'
  Plug 'Shougo/echodoc.vim'
          set cmdheight=2
          let g:echodoc#enable_at_startup = 1
          let g:echodoc#type = 'signature'
          set signcolumn=yes
  call plug#end()

leads to a nice behaviour for Fortran subroutines. (And only for them)
The call signature does not interrupt your typing flow, but is displayed at the bottom of the screen.
(Of course it would be even nicer to <TAB> through the parameters in insert mode, but from my limited understanding this requires some changes in neovim + language_client.)

While using these settings I found a bug (I can open a new Issue for this):
The display of the call signature is available only for subroutines not for functions.

subroutine incr(arg)                                                              
    integer, intent(inout) :: arg(:)
    arg = arg + 1                                                                     
end subroutine

integer function f(x)
    integer, intent(in) :: x
    f = 2 * x
end function

! Correctly displays the signature at the bottom of the screen.
call incr(
! Does not display the signature.
f(

I don't know if this a bug in echodoc or in fortls. But since echodoc should be language agnostic and works for languages that have only one kind of procedure, I guess it is a bug in fortls.

@hansec
Copy link
Owner

hansec commented May 22, 2019

I think some users like getting the call signature in the autocomplete, however it is obviously a subjective thing. On most platforms, when signatureHelp is supported, only the name is completed and the signature is provided as a separate pop-up (as you mentioned). However, it looks like the NeoVim client doesn't support signatureHelp at this time. I could add an additional option to autocomplete only the subroutine/function name, which I believe will give you the desired behavior.

As for the echodoc behavior, I don't think this is an issue with the language server. It is hard to tell completely but I think echodoc must be using some other mechanism to extract signatures, since it doesn't appear to interact with the language server client at all. However, I am not super familiar with Vim plugins and I didn't dig too deep so I certainly could be wrong. Even if it does though, I am pretty sure this would be an issue with how echodoc handles things since signatureHelp, autocomplete, etc. work as expected for both functions/subroutines.

@mcocdawc
Copy link
Contributor Author

I could add an additional option to autocomplete only the subroutine/function name, which I believe will give you the desired behavior.

That would be great. Thank you! Of course it is a subjective thing, but I am pretty sure, that I am not the only one who would like to use your tool in that way. (And actually I could solve it for myself in my local fortls.)

since signatureHelp, autocomplete, etc. work as expected for both functions/subroutines.

Did they work for you from inside neovim or another editor?

@mcocdawc
Copy link
Contributor Author

Apparently the echodoc documentation says:

  g:echodoc#type                          g:echodoc#type                              
                  The documentation display type.                                     
                  "echo": It uses the command line :echo.                             
                  "signature": It uses gonvim signature feature.                      
                  https://github.com/dzhou121/gonvim                              
                  "virtual": It uses neovim virtual text feature.                 
                  nvim_buf_set_virtual_text()                                     
                                                                                  
                  Default: "echo"    

So it seems to act independent of the language server client.

@Shougo
Copy link

Shougo commented May 22, 2019

g:echodoc#type is for only display type.

mcocdawc added a commit to mcocdawc/fortran-language-server that referenced this issue May 23, 2019
Complete only the name of procedures. Closes hansec#112
@mcocdawc
Copy link
Contributor Author

The issue with echodoc is solved. I made the mistake of testing one character function names. This works with echodoc.

integer function double(x)
    integer, intent(in) :: x
    double = 2 * x
end function

So a -autocomplete_name_only option is the only missing piece now.
I make a PullRequest in the same way as your -autocomplete_no_snippets commit.

hansec pushed a commit that referenced this issue May 28, 2019
Add option to complete only the name of procedures, fixes #112
@hansec hansec closed this as completed in 652771b May 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants