metakirby5 / codi.vim

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

Trying a setup for PureScript #19

Closed oblitum closed 8 years ago

oblitum commented 8 years ago

I'm not having success trying a setup for PureScript (the plugin is working for Python as expected). I've put this snippet in my .vimrc:

let g:codi#interpreters = {
    \     'purescript': {
    \         'bin': ['pulp', 'psci'],
    \         'prompt': '^> ',
    \     },
    \ }

When I open vim and execute :Code purescript I get a message "No matching autocommands" and nothing happens when I write code. An example session of PureScript REPL is like the following:

❯❯❯ pulp psci
PSCi, version 0.9.2
Type :? for help

> import Prelude
> 2 + 2
4

> foo
Error found:
in module $PSCI
at  line 1, column 1 - line 1, column 1

  Unknown value foo

See https://github.com/purescript/purescript/wiki/Error-Code-UnknownName for more information,
or to contribute content related to this error.

>

Any help appreciated!

metakirby5 commented 8 years ago

Thanks for the issue report! Always excited to add support for a new language.

Would you mind telling me how to install the dependencies required to run pulp psci, preferably on OS X? I'm a bit unfamiliar with PureScript's tooling.

oblitum commented 8 years ago

There're precompiled binaries here: http://www.purescript.org/download/. Sorry but I'm on ArchLinux and here it's as easy as pacman -S purescript pulp.

oblitum commented 8 years ago

It's also available from NPM.

oblitum commented 8 years ago

Ah, the download page says it's on homebrew as well!

oblitum commented 8 years ago

http://www.purescript.org/learn/getting-started/ tells the initial steps to get to the pulp psci command.

metakirby5 commented 8 years ago

Seems to be working on my end, with your exact config:

The error message could use some touching up, but that's what preprocess is for.

Note I had to pulp init, and it only worked in that directory (which is the desired behavior, since it's supposed to mimc the underlying interpreter). It also is not instantaneous because pulp psci takes a little while to start up, and the interpreter is started from scratch every time. Are you able to reproduce this?

oblitum commented 8 years ago

The error message could use some touching up, but that's what preprocess is for.

Yes, I thought about that too, I'm interested in that.

Are you able to reproduce this?

Sadly no, I get almost no feedback, I just get the "No matching autocommands" message from vim.

metakirby5 commented 8 years ago

Interesting... could you post your Vim and script versions? And perhaps record a screencast with asciinema if possible? Please show a successful run of pulp psci before you run vim -c 'Codi purescript'.

Regarding preprocess, you can basically clean up the output of the interpreter before it's handed off to the formatter, to git rid of messages that aren't useful. I currently have a line-wise preprocessor API, but I will probably have to change it to a buffer-wise API to accommodate multi-line error messages.

oblitum commented 8 years ago

This is my asciinema, it contains the vim version too: https://asciinema.org/a/bmmdzcgmiaheo3adwigsjq4bp

metakirby5 commented 8 years ago

It appears that Python isn't working quite correctly either (4 doesn't show up). Can you paste the output of man script? I'm interested in the date, since old versions of script have been an issue.

oblitum commented 8 years ago
script --version
script from util-linux 2.28

Python is working AFAIK, 4 is shown in the asciinema, maybe you have to replay it because this tool seems to cut some frames at random.

oblitum commented 8 years ago

By the way. The date at the bottom of man script is June 2014.

oblitum commented 8 years ago

It comes from this package on ArchLinux: https://www.archlinux.org/packages/core/i686/util-linux/

metakirby5 commented 8 years ago

Ah, I see that the text is a little cut off on the side on Asciinema - I believe you that it works correctly though. In any case, I'm able to reproduce the issue on my Ubuntu VM, and it has to do with script and/or Vim's job system not liking the space in pulp psci. The intermediate output is something like:

