Autocomplete tutorial


#1

Hi,

I tried out autocomplete and autocomplete plus package.
May be it is a user error:), but I can’t find how to make autocomplete node.js javascript libraries.

Here is a small node.js snippet, what I would like to achieve:

var fs = require("fs");
fs.readF[TAB]

expected autocompletes:
readFile, readFileSync

Also is there a package which could provide help for an appropriate function?
(eg. fs.readFile, would show the official documentation,
or the local help file: /usr/share/doc/nodejs/api/fs.html,
or the source file if available.)

Any help is much appreciated.


#2

The autocomplete-plus package does not provide intelligent suggestions. As far as I know it only scans the current file and selects suggestions based on those words.

There are packages that provide suggestions for autocomplete-plus like snippets or paths, but I don’t know of any package that does smart javascript auto completion.


#3

I don’t think any of the autocomplete packages for atom provide intelligent (or even marginally good) autocompletion. I started an issue on github here, recommending that the atom devs swipe the excellent autocompletion engine from Brackets.


#4

recommending that the atom devs swipe the excellent autocompletion engine from Brackets.

the excellent autocompletin engine behind brackets is not develop by bracket itself, they are using ternjs, you can get it (for javascript only) using a package named ternjs or tern…both works in similar way…

brackets provide a more transparent way because it just only works, instead with atom (or vim or sublime) you need create a configuration file for tern indicating in which folder are you saving your libs or if you’re using node (actually the tern plugin creates it but it’s not smart for include nodejs), would be cool than this could be more automatic and without user intervention…


#5

maybe you can suggest an improvement in the tern package or the autocomplete package here Must Have Packages That Don't Exist? …the tern package is far from complete.


#6

The development of both Tern and Ternjs package are stalled.

Also I don’t really get any meaningful suggestions.
It suggests only the same function which was already written in the edited file.

For now I installed nesh, and it works like this:

$ nesh
>.require fs
>fs.readFi[TAB]

Then hit Ctrl-Q twice, and I get the function source.


#7

when I start the tern server it gives me good suggestion, actually is pretty similar to the suggestion from chrome developer tools or brackets…check than you are running the server and than tern

nesh seems pretty interesting, but how you use it inside atom??..seems to be more like a repl, maybe a repl with steroids, but would be interesting integrate it inside atom.


#8

andML: I started the Tern server via Ctrl-Shift-P.
But how to check it? (I’m on linux) Is the server included in the Tern(js) package itself, or should I install it separately?

nesh: I use it from command line (which I launch it with Ctrl-Shift-T). I prototype what I want, later I integrate it inside atom.


#9

Is the server included in the Tern(js)

yes…you can check if it is running opening the devloper tools (cmd+shift+I)…this must show the tern port…

the key part is create the tern file, I don’t know if it’s automatically generate by atom but personally I prefer create it in my root folder and use the node plugin (this enable the autocomplete for browserify packages too)

.tern-project file

{
   "plugins" : {
        "node" : {"load":true}
    }

}

#10

I take a screenshot of terns, you can notice than my file is empty,so it’s not completing based in used words…and actually the suggestions are only th methods inside the kefir package…


#11

Thank you for your response.

I got hit by this bug: https://github.com/artoale/atom-tern/issues/13

Once I saved my document, closed atom, started it. Then started Tern package (checked in the console in developer tools). Hit some function, then correct autocomplete appeared.

After that despite uninstalling-reinstalling the Tern package, this bug never showed up again.

So now, I have autocompletion to function names. Still no “Go to definition” or doc text.
I’m looking for something like this:
http://nodejs.org/api/fs.html#fs_fs_readfile_filename_options_callback