Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable Automatic Type Acquisition (ATA) #116

Closed
nimo23 opened this issue Dec 7, 2016 · 18 comments
Closed

enable Automatic Type Acquisition (ATA) #116

nimo23 opened this issue Dec 7, 2016 · 18 comments
Milestone

Comments

@nimo23
Copy link

nimo23 commented Dec 7, 2016

VS Code 1.7.2 has enabled Automatic Type Acquisition (ATA) feature by default (https://code.visualstudio.com/updates). Would be nice to introduce ATA as a option in Typescript Eclipse-Projects as well.

@angelozerr
Copy link
Owner

Yes sure! Could you give me some idea (UI, etc) how it could work?

@nimo23
Copy link
Author

nimo23 commented Dec 7, 2016

Include a option in "Eclipse->Settings->JavaScript->Typescript" to enable/disable ATA.

If enabled, then "typescript.java" can provide IntelliSense for pure js-files by obtaining the coresponding declaration files of the js-files within the project-root with the help of TS Server and npmjs service.

@nimo23
Copy link
Author

nimo23 commented Dec 7, 2016

Maybe another option would be to have a context menu within the project explorer, such as "refresh ATA". With this, Eclipse User can manually trigger IntelliSense for js-files. So TS IDE does not include or ping npmjs service by itself. However, when enabled in settings, TS IDE can also include declaration files as soon as a js-file is included within the ts-project-folder.

For example, user include jquery.js within project root without typescript declaration file, then user triggers "refresh ATA" then TS IDE caches/includes declaration files of jquery to provide intellisense in ts-files. I am not sure about that, but I TS Server has also the ability to provide intellisense for js-files even when no official declaration file of this js-file exists. But I am not sure.

@nimo23
Copy link
Author

nimo23 commented Dec 7, 2016

More information in https://code.visualstudio.com/updates#_better-javascript-intellisense:

A TypeScript language server that has ATA enabled watches your package.json files and automatically installs the typings files of all dependencies in a cache on your file system.

So my suggestion of "refresh ATA" is not senseful, because ts server can handle it automatically by package.json.

@angelozerr
Copy link
Owner

angelozerr commented Dec 7, 2016

@nimo23 could you explain how ATA works with VSCode? I have tried to declare jquery in a package.json

{
    "dependencies": {
        "jquery": "3.1.1"
    }
}

and open a ts file, type jQuery and I though it that VSCode will download jQuery but it seems that it doesn't work like this. Thanks for your help.

@nimo23
Copy link
Author

nimo23 commented Dec 7, 2016

Is "typescript.disableAutomaticTypeAcquisition" set to "false"?

@angelozerr
Copy link
Owner

Here my settings.json

{
    "typescript.tsdk": "./node_modules/typescript/lib",
    "typescript.tsserver.trace": "messages",
    "typescript.disableAutomaticTypeAcquisition": false
}

I'm using VSCode 1.7.2 with TypeScript 2.1.4.

@nimo23
Copy link
Author

nimo23 commented Dec 7, 2016

As said in https://code.visualstudio.com/updates#_better-javascript-intellisense it should work. However, I tested it with a new project and it also does not work. Maybe not ready yet.

@nimo23
Copy link
Author

nimo23 commented Dec 7, 2016

In my editor it works before because I had def files within my old project. However, in new projects, it does not realy work.

@angelozerr
Copy link
Owner

When the download is done? When you open completion?

Anyway it seems (according the VSCode code) that ATA is not very complex to implement it since it is managed with tsserver (very cool!). Once I will understand how ATA works with VSCode, I will try to implement it.

@nimo23
Copy link
Author

nimo23 commented Dec 7, 2016

When the download is done?

good question. I think, yes, then it should fetch def file. I dont know about performance while opening code completion and fetching resource, IDE source editing could hang..not very user friendly.

@angelozerr
Copy link
Owner

good question.

I will study it.

I dont know about performance while opening code completion and fetching resource, IDE source editing could hang..not very user friendly.

Eclipse Oxygen should provide an async completion feature. I must test that.

@angelozerr
Copy link
Owner

See https://discventionstech.wordpress.com/2016/12/06/vs-code-automatic-type-acquisition-gotchas/ I will test that. It seems that it works only with js files and not with ts files. I will try with VSCode. @nimo23 is that, it works only with js files?

@nimo23
Copy link
Author

nimo23 commented Dec 22, 2016

ATA works only for js-files, ts files dont need ATA. When referencing js files in ts files then ts server use ATA for js files..

@angelozerr
Copy link
Owner

Ok thanks @nimo23 for your answer. I will try with VSCode and I will try to do the same thing for Eclipse. The cool thing is that the hard task is managed with tsserver, so perhaps the ATA integration could be easy.

@angelozerr
Copy link
Owner

@nimo23 I have studied ATA with typescript.java and as it uses tsserver, ATA works like a charm (tested with TypeScript 2.1.5). But today you must follow the following rules:

  • don't use embed node.js, but an installed node.js which provides npm too. I will try to fix this problem by adding npm in the embed node.js.

  • declare in your tsconfig.json:

{
	"typeAcquisition": {
		"enable": true
	}
}

And that's all! After that, create a ts file (it works with ts too) like:

import {} from "jquery";

Wait few seconds and try to open (Ctrl+Click) the jquery. It should open the ..AppData\Local\Microsoft\TypeScript\node_modules@types\jquery\index.d.ts file

I must improve the console to display trace of typings when download is done.

@angelozerr
Copy link
Owner

@nimo23 now embed node.js contains the npm #136

So you should just declare in your tsconfig.json:

{
	"typeAcquisition": {
		"enable": true
	}
}

and it should work.

@angelozerr
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants