vim-ctrlspace / vim-ctrlspace

Vim Space Controller
1.75k stars 73 forks source link

Some commands fail with "Undefined variable: idx" #286

Closed bodograumann closed 3 years ago

bodograumann commented 3 years ago

Describe the bug When using e or y in the buffer list I get the following error:

Error detected while processing function ctrlspace#keys#Keypressed[14]..ctrlspace#keys#file#CopyFileOrBuffer[1]..ctrlspace#files#CopyFileOrBuffer[7]..120_get_selected_file_or_buff: line 2: E121: Undefined variable: idx E116: Invalid arguments for function bufname(idx)), a:mod) E116: Invalid arguments for function resolve(bufname(idx)), a:mod) E116: Invalid arguments for function fnamemodify(s:modes.File.Enabled ? file : resolve(bufname(idx)), a:mod)

To Reproduce Steps to reproduce the behavior:

  1. Open ctrlspace bar
  2. Press e

Version(s) (please complete the following information):

Additional context Maybe you accidentally pushed a broken WIP to the master branch?

Konfekt commented 3 years ago

Yes, somehow idx is undefined at

" autoload/ctrlspace/files.vim (line 23)
function! s:get_selected_file_or_buff(mod) abort
Konfekt commented 3 years ago

@jyscao Probably just missing an initial line

let idx = ctrlspace#window#SelectedIndex()
jyscao commented 3 years ago

@bodograumann sorry, just noticed this now. And yes, this is definitely a goof caused by the new feature I added. I'll fix this asap

jyscao commented 3 years ago

@bodograumann just pushed the fix, should be good now

@Konfekt that indeed was the problem. However while doing the initial debugging I stumbled upon a related bug, hence my not immediately applying your suggested fix. What happens is that the files list held by the s:Cache object was not being populated when the editor and plugin are first loaded, thus even with idx defined, Vim throws an index out of bounds error. This is also fixed now.

bodograumann commented 3 years ago

I now get different errors. When using i:

Error detected while processing function ctrlspace#keys#Keypressed[14]..ctrlspace#keys#file#GoToDirectory[1]..ctrlspace#files#GoToDirectory[12]..119_get_selected_file_or_buff[2]..119_get_selected_file[7]..function ctrlspace#keys#Keypressed[14]..ctrlspace#keys#file#GoToDirectory[1]..ctrlspace#files#GoToDirect ory[12]..119_get_selected_file_or_buff[2]..119_get_selected_file: line 6: E684: list index out of range: 23 Error detected while processing function ctrlspace#keys#Keypressed[14]..ctrlspace#keys#file#GoToDirectory[1]..ctrlspace#files#GoToDirectory: line 12: E171: Missing :endif

When pressing e or y:

Error detected while processing function ctrlspace#keys#Keypressed[14]..ctrlspace#keys#file#EditFile[1]..ctrlspace#files#EditFile[1]..119_get_selected_file_or_buff[2]..119_get_selected_file[7]..function ctrlspace#keys#Keypressed[14]..ctrlspace#keys#file#EditFile[1]..ctrlspace#files#EditFile[1]..119get selected_file_or_buff[2]..119_get_selected_file: line 6: E684: list index out of range: 23

jyscao commented 3 years ago

I tried to reproduce in a new editor session, press <ctrl>+<space> then one of e, y and i, and all are working normally for me.

Can you provide more detailed steps to reproduce?

jyscao commented 3 years ago

@bodograumann I have a hunch of what the problem might be for you. Try refreshing your file cache first, then invoke one of those keys.

I will try to implement a better fix to this.

jyscao commented 3 years ago

@bodograumann I pushed a better fix for this issue. Please test and let me know.

bodograumann commented 3 years ago

Yes! Now it is working perfectly again. Thank you for the fix. :heart: