ternjs / tern_for_sublime

Sublime Text package adding Tern support
MIT License
803 stars 54 forks source link

Defining Globals for autocomplete #158

Closed nicklee1990 closed 7 years ago

nicklee1990 commented 7 years ago

I have some functions/objects which are available globally in my files but tern currently is unable to autocomplete these. How can I go about adding definitions of these globals?

I thought about trying to add a custom JSON type definition as mentioned in the Tern docs but I couldn't work out where to add it?

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

Cheers

marijnh commented 7 years ago

Can you be more specific? Are these globals defined in your project, and if so, how? Are you using a module loader Tern plugin?

nicklee1990 commented 7 years ago

My specific use case is with Protractor/node. In a project you have conf.js file where you can register global variables in an onPrepare method. These globals will then be available in your test files (for example tests/test.js) automatically, for example if I assign global.foo = bar in my conf.js file, in a test file in my project I can call foo.whatever without defining what foo is. Much the same as when you use built in node globals like process or module. However, when I'm in my test.js file, autocomplete doesn't detect what foo is since it was defined only in conf.js and therefore can't autocomplete the methods it exposes?

In that scenario where foo is an object I'd like to have autocomplete to see the methods available like what happens when for example you include the browser lib and you get autocomplete for document (for example) without having to require anything in a given file in the sublime project

I hope that is slightly clearer? I also thought maybe there would be some way of including a jsdoc statement in every test file as a last resort to assist tern with autocomplete but it doesn't seem to be the case

El 4 ene 2017, a las 21:32, Marijn Haverbeke notifications@github.com<mailto:notifications@github.com> escribi?:

Can you be more specific? Are these globals defined in your project, and if so, how? Are you using a module loader Tern plugin?

- You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/ternjs/tern_for_sublime/issues/158#issuecomment-270492886, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AG-F16XRTNNCyttXnvboiV9ewC3DLFHEks5rPBAFgaJpZM4Lazkj.

marijnh commented 7 years ago

Have you tried listing your conf.js file in the loadEagerly project config option?

nicklee1990 commented 7 years ago

That worked perfectly. thanks a lot!