ternjs / tern_for_sublime

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

nodeJS autocompletion issues #34

Open mayuroks opened 10 years ago

mayuroks commented 10 years ago

How to add node modules for auto completion with '.' (dot) as auto completion trigger ? Is there a quick way ?

marijnh commented 10 years ago

These seem to be two distinct questions. Node-style module loading is enabled by using the node plugin (specify it in your .tern-project file). Autocompletion on pressing dot is something that I guess ST does by default?

mayuroks commented 10 years ago

Yeah i just need nodeJS auto completion. Some how I feel I need to look into tern docs to be able to configure this. Please tell me how a sample .tern-project for regular nodejs auto completion would look like ... other wise i ll have to explore it out. Other than that this issue is mostly closed

ackalker commented 10 years ago

@mayuroks May I presume that you want Tern to autocomplete for nodejs modules which you've required earlier in your source code? If so, it's the same problem I'm having, using Sublime Text 2,

In a directory scraping, I have a silly toy project for scraping some HTML using cheerio and superagent nodejs module (both installed in the project using npm install. In this directory I have the following files besides the node_modules directory:

.tern-project:

{
  "plugins": {
    "node": {}
  }
}

example.js:

/*jslint node:true*/
"use strict";

var request = require('superagent');
var cheerio = require('cheerio');
var $ = cheerio.load('<html><head></head><body><div id="content"><div id="sidebar"></div><div id="main"><div id="breadcrumbs"></div><table id="data"><tr><th>Name</th><th>Address</th></tr><tr><td class="name">John</td><td class="address">Address of John</td></tr><tr><td class="name">Susan</td><td class="address">Address of Susan</td></tr></table></div></div></body></html>');

$('#data .name').each(function () {
    console.log($(this).text());
});

When editing example.js in ST 2, I can't get it to complete on any attribute of either request, cheerio or $. The same goes for fs = require('fs'); fs. and other node-internal modules. console. completes just fine and shows console.log (fn). When I open the same file in Adobe Brackets (which also uses a Tern plugin for completion), completions work just fine.

ackalker commented 10 years ago

Adding: When I backspace after completiing of console.log, things get really messed up when I retype console. Right now I'm very much inclined to think that the problem is with the ST plugin, not with the configuration of Tern.

mokkabonna commented 10 years ago

I just had a problem with the package AngularJS preventing me from seeing tern completions properly. I had a var path = require('path'); typing path. produced no info. After uninstalling the AngularJS package I got the expected result. Retried with installing it again, same problem.

Try uninstalling all packages, or one by one and check your result.

In my case I had other tern functionality working fine like jump to definition and select variable. But not completions.

Not sure how one package can effectively render another useless, but that's what happened to me.

mayuroks commented 10 years ago

I have .tern-project in my root directory now

{
  "plugins": {
    "node": {}
  }
}

screenshot from 2014-01-29 21 48 07

I installed mongoose and tried to get mongoose.connect()

Two things: 1) My sublime started hanging 2) Still no proper auto completion

marijnh commented 10 years ago

If sublime starts hanging, a likely problem is that, in following the project's dependencies, Tern ends up trying to load more code than it can really handle.

I just set up a simple project where I installed superagent and cheerio, and dropped in your file, and completion on the request and cheerio variables works as expected for me.

ackalker commented 10 years ago

It is working for me too now, I don't know what has changed, maybe there was some interference from other plugins which I had installed. Thanks for your help :-)

elliotboney commented 10 years ago

I am getting crazy empty string errors every character I type in any file I require mongoose as well. It's working great with other node modules.

I suspect that it could be because mongoose is LARGE and tern could just get overloaded, or maybe its the way mongoose exports?

module.exports = require('./lib/');
marijnh commented 10 years ago

That style of exports is supported. The way Tern deals with being fed more than it can handle is still rather bad (it basically just keeps trying, and might eat lots of memory and get very slow).

tdd commented 10 years ago

Hey Marijn,

