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

Fix async direnv on Vim 8.0 #4

Merged
merged 1 commit into from
Dec 26, 2017
Merged

Fix async direnv on Vim 8.0 #4

merged 1 commit into from
Dec 26, 2017

Conversation

halostatue
Copy link
Contributor

With the version of Vim 8.0 I have (MacVim, 8.0, patches 1-1272), I am getting this error with direnv.vim:

  Error detected while processing function
  .../direnv.vim/plugin/direnv.vim|60| direnv#export[14]
  E475: Invalid argument: stderr

It appears that in Vim 8.0, the dictionary provided to the job must not have any keys except the callback keys, unlike with neovim.

After several experimental implementations, this is the one that works.

With the version of Vim 8.0 I have (MacVim, 8.0, patches 1-1272), I am getting
this error with direnv.vim:

  Error detected while processing function
  .../direnv.vim/plugin/direnv.vim|60| direnv#export[14]
  E475: Invalid argument: stderr

It appears that in Vim 8.0, the dictionary provided to the job must not have
any keys *except* the callback keys, unlike with neovim.

After several experimental implementations, this is the one that works.
@zimbatm
Copy link
Member

zimbatm commented Dec 11, 2017

I don't have enough Vimscript experience to have good judgement here. @hauleth did a big change in #3 so I will leave it up to him to do the review.

Can you ping me again in a week if nothing is happening here?

\ }
endif

function! direnv#export() abort
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting this function to autoload folder makes no sense as it is launched on VimEnter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is launched on VimEnter, but it requires access to s:job_status and s:direnv_cmd, which it won’t have if it remains in plugin/direnv.vim. It wouldn’t be hard to rewrite this to just use s: functions, but given that direnv#export() is available, it is typical in the VimL that I’ve seen to put functions defined that way in autoload/.

let s:direnv_auto = get(g:, 'direnv_auto', 1)
let s:job_status = { 'running': 0, 'stdout': [''], 'stderr': [''] }

function! direnv#auto() abort
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this function to autoload makes no sense as it is launched always when sourcing plugin/direnv.vim.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only moved this because of line 8 (the moving of let s:direnv_auto); it’s probably not necessary to move.

" Author: zimbatm <http://zimbatm.com/> & Hauleth <[email protected]>
" Version: 0.3

scriptencoding utf-8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for that, as there are no non-ASCII characters in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve generally taken the habit of putting that in there all the time. It’s not necessary, but it shouldn’t hurt.

@hauleth
Copy link
Contributor

hauleth commented Dec 11, 2017

Ok, I will fix this issue later.

let s:direnv_auto = get(g:, 'direnv_auto', 1)
let s:job_status = { 'running': 0, 'stdout': [''], 'stderr': [''] }

function! direnv#auto() abort
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only moved this because of line 8 (the moving of let s:direnv_auto); it’s probably not necessary to move.

\ }
endif

function! direnv#export() abort
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is launched on VimEnter, but it requires access to s:job_status and s:direnv_cmd, which it won’t have if it remains in plugin/direnv.vim. It wouldn’t be hard to rewrite this to just use s: functions, but given that direnv#export() is available, it is typical in the VimL that I’ve seen to put functions defined that way in autoload/.

call delete(l:tmp)
endif
endfunc
" MacVim (vim 8.0) with patches 1-1272 throws an error if a job option is given
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is not necessary, as it describes an earlier attempt, where I attempted to have s:job_status (the way that it is defined that works for neovim) be assigned to s:job on neovim and then have a simple s:job with the necessary callback that forwards to the functions on s:job_status. I couldn’t get that working at all (a lot of errors about dictionary function called with no dictionary, but apparently in the async job handler called by job_start()). Thus, the move to separate functions from callbacks entirely.

endfunction

function! direnv#on_stdout(_, data, ...) abort
let s:job_status.stdout = a:data
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the previous form of this (let s:job_status.stdout[-1] = a:data[0]; call extend(s:job_status.stdout, a:data[1])) I was getting out-of-range errors if the output was empty (particularly with the .stderr version).

@hauleth
Copy link
Contributor

hauleth commented Dec 11, 2017

@halostatue could you please check my fix on #6?

@replaid replaid mentioned this pull request Dec 22, 2017
@replaid
Copy link

replaid commented Dec 22, 2017

@zimbatm Ping, it's been 11 days.

@halostatue
Copy link
Contributor Author

There’s some back and forth on possible fixes that are less invasive in #6, but I haven’t seen movement in that in a couple days (and the base fixes in #6 do not fix all of the issues, but I don’t know if the array/extend trick is an nvim optimization or not)

@zimbatim asked for assistance with CI (#5?) that I’ve gad no time to help with and I don’t use nvim (no good Mac GUI yet).

I’m not sure whether I’m running this or my modified version of #6, but both work beautifully for me so MacVim in both modes.

@zimbatm zimbatm merged commit 2d1d455 into direnv:master Dec 26, 2017
@zimbatm
Copy link
Member

zimbatm commented Dec 26, 2017

I'm just going to merge this since @halostatue hasn't come back to us

@halostatue halostatue deleted the silence-vim-errors branch December 26, 2017 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants