ternjs / tern

A JavaScript code analyzer for deep, cross-editor language support
https://ternjs.net/
MIT License
4.25k stars 378 forks source link

CoffeeScript #226

Open Tranquility opened 10 years ago

Tranquility commented 10 years ago

Is there a way to use tern with CoffeeScript (in vim)?

marijnh commented 10 years ago

There's a hack at https://github.com/mntmn/tern-coffeescript , but that's not very mature. More work might be done on this in the future, but I can't promise anything.

tarruda commented 10 years ago

I have taken a quick look at the implementation. It seems @mntmn reimplemented source maps for coffeescript because it wasnt available at the time tern was released. Now it should be more trivial since the coffeescript compiler natively supports v3 source maps. I'm going to give it a shot using the current version of the coffeescript compiler.

I was thinking of adding some server hooks that would maintain maps of coffeescript filenames/source maps that get used transparently when queries are made with the coffeescript plugin loaded. @marijnh, is something like this currently possible? If so, can you provide a simple example?

If such extension is not currently possible then it might be worth adding it, since there quite a few compile-to-js tools out there(coffeescript, typescript, traceur...) that could make use of it.

marijnh commented 10 years ago

A rough form of CoffeeScript support will be added soon. It will not have error-tolerant parsing until someone puts in the work of implementing such a parser for CoffeeScript.

tarruda commented 10 years ago

@marijnh that is nice to know. I also tought a bit about the error-tolerant parsing issue and a few possible hacks to partially work around it. What do you think of this:

1- Try to parse the current file 2- If the error ocurrs after the line being completed, try to parse only up to the line before the completion point(since coffeescript uses indentation as block delimiter this might work) 3- If the error occurs before the line being completed, replace the line where the error happened with an empty line and try again. 4- If everything failed, use the result of the previous compilation

A big problem with this approach is that it will be very expensive for editors that use plugins like vim's youcompleteme which queries for completions without user the user explicitily asking for it, but might be worth a shot anyway.

othree commented 10 years ago

HI

I have try to complete this. My first principle is not to hack tern.js. So I use plugin and add a new command 'coffee'. And update tern_for_vim to use the new command.

I use mntmn's approach to do the job. The new 'coffee' command is a pre parser. It will rename the file.name and convert file.text from coffeescript to javascript. Calculate the end position. Then send to server to do a real request.

And since coffeescript compiler is not error tolerance. I do a little hack try to make coffeescript can be compile. ex: obj. will become obj.__fake__, then the __fake__ part will be removed before send to the server.

This approach have some issues can't fix.

First, It's not possible to deal with required file. Other plugin like requirejs and node will not call the new 'coffee' command. If tern.js can allow plugin to hijack any request before it do anything at request method. This issue should be possible to fix. And I don't need to add new command. Will much easier to integrate with other editor.

Second is about file name extension. And for now, requirejs and node all think file extension is 'js'. It means coffeescript will not be loaded by this two plugin. So I think it should have a list by order. tern.js should check one by one in getFile.

The last problem is the command run function. Because its sync function. I can't real use my current approach on some condition. ex: If getFile is async mode, my solution will fail.

But if the first 2 problem can be solve. Then the last one is not a problem anymore. The first one is easy. But the second one is not that easy. So I think I should see if you have any idea before did any hack.

My workable version is here:

I install tern in my tern_for_vim by clone it directly. Don't forget to npm install in tern.

marijnh commented 10 years ago

Hi @othree , could you create a branch with only these changes, in a few structured commits, to make it easier for me to look at them?

othree commented 10 years ago

Hi @marijnh , I have another post in tern-dev group about this. My current implementation solves problems I mentioned above. But I didn't fine tune the code. I spend lots of time to make ternjs works on Backbone projects in recent days. So I will explain what I did here instead. (I am willing to send a pull request with clean commit. But I want to fine tune it first.)

I overwrite getFile method to find possible coffee files. If a coffee script is found. It will compile it and send back. If not find any coffee script file. It will look for js file.

I also overwrite request to remember the mapping information. And the mapping information comes from @mntmn's code.

The last part I did is to modify coffee script to make it possible to compile. But this process is only on part file request. I did 2 modification:

cooolbasha commented 10 years ago

is there any update on this...

joaoafrmartins commented 10 years ago

+1

marijnh commented 10 years ago

The original project (where I claimed that support would be added soon) fell through. I still haven't seen a serious implementation of this.

joaoafrmartins commented 10 years ago

this is rather an extensive project... i tried the plugin on sublime with @marijnh implementation and although it works its not really what one would call quality code completion... what would be the requirements for such an implementation?

PEM-- commented 10 years ago

+1

joaoafrmartins commented 10 years ago

what would be teh requirements for full coffeescript integration with tern? a recursive descent parser simillar to acorn?

romanzolotarev commented 9 years ago

+1

calebl commented 9 years ago

+1

dcsan commented 9 years ago

+1

marijnh commented 9 years ago

Stop adding '+1' posts here. If you want to be notified of further activity, subscribe to this issue. If you want something to actually happen, organize for someone to pay me to work on this.

fpaboim commented 9 years ago

You could put some gittips on the project(now apparently gratipay - you can imagine searching for git tips...), or on a per request basis if possible, I would give a few bucks for coffeescript support. Great job with all your other projects and writings btw, you always seem to popup in javascript land ;)

jeffling commented 9 years ago

@marijnh how have people generally organized to pay you for a feature? Do you have some sort of bounty system you prefer, since there are several out there?

marijnh commented 9 years ago

I've set up crowd-funding campaigns before, but there haven't been any user-organized funding drives. Bountysource looks like a decent platform for this, but I have no strong preference.

katspaugh commented 9 years ago

I started refactoring @othree's tern-coffee plugin: https://github.com/katspaugh/tern-coffee The main difference is it's using Mozilla's source-map module. The fork is unfinished and I would rather help fund someone else to solve this issue.

@marijnh, can we reopen this issue to start crowdfunding it on Bountysource (https://www.bountysource.com/issues/1607447-coffeescript)?

marijnh commented 9 years ago

I am currently super busy with other things. Once I have time for Tern, ES6 support is first, but after that, I can revisit compile-to-JS language support. Not sure why I closed this -- reopening.

katspaugh commented 9 years ago

Great, thanks!

I've posted a small bounty, guys please join!

davibe commented 9 years ago

+1

katspaugh commented 9 years ago

Link to crowd-funding of this issue:

https://www.bountysource.com/issues/1607447-coffeescript

danihodovic commented 9 years ago

@marijnh how much funding would you need for CS support?

zeekay commented 8 years ago

+1

arichiardi commented 7 years ago

On the same note, I was looking at tern for ClojureScript completion as we seem not to have a good completion story for it at the moment, especially for JavaScript objects.