First, a boatload of thanks for every awesome JS stuff you do: Eloquent JS, CodeMirror, Tern… the list keeps going :smile:

I'm trying to properly set up Tern on my ST2 and face some issues. I teach JS a lot so having it bulletproof would be of immense help.

I have several separate issues. First, autocompletion per se. I configured ST2 to auto-complete on dots in JS source too, and that does trigger. However, most of the results I get are incorrect or plain missing. I also have a .tern-project at my project root which states:

{
  "plugins": {
    "node": {}
  }
}

For instance, in this file if I try to complete async. after the require lines, I only get “waterfall (?)”, which I presume is deduced from such a call later in my file. I don't get any completion on the methods exposed by waterfall, nor their hints.

I do get completion for Node built-in modules the node plugin undoubtedly provides JSON defs for, but even there, I don't get any parameter hints (despite the global tern_argument_hints setting being set to true in my user prefs file; granted, that's another issue than auto-completion).

In short, either I'm missing something, or it falls short most of the time, and shouldn't according to your demo, replies here, etc.

What am I missing here?

Thanks again!

elliotboney commented 10 years ago

I second what Christopher said. I have trouble getting bulletproof completion. A lot of times I'm not sure if I'm doing something wrong or maybe the node module doesn't have what tern needs.

Us beginners could really benefit from some example tern project files and a demo package that is known to work so we can see if it's something on our end.

I'd be happy to put this together and maintain it if I got help setting it up correctly

Elliot Boney Co-Founder


Digital Grove We Grow Business digitalgrove.org

Please excuse typos, sent from my smartphone. On Mar 10, 2014 5:43 AM, "Christophe Porteneuve" notifications@github.com wrote:

Hey Marijn,

First, a boatload of thanks for every awesome JS stuff you do: Eloquent JS, CodeMirror, Tern... the list keeps going [image: :smile:]

I'm trying to properly set up Tern on my ST2 and face some issues. I teach JS a lot so having it bulletproof would be of immense help.

I have several separate issues. First, autocompletion per se. I configured ST2 to auto-complete on dots in JS source too, and that does trigger. However, most of the results I get are incorrect or plain missing. I also have a .tern-project at my project root which states:

{ "plugins": { "node": {} } }

For instance, in this filehttps://github.com/tdd/node-demo/blob/master/app/engine.jsif I try to complete async. after the require lines, I only get "waterfall (?)", which I presume is deduced from such a call later in my file. I don't get any completion on the methods exposed by waterfall, nor their hints.

I do get completion for Node built-in modules the node plugin undoubtedly provides JSON defs for, but even there, I don't get any parameter hints (despite the global tern_argument_hints setting being set to true in my user prefs file; granted, that's another issue than auto-completion).

In short, either I'm missing something, or it falls short most of the time, and shouldn't according to your demo, replies here, etc.

What am I missing here?

Thanks again!

Reply to this email directly or view it on GitHubhttps://github.com/marijnh/tern_for_sublime/issues/34#issuecomment-37173966 .

marijnh commented 10 years ago

@tdd @elliotboney Are you on Windows? There is reportedly some problem with package path resolution in the node plugin on Windows. The example with completing on async works for me (on Linux).

As for bulletproof, that is something that Tern is never going to be, since the task it tackles is messy and poorly defined. It'll always fail in some circumstances, annoying as that is.

elliotboney commented 10 years ago

I'm on osx.

Elliot Boney Co-Founder ----------------------------------- Digital Grove ----------------------------------- s: digitalgrove.org http://go.toutapp.com/6a7e9d75cc3ebd5197 e: elliot@digitalgrove.org m: 512-557-3162 ----------------------------------- We Grow Business.

On Wed, Mar 12, 2014 at 11:45 AM, Marijn Haverbeke <notifications@github.com

wrote:

@tdd https://github.com/tdd @elliotboneyhttps://github.com/elliotboneyAre you on Windows? There is reportedly some problem with package path resolution in the node plugin on Windows. The example with completing on async works for me (on Linux).

