OmniSharp / omnisharp-vim

Vim omnicompletion (intellisense) and more for C#
http://www.omnisharp.net
MIT License
1.72k stars 168 forks source link

Code Actions on class throw "Vim(let):E684: list index out of range: 0" when using Omnisharp_selector_ui = 'fzf' #574

Closed Melandel closed 4 years ago

Melandel commented 4 years ago

Hello,

I like this plugin a lot!

I noticed that with Omnisharp_selector_ui = '', the code actions at the level of class declarations, such as generate the constsructor, or generate substitutions..., or generate Equals(object) work correctly, while with Omnisharp_selector_ui = 'fzf' an error Vim(let):E684: list index out of range: 0 is thrown.

I am using gvim 8.2 on Windows, with the latest commits for all plugins.

Can you reproduce it?

nickspoons commented 4 years ago

I'll try reproducing it later when I'm at a computer, but first - do you have fzf working for other things in Vim. e.g. buffer selection and finding files?

Melandel commented 4 years ago

I can confirm that fzf does work for :History, :Buffers and :BLines - also with code actions regarding a method (for example Use expression body for methods

nickspoons commented 4 years ago

Ok, very interesting, I'll try to repro

Melandel commented 4 years ago

Thanks!

nickspoons commented 4 years ago

@Melandel I tried this out but can't reproduce. My code actions all work fine with fzf.

I'm using gvim 8.2.241.

Are you getting any more information on that error? A function name or line number perhaps?

What type of project? .NET framework? Core? Is there a repo I can test?

Melandel commented 4 years ago

I am using GVim 8.2 (x64) with included patch 1-430, compiled Mar 22 2020 (so I believe it's v8.2.0423)

There is a line number: 21.

Here's all the message I get:

Error detected while processing function 5[30]..<SNR>30_callback:
line    21:
Vim(let):E684: list index out of range: 0

The code I'm using is the direct output of the following command using dotnet core 3.1.102's cli:

dotnet new console -n helloWorld

It's a basic hello world, and I am using :OmniSharpGetCodeActions on the line n°4:

    class Program
nickspoons commented 4 years ago

Can you show the output of :scriptnames, so I can see what script number 30 is?

Melandel commented 4 years ago

oh, so that 30 means the 30th in :scriptnames?

I'm super glad I learned that.

The script number 30 is this one, which I copied from here in order to add it to my list of vim packages.

scriptnames (141 lines)
  1: ~/Desktop/tools/vim/_vimrc
  2: ~/Desktop/tools/vim/syntax/syntax.vim
  3: ~/Desktop/tools/vim/syntax/synload.vim
  4: ~/Desktop/tools/vim/syntax/syncolor.vim
  5: ~/Desktop/tools/vim/filetype.vim
  6: ~/Desktop/tools/vim/menu.vim
  7: ~/Desktop/tools/vim/lang/menu_fr.latin1.vim
  8: ~/Desktop/tools/vim/lang/menu_fr_fr.latin1.vim
  9: ~/Desktop/tools/vim/autoload/paste.vim
 10: ~/Desktop/tools/vim/ftplugin.vim
 11: ~/Desktop/tools/vim/indent.vim
 12: ~/Desktop/tools/vim/pack/plugins/start/vim-empower/colors/empower.vim
 13: ~/Desktop/tools/vim/pack/dist/opt/matchit/plugin/matchit.vim
 14: ~/Desktop/tools/vim/plugin/getscriptPlugin.vim
 15: ~/Desktop/tools/vim/plugin/gzip.vim
 16: ~/Desktop/tools/vim/plugin/logiPat.vim
 17: ~/Desktop/tools/vim/plugin/manpager.vim
 18: ~/Desktop/tools/vim/plugin/matchparen.vim
 19: ~/Desktop/tools/vim/plugin/netrwPlugin.vim
 20: ~/Desktop/tools/vim/plugin/rrhelper.vim
 21: ~/Desktop/tools/vim/plugin/spellfile.vim
 22: ~/Desktop/tools/vim/plugin/tarPlugin.vim
 23: ~/Desktop/tools/vim/plugin/tohtml.vim
 24: ~/Desktop/tools/vim/plugin/vimballPlugin.vim
 25: ~/Desktop/tools/vim/plugin/zipPlugin.vim
 26: ~/Desktop/tools/vim/pack/plugins/start/ale/plugin/ale.vim
 27: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/balloon.vim
 28: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/events.vim
 29: ~/Desktop/tools/vim/pack/plugins/start/fzf.vim/plugin/fzf.vim
 30: ~/Desktop/tools/vim/pack/plugins/start/fzfcore.vim/plugin/fzf.vim
 31: ~/Desktop/tools/vim/pack/plugins/start/gvimtweak/plugin/gvimtweak.vim
 32: ~/Desktop/tools/vim/pack/plugins/start/lightline.vim/plugin/lightline.vim
 33: ~/Desktop/tools/vim/pack/plugins/start/omnisharp-vim/plugin/OmniSharp.vim
 34: ~/Desktop/tools/vim/pack/plugins/start/omnisharp-vim/ftdetect/cake.vim
 35: ~/Desktop/tools/vim/pack/plugins/start/omnisharp-vim/ftdetect/csx.vim
 36: ~/Desktop/tools/vim/pack/plugins/start/targets.vim/plugin/targets.vim
 37: ~/Desktop/tools/vim/pack/plugins/start/ultisnips/plugin/UltiSnips.vim
 38: ~/Desktop/tools/vim/pack/plugins/start/ultisnips/autoload/UltiSnips/map_keys.vim
 39: ~/Desktop/tools/vim/pack/plugins/start/ultisnips/ftdetect/snippets.vim
 40: ~/Desktop/tools/vim/pack/plugins/start/vifm.vim/plugin/vifm.vim
 41: ~/Desktop/tools/vim/pack/plugins/start/vifm.vim/autoload/vifm/globals.vim
 42: ~/Desktop/tools/vim/pack/plugins/start/vifm.vim/ftdetect/vifm-rename.vim
 43: ~/Desktop/tools/vim/pack/plugins/start/vifm.vim/ftdetect/vifm.vim
 44: ~/Desktop/tools/vim/pack/plugins/start/vim-amake/plugin/amake.vim
 45: ~/Desktop/tools/vim/pack/plugins/start/vim-dadbod/plugin/dadbod.vim
 46: ~/Desktop/tools/vim/pack/plugins/start/vim-easy-align/plugin/easy_align.vim
 47: ~/Desktop/tools/vim/pack/plugins/start/vim-emoji-complete/plugin/emoji_complete.vim
 48: ~/Desktop/tools/vim/pack/plugins/start/vim-fugitive/plugin/fugitive.vim
 49: ~/Desktop/tools/vim/pack/plugins/start/vim-fugitive/ftdetect/fugitive.vim
 50: ~/Desktop/tools/vim/pack/plugins/start/vim-gitbranch/plugin/gitbranch.vim
 51: ~/Desktop/tools/vim/pack/plugins/start/vim-indent-object/plugin/indent-object.vim
 52: ~/Desktop/tools/vim/pack/plugins/start/vim-obsession/plugin/obsession.vim
 53: ~/Desktop/tools/vim/pack/plugins/start/vim-snippets/plugin/vimsnippets.vim
 54: ~/Desktop/tools/vim/pack/plugins/start/ultisnips/after/plugin/UltiSnips_after.vim
 55: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale.vim
 56: ~/Desktop/tools/vim/pack/plugins/start/lightline.vim/autoload/lightline.vim
 57: ~/Desktop/tools/vim/pack/plugins/start/vim-gitbranch/autoload/gitbranch.vim
 58: ~/Desktop/tools/vim/pack/plugins/start/lightline.vim/autoload/lightline/tab.vim
 59: ~/Desktop/tools/vim/pack/plugins/start/lightline.vim/autoload/lightline/colorscheme/deus.vim
 60: ~/Desktop/tools/vim/pack/plugins/start/lightline.vim/autoload/lightline/colorscheme.vim
 61: ~/Desktop/Session.vim
 62: ~/Desktop/tools/vim/scripts.vim
 63: ~/Desktop/tools/vim/syntax/conf.vim
 64: ~/Desktop/tools/vim/ftplugin/conf.vim
 65: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/util.vim
 66: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/linter.vim
 67: ~/Desktop/tools/vim/syntax/vim.vim
 68: ~/Desktop/tools/vim/syntax/python.vim
 69: ~/Desktop/tools/vim/pack/plugins/start/vim-css-color/after/syntax/vim.vim
 70: ~/Desktop/tools/vim/pack/plugins/start/vim-css-color/autoload/css_color.vim
 71: ~/Desktop/tools/vim/ftplugin/vim.vim
 72: ~/Desktop/tools/vim/indent/vim.vim
 73: ~/Desktop/tools/vim/pack/plugins/start/ale/ale_linters/vim/ale_custom_linting_rules.vim
 74: ~/Desktop/tools/vim/pack/plugins/start/ale/ale_linters/vim/vint.vim
 75: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/engine.vim
 76: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/command.vim
 77: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/history.vim
 78: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/sign.vim
 79: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/list.vim
 80: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/highlight.vim
 81: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/cursor.vim
 82: ~/Desktop/tools/vim/pack/plugins/start/ultisnips/syntax/snippets.vim
 83: ~/Desktop/tools/vim/pack/plugins/start/vim-css-color/after/syntax/python.vim
 84: ~/Desktop/tools/vim/syntax/sh.vim
 85: ~/Desktop/tools/vim/pack/plugins/start/ultisnips/ftplugin/snippets.vim
 86: ~/Desktop/tools/vim/autoload/dist/ft.vim
 87: ~/Desktop/tools/vim/syntax/html.vim
 88: ~/Desktop/tools/vim/syntax/javascript.vim
 89: ~/Desktop/tools/vim/pack/plugins/start/vim-css-color/after/syntax/javascript.vim
 90: ~/Desktop/tools/vim/pack/plugins/start/vim-css-color/syntax/colornames/extended.vim
 91: ~/Desktop/tools/vim/pack/plugins/start/vim-css-color/syntax/colornames/basic.vim
 92: ~/Desktop/tools/vim/syntax/vb.vim
 93: ~/Desktop/tools/vim/syntax/css.vim
 94: ~/Desktop/tools/vim/pack/plugins/start/vim-css-color/after/syntax/css.vim
 95: ~/Desktop/tools/vim/pack/plugins/start/vim-css-color/after/syntax/html.vim
 96: ~/Desktop/tools/vim/ftplugin/html.vim
 97: ~/Desktop/tools/vim/autoload/htmlcomplete.vim
 98: ~/Desktop/tools/vim/indent/html.vim
 99: ~/Desktop/tools/vim/indent/javascript.vim
100: ~/Desktop/tools/vim/pack/plugins/start/ale/ale_linters/html/alex.vim
101: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/handlers/alex.vim
102: ~/Desktop/tools/vim/pack/plugins/start/ale/ale_linters/html/fecs.vim
103: ~/Desktop/tools/vim/pack/plugins/start/ale/ale_linters/html/htmlhint.vim
104: ~/Desktop/tools/vim/pack/plugins/start/ale/ale_linters/html/proselint.vim
105: ~/Desktop/tools/vim/pack/plugins/start/ale/ale_linters/html/stylelint.vim
106: ~/Desktop/tools/vim/pack/plugins/start/ale/ale_linters/html/tidy.vim
107: ~/Desktop/tools/vim/pack/plugins/start/ale/ale_linters/html/writegood.vim
108: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/handlers/writegood.vim
109: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/node.vim
110: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/path.vim
111: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/handlers/fecs.vim
112: ~/Desktop/tools/vim/syntax/nosyntax.vim
113: ~/Desktop/tools/vim/pack/plugins/start/fzf.vim/autoload/fzf/vim.vim
114: ~/Desktop/setup/my_vimrc.vim
115: ~/Desktop/tools/vim/pack/plugins/start/vim-fugitive/autoload/fugitive.vim
116: ~/Desktop/tools/vim/pack/plugins/start/vim-fugitive/syntax/fugitive.vim
117: ~/Desktop/tools/vim/syntax/diff.vim
118: ~/Desktop/tools/vim/ftplugin/gitcommit.vim
119: ~/Desktop/tools/vim/ftplugin/git.vim
120: ~/Desktop/tools/vim/syntax/gitcommit.vim
121: ~/Desktop/tools/vim/pack/plugins/start/ale/ale_linters/gitcommit/gitlint.vim
122: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/python.vim
123: ~/Desktop/tools/vim/pack/plugins/start/ultisnips/autoload/UltiSnips.vim
124: ~/Desktop/tools/vim/pack/plugins/start/omnisharp-vim/ftplugin/cs/OmniSharp.vim
125: ~/Desktop/tools/vim/pack/plugins/start/omnisharp-vim/autoload/OmniSharp/util.vim
126: ~/Desktop/tools/vim/pack/plugins/start/omnisharp-vim/autoload/OmniSharp.vim
127: ~/Desktop/tools/vim/pack/plugins/start/omnisharp-vim/autoload/OmniSharp/proc.vim
128: ~/Desktop/tools/vim/ftplugin/cs.vim
129: ~/Desktop/tools/vim/indent/cs.vim
130: ~/Desktop/tools/vim/syntax/cs.vim
131: ~/Desktop/tools/vim/syntax/xml.vim
132: ~/Desktop/tools/vim/syntax/dtd.vim
133: ~/Desktop/tools/vim/pack/plugins/start/vim-css-color/after/syntax/xml.vim
134: ~/Desktop/tools/vim/pack/plugins/start/omnisharp-vim/autoload/OmniSharp/stdio.vim
135: ~/Desktop/tools/vim/pack/plugins/start/omnisharp-vim/ale_linters/cs/omnisharp.vim
136: ~/Desktop/tools/vim/pack/plugins/start/ale/ale_linters/cs/csc.vim
137: ~/Desktop/tools/vim/pack/plugins/start/ale/ale_linters/cs/mcs.vim
138: ~/Desktop/tools/vim/pack/plugins/start/ale/ale_linters/cs/mcsc.vim
139: ~/Desktop/tools/vim/pack/plugins/start/omnisharp-vim/autoload/ale/sources/OmniSharp.vim
140: ~/Desktop/tools/vim/pack/plugins/start/ale/autoload/ale/other_source.vim
141: ~/Desktop/tools/vim/pack/plugins/start/omnisharp-vim/autoload/fzf/OmniSharp.vim

Edit: I updated both fzf's binary from here (fzf-0.21.1-windows_amd64.zip), and fzf core's plugin script. I get the same error.

In order to reproduce, I found out the cursor has to be on a word in the line, not at the beginning (otherwise it says No code action found)

With my poor knowledge of vimscript and enough echomsg spamming, it seems like the function action_sink from omnisharp-vim/autoload/fzf/OmniSharp.vim is causing the exception, more precisely the line 29

  let action = filter(copy(s:actions), {i,v -> get(v, 'Name') ==# a:str})[0]

I must go to bed right now but I hope I was of any help!

On another note, I wanted to thank you so much for being so responsive and making me progress in my vimscript-fu (understanding what the mysterious numbers mean in the exception is going to help so much)

Also, I didn't think it was related, but maybe. This is what I get from :OmniSharpGetCodeActions with preview_ui = 'fzf': image

And that is what I get from the same command, with preview_ui = '' image

Sorry. I just noticed the difference just now.

nickspoons commented 4 years ago

Ooh, now I think I might see it. There's an encoding issue involved here. Your "é" characters are not appearing in fzf.

When you select an action, we are taking the action name from fzf and using that to select the correct action to pass back to OmniSharp-roslyn. Because of the encoding error, the name presumably no longer matches? I'll have a play and see if I can do this in a more robust way.

On another note, I wanted to thank you so much for being so responsive and making me progress in my vimscript-fu (understanding what the mysterious numbers mean in the exception is going to help so much)

You're welcome 😄. If you ever want to discuss/debug things in a chat environment, the OmniSharp slack group works well too - mostly quiet but the #vim channel there can be good.

nickspoons commented 4 years ago

OK I managed to reproduce the issue, by adding some "é" characters to my actions. I've come up with a solution - see the commit message for details.

I'm pretty sure this will fix it for you, @Melandel, but of course let me know if it doesn't and I'll re-open.

Melandel commented 4 years ago

The action now works, but removes all syntax highlighting from the file (which comes back when I enter then leave insert mode) :(

For some reason, I don't recall having the highlighting stripped off from the file when using a code action. But I am able to confirm that the syntax highlighting disappears when using GetCodeActions on any line of the file. Maybe I changed something in my config ?

I have always had let g:OmniSharp_highlight_types = 2.

If it's not an issue at the level of my config, it might be an interesting idea in terms of user experience to update the highlighting after using a code action. I'm going to investigate furthermore.

Also, for my own curiosity:

nickspoons commented 4 years ago

Try let g:OmniSharp_highlight_types = 3, which updates on all code changes. I agree that triggering highlighting after any code action would be a good idea.

nickspoons commented 4 years ago

I don't have good answers for your follow-up questions I'm afraid. All OmniSharp-vim here is send requests to the server, and present what it makes available. So it's the server that decides whether code actions should be available when the cursor is at the start of the line, or on a symbol. And also where the language settings come from.