Merge pull request #110 from puremourning/neovim-env
Support setting environment in neovim
This commit is contained in:
commit
8c01ea7bfd
3 changed files with 56 additions and 20 deletions
|
|
@ -174,7 +174,6 @@ neovim doesn't implement some features Vimspector relies on:
|
|||
the output window's current output.
|
||||
* Prompt Buffers - used to send commands in the Console and add Watches
|
||||
* Balloons - used to display the values of variables when debugging.
|
||||
* Environment variables when laucnhing debugee in embedded terminal.
|
||||
|
||||
Workarounds are in place as follows:
|
||||
|
||||
|
|
@ -187,9 +186,6 @@ Workarounds are in place as follows:
|
|||
There is no workaroud for the lack of balloons; you'll just have to use
|
||||
`:VimspectorEval` or `:VimspectorWatch`, or switch to Vim.
|
||||
|
||||
The only workaround for the missing environment variables feature is to use
|
||||
neovim master (it doesn't work in neovim 0.4).
|
||||
|
||||
## Language dependencies
|
||||
|
||||
The debug adapters themselves have certain runtime dependencies:
|
||||
|
|
@ -732,10 +728,6 @@ session.
|
|||
|
||||
### Alternative: Use debugpy directly
|
||||
|
||||
*** NOTE: This solution does not work in NeoVim 0.4 due to missing environment
|
||||
variables support when launching a terminal. Do not raise issues about this if
|
||||
you are using NeoVim 0.4. ***
|
||||
|
||||
If you can't get a node 10 environment set up for whatver reason, then you can
|
||||
avoid that issue by using `debugpy` (formerly `ptvsd`) directly.
|
||||
|
||||
|
|
|
|||
|
|
@ -44,17 +44,27 @@ function! vimspector#internal#neojob#StartDebugSession( config ) abort
|
|||
return v:false
|
||||
endif
|
||||
|
||||
let s:job = jobstart( a:config[ 'command' ],
|
||||
\ {
|
||||
\ 'on_stdout': funcref( 's:_OnEvent' ),
|
||||
\ 'on_stderr': funcref( 's:_OnEvent' ),
|
||||
\ 'on_exit': funcref( 's:_OnEvent' ),
|
||||
\ 'cwd': a:config[ 'cwd' ],
|
||||
\ 'env': a:config[ 'env' ],
|
||||
\ }
|
||||
\ )
|
||||
|
||||
" FIXME: env might not work: Missing in neovim 0.4. But in master:
|
||||
" HACK: Workaround for 'env' not being supported.
|
||||
|
||||
let old_env={}
|
||||
try
|
||||
let old_env = vimspector#internal#neoterm#PrepareEnvironment(
|
||||
\ a:config[ 'env' ] )
|
||||
let s:job = jobstart( a:config[ 'command' ],
|
||||
\ {
|
||||
\ 'on_stdout': funcref( 's:_OnEvent' ),
|
||||
\ 'on_stderr': funcref( 's:_OnEvent' ),
|
||||
\ 'on_exit': funcref( 's:_OnEvent' ),
|
||||
\ 'cwd': a:config[ 'cwd' ],
|
||||
\ 'env': a:config[ 'env' ],
|
||||
\ }
|
||||
\ )
|
||||
finally
|
||||
call vimspector#internal#neoterm#ResetEnvironment( a:config[ 'env' ],
|
||||
\ old_env )
|
||||
endtry
|
||||
|
||||
return v:true
|
||||
endfunction
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,27 @@ set cpoptions&vim
|
|||
" FIXME: Tidy this map when buffers are closed ?
|
||||
let s:buffer_to_id = {}
|
||||
|
||||
function! vimspector#internal#neoterm#PrepareEnvironment( env ) abort
|
||||
let old_env = {}
|
||||
|
||||
let new_env = copy( environ() )
|
||||
for key in keys( a:env )
|
||||
if has_key( new_env, key )
|
||||
let old_env[ key ] = new_env[ key ]
|
||||
endif
|
||||
call setenv( key, a:env[ key ] )
|
||||
endfor
|
||||
|
||||
return old_env
|
||||
endfunction
|
||||
|
||||
function! vimspector#internal#neoterm#ResetEnvironment( env, old_env ) abort
|
||||
for key in keys( a:env )
|
||||
let value = get( a:old_env, key, v:null )
|
||||
call setenv( key, value )
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! vimspector#internal#neoterm#Start( cmd, opts ) abort
|
||||
if ! get( a:opts, 'curwin', 0 )
|
||||
if get( a:opts, 'vertical', 0 )
|
||||
|
|
@ -34,8 +55,21 @@ function! vimspector#internal#neoterm#Start( cmd, opts ) abort
|
|||
endif
|
||||
endif
|
||||
|
||||
" FIXME: 'env' doesn't work
|
||||
let id = termopen( a:cmd, { 'cwd': a:opts[ 'cwd' ] } )
|
||||
" HACK: Neovim's termopen doesn't support env
|
||||
|
||||
let old_env={}
|
||||
try
|
||||
let old_env = vimspector#internal#neoterm#PrepareEnvironment(
|
||||
\ a:opts[ 'env' ] )
|
||||
let id = termopen( a:cmd, {
|
||||
\ 'cwd': a:opts[ 'cwd' ],
|
||||
\ 'env': a:opts[ 'env' ],
|
||||
\ } )
|
||||
finally
|
||||
call vimspector#internal#neoterm#ResetEnvironment( a:opts[ 'env' ],
|
||||
\ old_env )
|
||||
endtry
|
||||
|
||||
let bufnr = bufnr()
|
||||
let s:buffer_to_id[ bufnr ] = id
|
||||
return bufnr
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue