Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Completion for object litteral #30

Open
angelozerr opened this issue Sep 9, 2014 · 2 comments
Open

Completion for object litteral #30

angelozerr opened this issue Sep 9, 2014 · 2 comments

Comments

@angelozerr
Copy link
Contributor

Even if tern doesn't support completion for object litteral (see issue 311), I create this issue because tern-closure needs that too.

For instance you can write this JS :

var newHeader = goog.dom.createDom('h1', {'style': 'background-color:#EEE'},
    'Hello world!');

It should be very cool if we can have completion like this :

var newHeader = goog.dom.createDom('h1', {'s // here Ctrl+Space shows 'style'

and :

var newHeader = goog.dom.createDom('h1', {'style': 'back // here Ctrl+Space shows background-color
@jgiles
Copy link
Contributor

jgiles commented Sep 11, 2014

Hmm, this could be really tricky. We don't even know what the properties should be for the second argument for createDom (it's typed as (Object|null|string|undefined)), and even if we did we'd have to map that type onto the argument we're passing in (Tern doesn't support that currently), and I'm guessing we would have trouble with the parser here. In this particular instance, you really could pass any keys in for the properties.
I'm also not sure that that this is common enough to be all that helpful even if we did get it working.

@angelozerr
Copy link
Contributor Author

Hmm, this could be really tricky.

I know but in AngularJS Eclipse (https://github.com/angelozerr/angularjs-eclipse) I have more and more issues about this feature. More once this feature will be done, I could validate too the parameters with tern-lint (https://github.com/angelozerr/tern-lint/wiki/Validation-Rules)

So I have started to develop this feature for AngularJS (see ternjs/tern#387)

The basic idea is to hard code the JSON schema of the object (ex : createDom has style property, etc) and attach this schema in the objectType retrieved by the function declared with !effect. In this function we search the object litteral and attach the well JSON schema.

After that I use completion hook to search ObjectExpression and test if the current objectType have JSON schema attached. If I have a JSON schema, I populate the tern completion with missing properties.

We don't even know what the properties should be for the second argument for createDom

Yes I know, We need to do that with !effect function

In this particular instance, you really could pass any keys in for the properties.

Sorry I don't understand?

I'm also not sure that that this is common enough to be all that helpful even if we did get it working.

JS framework uses a lot of object litteral and I find it's very hard to know which properties you can use it.I would like to for instance support this feature too for Google Maps Tern plugin https://github.com/angelozerr/tern.java/wiki/Tern-&-Google-Maps-support

As you are very talented, I would like to find a clean mean to support objet litteral inside tern. Hope you will able to help me. Many thank's!

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

No branches or pull requests

2 participants