metakirby5 / codi.vim

:notebook_with_decorative_cover: The interactive scratchpad for hackers.
MIT License
3k stars 83 forks source link

Not show any thing after :Codi #130

Closed v6cc closed 3 years ago

v6cc commented 3 years ago

a.py

a = 3
b = 2
a * b

if use let g:codi#virtual_text=0 , not show any thing after :Codi

may be because the envirment, it correct works on my mac

and python, lua not work , typescript, javascript work

python node lua tsun already install

codi.log has many Garbled, don't know why ..

let plugPosition="~/.config/nvim/plugged"

call plug#begin(plugPosition)
Plug 'metakirby5/codi.vim'
call  plug#end()

let g:codi#log="/home/test/.config/nvim/codi.log"

if use let g:codi#virtual_text=1 , get this:

set0

Environment

codi.log

dky commented 3 years ago

I'm noticing the same thing. I'm running Neovim 0.4.4 + Python 3.9.0 on MacOS Big Sur. If I run Vim codi works fine with split text but the virtual text support is not working in neovim.

Like @zdmgmail I tried setting let g:codi#virtual_text=0 in hopes that the sidebar text would work but no dice.

EarlPitts commented 3 years ago

Same issue here, using arch with Neovim 0.4.4 and Python 3.9.1.

I found two things that seems to cause the error, at least on my machine:

  1. The control sequence that the preprocess function in autoload/codi.vim tries to substitute lacks a ? character. This can be fixed by adding a custom preprocess function to the codi config:
    
    function! s:pp_py(line)
    " Strip escape codes
    return substitute(a:line, "\<esc>".'\[?*[0-9;]*\a', '', 'g')
    endfunction

let g:codi#interpreters = { \ 'python': { \ 'bin': 'python', \ 'preprocess': function('s:pp_py'), \ }, \ }

Or modifying the preprocess function:

function! s:preprocess(text, ...) " Default pre-process let out = substitute(substitute(substitute(a:text, \ "\".'|'."\", '', 'g'), \ '(^|\n)(\^D)+', '\1', 'g'), \ "\".'[?[0-9;]\a', '', 'g') if a:0 && has_key(a:1, 'preprocess') let out = a:1'preprocess' endif return out endfunction

2. The second problem seems to be related to the `codi_nvim_callback` function.
It splits the line python sends back by carriage returns. The problem is that the lines containing the response from the interpreter has a carriage return in the middle of the line.
![2021-01-10_102749](https://user-images.githubusercontent.com/34306800/104119274-9054a700-532e-11eb-92fe-1c3cd5ffb7a6.png)
This causes the wrong outputs to be joined together, resulting in this:
![2021-01-10_103502](https://user-images.githubusercontent.com/34306800/104119444-85e6dd00-532f-11eb-8d35-d930e838a87b.png)
I fixed it by using a snippet from an earlier commit, that checked for carriage return only at the end of the line.

for line in a:data let s:nvim_async_lines[a:job_id] .= line

" If we hit a newline, we're ready to handle the data
if s:nvim_async_lines[a:job_id][-1:] == "\<cr>"
  let input = s:nvim_async_lines[a:job_id]
  let s:nvim_async_lines[a:job_id] = ''
  try
    call s:codi_handle_data(s:async_data[a:job_id], input)
  catch /E716/
    " No-op if data isn't ready
  endtry
endif

endfor


I've tested it for python, lua and javascript, and they seem to be working fine now.
dky commented 3 years ago

@EarlPitts would you happen to have a fork/branch I could try these fixes out on?

dky commented 3 years ago

@EarlPitts Doh!, I see your PR. Going to test that.

dky commented 3 years ago

@EarlPitts tested

Screen Shot 2021-01-10 at 12 40 48 PM

Works like a charm!

metakirby5 commented 3 years ago

Just merged #131, thanks @EarlPitts!

Closing as fixed.