As for bulletproof, that is something that Tern is never going to be, since the task it tackles is messy and poorly defined. It'll always fail in some circumstances, annoying as that is.

Reply to this email directly or view it on GitHubhttps://github.com/marijnh/tern_for_sublime/issues/34#issuecomment-37432250 .

tdd commented 10 years ago

So am I, OSX. Mavericks and ST2, specifically.

Christophe Porteneuve tdd@tddsworld.com

elliotboney commented 10 years ago

Mavericks and ST3

Elliot Boney Co-Founder ----------------------------------- Digital Grove ----------------------------------- s: digitalgrove.org http://go.toutapp.com/6a7e9d75cc3ebd5197 e: elliot@digitalgrove.org m: 512-557-3162 ----------------------------------- We Grow Business.

On Wed, Mar 12, 2014 at 12:52 PM, Christophe Porteneuve < notifications@github.com> wrote:

So am I, OSX. Mavericks and ST2, specifically.

Christophe Porteneuve tdd@tddsworld.com

Reply to this email directly or view it on GitHubhttps://github.com/marijnh/tern_for_sublime/issues/34#issuecomment-37441015 .

marijnh commented 10 years ago

Well, I dusted off my Mac (which is stuck on Lion, due to being ancient), installed ST3, and then put the engine.js file @tdd linked along with the minimal node-enabled .tern-project file in a directory. Next, I npm-installed underscore, async, and promise in this directory. When I go into engine.js and type something like async.f, I get accurate completions for the async library.

But then, if I also install events, all imports below that one seem to be messed up. Could it be that this is the problem you are seeing?

I'll see if I can find something about the code in the events lib that is throwing Tern for a loop.

marijnh commented 10 years ago

Actually, that was a fluke. Completion seems to work properly for me on OS X.

A complete example of a project, including a list of npm-installed libraries, and where these are installed, is still welcome.

tdd commented 10 years ago

Hey Marijn,

Thanks for looking into this.

The complete project is actually on GitHub:

https://github.com/tdd/node-demo

Also, I'm on Mavericks but on ST2 (still prefer it to ST3, I guess), so that might impact some of my results?

The .tern-project I use is just as follows:

{
   "plugins": {
     "node": {}
   }
}

Thanks!

marijnh commented 10 years ago

I can only say that this works for me with ST2 on Linux (I clone the project, npm install, and open app/engine.js in ST2. completing on async. works fine).

d0b1010r commented 10 years ago

The example @tdd gave works for me on Mavericks/ST2.

tdd commented 10 years ago

Hey there,

Well I'm on Mavericks/ST2 now, using nvm. I put my tern_command setting in my user prefs:

    "tern_command": [
        "/Users/tdd/.nvm/v0.10.26/bin/node"
    ],

…since then, basically any attempt at completion (including automatic file-local identifier completion ST normally does) basically hangs ST2 on that same project, in that same file.

What am I missing here? It is a fresh clone of this plugin repo, there are no conflicting packages to the best of my knowledge.

Best,

tdd commented 10 years ago

(Also, it used not to work because indeed it couldn't find my node binary).

marijnh commented 10 years ago

Does it hang on any file, or when you are trying to use it in a project that might be pulling in huge dependencies (or simply in a huge file)?

The hangs caused by dependencies should be better in the current master branch (soon to be released as a new release). Hangs on giant files are still a problem. But I've never seen it hang on small files -- that might suggest the python glue code is getting stuck somehow. Do you see a node process when this happens? Is it using ridiculous amounts of cpu and/or memory?

arjunmehta commented 9 years ago

@tdd your "tern_command" property should be pointing to a binary of tern not node!

arjunmehta commented 9 years ago

Also @mayuroks : To make . (dot) code completion work just add "." to the list of characters in your "auto_complete_triggers" in your User/Preferences.sublime-settings file:

"auto_complete_triggers": [{"characters": "."}],