script -qfec 'pulp psci' /dev/null
bash: -c: line 0: unexpected EOF while looking for matching `''
bash: -c: line 1: syntax error: unexpected end of file 

...which is odd, since there is clearly a matching end quote. I haven't found a solution yet, but just wanted to give an update.

oblitum commented 8 years ago

Thanks for the report.

You're on the track but weirdly for me here on ArchLinux your command script -qfec 'pulp psci' /dev/null enters the REPL without problems. Anyway, I then created a script pulp_psci that's just pulp psci to try the plugin using a single command and it now started to work!

Some things I've noticed:

oblitum commented 8 years ago

As you said before:

It also is not instantaneous because pulp psci takes a little while to start up, and the interpreter is started from scratch every time.

That should be the reason why I'm seeing this slowness.

oblitum commented 8 years ago

I've found a fix, it looks like an issue with the new job API from Vim, I think this should be fixed upstream.

Your script does:

let job = job_start(cmd, { 'callback': 'codi#__callback' })

where cmd is 'script -qfec '.shellescape('pulp psci', 1).' /dev/null', which end up as "script -qfec 'pulp psci' /dev/null", since shellescape will use single quotes, per docs, for strings containing whitespace. If you check :h job_start:

        [snip]
        {command} can be a String.  This works best on MS-Windows.  On
        Unix it is split up in white-separated parts to be passed to
        execvp().  Arguments in double quotes can contain white space.

        {command} can be a List, where the first item is the executable
        and further items are the arguments.  All items are converted
        to String.  *This works best on Unix*.
        [snip]

Notice how the first paragraph seems incompatible with shellescape given the arguments containing whitespace are expected with double-quotes.

Learning that I've then patched the script with the following:

let job = job_start('script -qfec "pulp psci" /dev/null', { 'callback': 'codi#__callback' })

Which, strangely, didn't work either! Since it's following the docs, looks like some bug, or just not to be used on Linux.

I've then followed the second paragraph and did:

let job = job_start(['script', '-qfec', 'pulp psci', '/dev/null'], { 'callback': 'codi#__callback' })

This worked! So, you should use job_start that way for best compatibility with *nix.

cc @Shougo

Shougo commented 8 years ago

cc @Shougo

Hi, what's?

oblitum commented 8 years ago

@Shougo I've just cc you because I recall you implemented the job api on Vim right? It's just to inform you of these issues regarding commands containing whitespace/quotation.

Shougo commented 8 years ago

Hm. OK. It should be reported to upstream. But to escape arguments is very difficult. I recommend for you to use the arguments list.

metakirby5 commented 8 years ago

@oblitum Wow, I had no idea how I missed the list command form of job_start! That actually makes things a lot easier. Expect a commit addressing this soon.

@Shougo Thanks for chiming in and reporting :)

metakirby5 commented 8 years ago

@oblitum Can you check out the user/metakirby5_2 branch (I sure am bad at naming) and see if it works for you?

oblitum commented 8 years ago

@metakirby5 yes, it fixes.

Just a reminder that the spurious "No matching autocommands" message is still present.

metakirby5 commented 8 years ago

The only thing I can think of that would be causing that is the user autocommands. I've added a wrapper around the triggers which checks if they exist - can you pull again and see if it resolves the issue?

oblitum commented 8 years ago

Sadly it didn't work, the message still shows up.

oblitum commented 8 years ago

One thing though. I've noticed the message shows up for :Codi purescript and not for :Codi python, despite the last commit being applied or not.

metakirby5 commented 8 years ago

That's certainly interesting... would you happen to have any other plugins installed for the purescript filetype? Could you try running :Codi purescript using a .vimrc that contains nothing but the Codi-related plugin calls and settings?

oblitum commented 8 years ago

Spot on, I've tried here and found out that the message shows up only when FrigoEU/psc-ide-vim is on my plugin list. I've then removed code.vim from the plugin list while leaving just psc-ide-vim and tried set ft=purescript just after opening vim and the message appeared. So, this is a psc-ide-vim issue.

metakirby5 commented 8 years ago

Great that we've isolated the problem! I'll go ahead and merge this in and close the issue.

oblitum commented 8 years ago

OK. Thanks for the help! Feel free to embed PureScript support.

metakirby5 commented 8 years ago

I think I'll actually leave PureScript out due to the caveat of requiring a pulp init. Since Codi is meant to be a scratchpad, it should ideally work anywhere as long as you have the interpreter. If there is enough demand for languages that require similar prerequisites, I'll give it some more thought :)

oblitum commented 8 years ago

OK. Just like to comment that in PureScript development, AFAIK, it's always expected to run REPL inside a project, so it's not a problem to expect that from the user. In PureScript one starts the REPL in context with a project to try out importing its own code/library and playing with it.

metakirby5 commented 8 years ago

Hmm... seems reasonable. However, running :Codi purescript outside of a project provides no indication of what's not working, which is problematic for built-in behavior. I think I might need to add an optional 'precondition' which allows user-defined checking of dependencies such as having run pulp init. Since PureScript is the only language which requires this particular attribute, I don't want to introduce this quite yet. I'll open up an enhancement issue for this, though!

oblitum commented 8 years ago

OK. Thanks anyway, being configurable as it is is a pretty good option.

oblitum commented 8 years ago

For information. The vim message issue has been fixed in the affected plugin https://github.com/FrigoEU/psc-ide-vim/issues/17