Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Integrate tern-threejs in script editor #6654

Merged
merged 1 commit into from
Jun 6, 2015

Conversation

zz85
Copy link
Contributor

@zz85 zz85 commented Jun 6, 2015

Some notes:

  • uses tern-threejs module js
  • uses auto-complete as you type behaviour
  • does not automatically autocomplete single matches
  • uses insensitive autocomplete matching in tern (Related PR)
  • since acorn loose parser is being used, esprima parser could be removed to reduce number of libs..
  • not including tern definitions for browser dom and ecma5 to reduce suggestions for now

screenshot 2015-06-06 12 16 58

screenshot 2015-06-06 12 17 21

ping @mrdoob @tylerwbell

@mrdoob
Copy link
Owner

mrdoob commented Jun 6, 2015

Epic! Many thanks! 😊

mrdoob added a commit that referenced this pull request Jun 6, 2015
Editor: Integrate tern-threejs in script editor
@mrdoob mrdoob merged commit 5ab4a4a into mrdoob:dev Jun 6, 2015
@mrdoob
Copy link
Owner

mrdoob commented Jun 6, 2015

Is there a way to auto-complete this?

screen shot 2015-06-06 at 14 42 47

@zz85
Copy link
Contributor Author

zz85 commented Jun 6, 2015

@mrdoob what would this refer to here? If there're properties that ternjs pick up within the scope, then it should auto-complete. If this refers to some javascript or dom functions then the ecma5 or browser ternjs definitions could be added to auto complete them. (for example, if you use this. at the global scope vs inside Vector function gives different auto-complete results http://zz85.github.io/campjs-livecode/)

@zz85 zz85 deleted the editor-tern-autocomplete branch June 6, 2015 16:16
@zz85 zz85 restored the editor-tern-autocomplete branch June 6, 2015 16:17
@zz85
Copy link
Contributor Author

zz85 commented Jun 6, 2015

hmm... it seems like this refers to the object that script is used on. I think it's possible to tell ternjs what scope this is in, but I need to play around with it's api a little first...

http://ternjs.net/doc/manual.html

@angelozerr
Copy link

@zz85 @mrdoob I think you should create your issue at https://github.com/tylerwbell/tern-threejs

In my case, I follow this project and I could help you if I know how to fix teh issue and if I find time.

@zz85
Copy link
Contributor Author

zz85 commented Jun 8, 2015

@angelozerr thanks for suggesting but I do not think it's an issue with tern-threejs project, because auto-completing this in the script editor has a different use case, since it's code is being evaluated at run time and bind to the object (in app.js)

var functions = ( new Function( 'player, scene, keydown, keyup, mousedown, mouseup, mousemove, touchstart, touchend, touchmove, update', script.source + '\nreturn { keydown: keydown, keyup: keyup, mousedown: mousedown, mouseup: mouseup, mousemove: mousemove, touchstart: touchstart, touchend: touchend, touchmove: touchmove, update: update };' ).bind( object ) )( this, scene );

so I would say it's rather specific here to how three.js script can request ternjs to analyze with a different scope..

@zz85
Copy link
Contributor Author

zz85 commented Jun 8, 2015

I don't have enough brain cycles to be able to wrap my mind around all of ternjs internals right now, but I'm guessing it might be possible to invoke a 'speculative this' in ternjs inference (related issue)

I would be tempted to just use an easier implementation (like using get-hint and javascript-hint to add simple tokens for autocomplete) but if ternjs can be integrated it would give more contextual and accurate autocoplete.

@zz85
Copy link
Contributor Author

zz85 commented Jun 8, 2015

one quick workaround would be to prepend update.prototype = new THREE.Mesh;. then add some hacks to codemirror-ternjs plugin to adjust for line offsets if we are injecting the link invisibly into the editor...

image

@mrdoob
Copy link
Owner

mrdoob commented Jun 8, 2015

I guess prepending this = new THREE.Mesh() doesn't work? 😶

@angelozerr
Copy link

IMHO, I think the best mean to manage this case is to do like node.js tern plugin by creating a scope for each script. See https://github.com/marijnh/tern/blob/master/plugin/node.js#L31

When scope is created you could register this and update function by injecting the well event instance. So you will benefit with event compeltion too.

@zz85 perhaps you could integrate tern-lint to validate with semantic mean (and not syntax) the script. See https://github.com/angelozerr/tern-lint

@zz85
Copy link
Contributor Author

zz85 commented Jun 17, 2015

@angelozerr that's a cool project! I should try it out sometime.

@mrdoob nope. that would be pretty invalid javascript. if you would really want this to happen, I think I can ask about this in https://groups.google.com/forum/?fromgroups#!forum/tern-dev

@mrdoob
Copy link
Owner

mrdoob commented Dec 22, 2016

Is there any way to automate this tern-threejs stuff? I suspect is pretty outdated at the moment, and we keep fixing it by hand...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants