Smart autocompletion

#1

The Atom’s main page states “Atom helps you write code faster with a smart and flexible autocomplete.”, however I think that is not applicable utterly.

Example:

I installed validator package

npm i validator

Then I imported in my app.js file and tried to get isEmail as a suggestion.

const validator = require('validator');
console.log(validator.isEmail('foo@bar.com')

However it never autocompleted that function.

Is that a bug? or am I not getting this correctly?

0 Likes

#2

You’re not getting it correctly.

Atom is a general purpose text editor. It intentionally keeps language specific features to a minimum, only providing snippets and syntax highlighting for ~30 languages. I.e., it does not, and has never claimed to, understand JS out the box. I believe your quote is referring to the inbuilt autocomplete provider, which pulls words from open files in a language-agnostic way, and checks things like closeness to existing prefix and proximity to cursor to present the most likely thing you’re going to type. Of course, this requires it already being in an open file somewhere.

To get language specific autocompletion, you will need community packages. Your best be is the ide-typescript package, which supports JS to some degree. I don’t know if it completes JS though, as I’ve only really used it for TypeScript.

However, autocomplete for JS in general is impossible, given the lack of types. E.g.,

let foo = {a: 5}

if (Date.now() % 2 == 0) {
  foo = {b: false}
}

foo. // what completes here?

This was a contrived example, but shows why you shouldn’t expect to find an autocomplete service that works 100% correctly. This hasn’t stopped people trying, but if you really want static analysis features like that you’ll have more luck with TypeScript.

2 Likes

#3

I haven’t used Visual Studio Code yet but I have been some videos where it autocompletes NodeJS functions and I thought it would be the same for Atom.

0 Likes

#4

It might; I didn’t say that kind of autocompletion doesn’t exist. E.g., Python has a similar issue but people still made Jedi. I meant that it’s very limited compared to languages with types.

Interestingly, Atom used to be able to do the JS Node modules autocomplete through the ide-typescript package. But it recently switched to a different backend server, which seems incapable of this (VS Code uses the previous one I believe). You can use this previous server if you download a repo clone from before the switch, but that’s not exactly friendly and precludes future updates.

I still maintain TypeScript is the better choice if you value static analysis tools, but I’d recommend VS Code if you want JS autocomplete.

0 Likes