metakirby5 / codi.vim

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

[Feature Request] Java and Scala support #92

Open bynux-gh opened 6 years ago

bynux-gh commented 6 years ago

With Java being one of the most ubiquitous languages in use, and Scala one of its best alternatives, support for these languages would be an extremely useful feature. Both languages have built-in REPL tools (jshell with Java 8+, and the scala command for Scala).

I'll take a look into the Vimscript and submit a pull request if I can get either language working.

metakirby5 commented 6 years ago

Thanks for offering to take a look :) This section in the docs should be helpful to look at. Let me know if you have any questions!

bynux-gh commented 6 years ago

I've put together the interpreters how I'd expect them to work, but based on g:codi#log it seems the REPLs for both Scala and Java are running too slowly to show a prompt, let alone return any values.

Here's an example of results I'm getting from the log. Maybe an extra pair of eyes could parse through it and figure out what I'm doing wrong, or if jshell and scala are just weird somehow.

I do notice a spike in CPU usage when typing while Codi is on, and the logs confirm that something's happening behind the scenes. I'm wondering if they need preprocessor functions or something, but the logs make it look like the interpreters are just "giving up" before anything meaningful can be returned.

It may also be a problem with my machine, though I'm running an upper-mid-tier processor.

The code I added:

" From codi.vim/autoload/codi/load.vim - starting at Line 179
"      \ 'julia': {
"         \ 'bin': ['julia', '-qi', '--color=no', '--history-file=no'],
"         \ 'prompt': '\(julia> \)',
"         \ 'preprocess': function('s:pp_remove_esc'),
"         \ },
       \ 'java': {
          \ 'bin': 'jshell',
          \ 'prompt': '\(jshell> \)',
          \ },
       \ 'scala': {
" Remove color from prompt to avoid ANSI escape codes.
          \ 'bin': ['scala', '-Dscala.color=false'], 
          \ 'prompt': '\(jshell> \)',
       \ },
    \ }
"function! codi#load#interpreters()
" return s:deep_extend(s:codi_default_interpreters, g:codi#interpreters)
"endfunction
"...
metakirby5 commented 6 years ago

Not sure what's wrong with jshell - it seems that the executable is just not giving us the rest of the output we want. For scala however, you just have the wrong prompt; replace it with ^scala>. The output is not formatted correctly for consumption, so some work will have to be done there.

bynux-gh commented 6 years ago

For scala however, you just have the wrong prompt...

Oh...right. :sweat_smile: