atom-ide-javascript icon indicating copy to clipboard operation
atom-ide-javascript copied to clipboard

Require options

Open Ismael-Oliv opened this issue 5 years ago • 18 comments

When I try to import using javascript like this way "const fs = require('fs') and typescript with "import", it doesn't show all the "require" options that it used to do. I'm using the 1.2.0 atom-ide-javascript version

video.zip

Ismael-Oliv avatar Jul 25 '20 17:07 Ismael-Oliv

Does it show any other autocomplete? Something like:

["1"].conc

should suggest concat.

aminya avatar Jul 25 '20 17:07 aminya

yeah, It does

Captura de tela de 2020-07-25 14-18-37

Ismael-Oliv avatar Jul 25 '20 17:07 Ismael-Oliv

@lierdakil Any idea about this? Has anything changed from the TypeScript side?

aminya avatar Jul 25 '20 17:07 aminya

@Ismael-Oliv Please try with v1.2.1 and see if this fixes it.

aminya avatar Jul 25 '20 17:07 aminya

Not yet, but it worked when I installed the express types' => @types/express.

Captura de tela de 2020-07-25 14-58-47

And I think it's because of autocomplete-paths package , its showing so many stuffs .

Captura de tela de 2020-07-25 15-04-01

Ismael-Oliv avatar Jul 25 '20 18:07 Ismael-Oliv

If you type

const fs = require('f

doesn't it offer 'fs'?

It offers all the installed dependencies and Node libraries to me: image

If you want a specific library you should install it inside package.json, otherwise, it will only show the Node libraries.

aminya avatar Jul 25 '20 18:07 aminya

yeah, But it just shows the "require" options because I had installed the express types of typescript

Captura de tela de 2020-07-25 15-11-13

When I try to import anything without installing any library, it's not showing ...

Captura de tela de 2020-07-25 15-18-48

But I'm gonna remove atom and Install again with all packages. to see if it work

Ismael-Oliv avatar Jul 25 '20 18:07 Ismael-Oliv

OK. Now I understand the problem better. When you do not have any library installed, it does not show it. Although I cannot reproduce it, I will take a closer look. image

I do not think reinstalling Atom helps much. If you install atom-ide-javascript only, it will install all the deps automatically.

aminya avatar Jul 25 '20 18:07 aminya

I can confirm that sometimes the autocomplete is not fast/intelligent enough here. It might be because of the TypeScript server. @lierdakil and I will take a look into this.

image

aminya avatar Jul 25 '20 18:07 aminya

I installed it again and it's not working yet

Captura de tela de 2020-07-25 15-56-38

if is there something that I can do to help you, just tell me.

Ismael-Oliv avatar Jul 25 '20 18:07 Ismael-Oliv

Try installing @types/node for now, which you should always do when writing Node programs, until we see if we can reproduce this.

aminya avatar Jul 25 '20 19:07 aminya

Alright, no problem. :+1:

Ismael-Oliv avatar Jul 25 '20 19:07 Ismael-Oliv

I think I should add an option for automatic Nodejs completions. Maybe it works on my system out of the box because I have @types/node installed globally.

aminya avatar Jul 25 '20 19:07 aminya

Alright, I'm gonna try it ...

Ismael-Oliv avatar Jul 25 '20 19:07 Ismael-Oliv

Without @types/* packages in scope, TypeScript server should generally recognize require, but only offers sub-directories of node_modules as "bare" import suggestions. If you add ./ to the argument, it switches to local files instead. Generally a good idea to add relevant @types to devDependencies in any case, although I appreciate it can be a bit of a hassle. Also, unless require is defined somewhere in the ambient declaration, tsserver doesn't assume require is even defined, so it doesn't offer it as a suggestion.

There is a caveat however, TypeScript will sometimes cache type definitions in $HOME/.cache/typescript and might use those even if there aren't any installed in the current project. There is very little information on when exactly this happens however, so I couldn't tell you how that works if my life depended on it.

Including/enabling Node definitions by default isn't the greatest idea, because some of us write code for the browser (shocking, I know), and we don't really want to see Node-specific suggestions that won't work.

lierdakil avatar Jul 26 '20 05:07 lierdakil

I have a suggestion. We can add a command and a Tool-bar button to add Nodejs support by using that. People who need Node should click or run that command first, or should install the @types

aminya avatar Jul 26 '20 05:07 aminya

Typing npm i --save-dev --only=dev @types/node once per project isn't that much of a chore I reckon, so I don't see much value in inventing new ways to add some definitions (which aren't even necessarily correct, because who knows what node version does the user intend to use) only for the sake of saving a couple keystrokes.

The "hassle" I was talking about above is tracking down and installing definitions for all the dependencies -- that is a bit of a chore.

lierdakil avatar Jul 26 '20 06:07 lierdakil

I am planning to add a npm IDE which adds GUI and clickable buttons for running various operations. I think we can address installing the types in that package!

aminya avatar Jul 26 '20 06:07 aminya