-
Notifications
You must be signed in to change notification settings - Fork 14
Compile ts files with tsserver #109
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
Comments
@nimo23 I have started to implement compileOnSave with tsserver. The "compileOnSaveEmitFile" is available since TypeScript 2.0.5, so if you install typescript.java 1.2.0 wich provides TypeScript 2.0.9 as embed TypeScript, you can play with this feature. Once job https://opensagres.ci.cloudbees.com/job/angular2-eclipse/92/ will be finished you will able to install Angular2 Eclipse 1.2.0-SNAPSHOT with update site https://github.com/angelozerr/angular2-eclipse/wiki/Installation-Update-Site Please note that my work is not finished:
I have enable compileOnSave with tsserver when TypeScript 2.0.5 is consumed. Do you think we need a preferences to use tsc and not tsserver when TypeScript 2.0.5 is installed? |
Hello, thank you!
I think, soon all users will at least have ts version 2.1, so tsserver can be used. There is no need to give user the option to use tsc instead of tsserver as TS IDE will include ts version 2.1 soon (it is on the way: https://blogs.msdn.microsoft.com/typescript/2016/11/08/typescript-2-1-rc-better-inference-async-functions-and-more/). In future, are there any benefits or reasons to use tsc instead of tsserver? If not, then users need no preference to choose between tsc and tsserver. |
The big problem is that I cannot refresh correctly the emitted files. See microsoft/TypeScript#12124, with tsc I can because it returns the emited files. |
I understand. I hope microsoft/TypeScript#12124 will be done. As you said:
Maybe this is related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=507280 ? I dont know, however, would it be a problem to do always (as long as this issue is not resolved) a full refresh of the actual TypeScript Build Path when compiling is done. "Async compile" -> "Callback/promise" -> "Refresh full build path"? |
I do a refresh, but the problem is that the refresh of js, map file is done BEFORE the emited file is generated. CompileOnSaveEmitFile command is asynch, so it generates the js, map files but don't wait for that thoses files are finished to generate. I think I will keep this problem for the moment. |
I dont know about CompileOnSaveEmitFile command. Normally, async methodes should have callbacks/promises so you can hook into it when command is done. So when async method is done, "callback for refresh" is called AFTER the emited file is generated. However, I dont know if this method supports that. |
i guess we could just depend on General->Workspace->refresh using native hooks or polling to let eclipse auto refresh the generated js files? |
I don't know how it works. Is this feature is able to track a file creation which is not created with Eclipse? |
yes, you can quickly see it working for you self open up in the navigator a project and look at a certain folder or the root of that project, go with the file explorer of windows and do new ->create text file So i guess for now for people really wanting to have the latest js files directly updated they can enable that. But i don't know how that works for other OS's. Because i think its really a native thing (maybe for other besides windows they do pure polling) in eclipse i think its this native pluging: org.eclipse.core.resources.win32.x86_64_3.5.0.v20140124-1940.jar that does that job |
this scenario works well when using eclipse "refresh using native hooks", however, it does NOT work when file is created by terminal or the like. For example, when using angular cli, files are created by terminal commands and eclipse "refresh using native hooks" does not work anymore. I reported this issue in https://bugs.eclipse.org/bugs/show_bug.cgi?id=507280. You can easily see that, when using eclipse built-in-terminal and do something like "touch test.ts" within your project root. Unfortunatly, Eclipse does not refresh and show this newly created file even when "refresh using native hooks" is enabled. |
i guess the mac (thats where you test against?) doesn't have that native code? But then i think it should fall back into polling echo $null >test.txt it popups right away. |
the thing is that in the end it would be nice that we wouldn't depend on refresh stuff like this. I had for exampe big problems with that setting, because i have a project that is a maven java and typescript project within eclipse so it has a maven builder, the java builder and the type script builder. If then the bin dir of the classes is also the default \target\classes of maven (where also the maven plugin works in) then the auto refresh really screws stuff up. Because the builder is constantly triggered and the maven plugin also works outside of eclipse (and doesn't do a refresh) so the classes that the java builder generates are constantly gone. This is somehow not really a problem when typescript is not added, but that one also changes stuff again and that triggers maven again to build, So i constantly was loosing my compiled classes. If the native refresh was disabled it worked a bit better (because i think now files are not constantly coming in, its more 1 big refresh inside eclipse). |
yes, on mac.
So maybe such cases should be reported on https://bugs.eclipse.org/bugs. |
@nimo23 @jcompagner to fix problem with refresh of emited files, tsserver should support that. See microsoft/TypeScript#12124 Hope TypeScript team will implement this feature. |
@lorenzodallavecchia I have implemented compile on save with tsserver. Please give me feedback and PR if you think you could improve it. Thanks. The pros are:
The cons are:
|
Terrific news @angelozerr! I'm glad you are mentioning file dependencies as one of the pros: in fact I had noted recently that the tsc-based is not capable of recompiling even trivial dependencies within the same project. Too bad about the errors. Provided the time, I will also try to look into that. In the meantime, thanks! |
Ok @angelozerr I have done some testing of the new tsserver-based CoS and now I understand a lot of things better. The following is a list of findings and problems. Language services require at least one open fileThis one somehow shocked me: for tsserver to "know" about a tsconfig.json and all of its files, at least one file must be open (that means, an If all files are closed, tsserver will not respond to any query about the project (not
the file itself is not recompiled! This can cause all sorts of problems in Eclipse: for example when refreshing external changes, doing a Find-Replace, moving/renaming files or checking out from Git. Multiple tsconfig.json supportThe tsserver does support multiple tsconfig.json files. However, both tsconfigs must have at least one file open (because of the above problem). For example, in #128, the scenario with single-poject-multi-config would work perfectly provided that one file is opened from each of the tsconfig scopes. Added/deleted filesWhen a file is removed in Eclipse, no notification is sent to tsserver. The overall supporto for project-level changes seems completely lacking from tsserver: this is probably a result of it being used as backend for tools like VSCode that are still not providing the level of project scope you can see in Eclipse. For example, it is still normal in VSCode to not expect error to be listed for closed files. Unfortunately, for CoS to be realiable, each delta in the Eclipse workspace must be communicated to tsserver. The client cannot risk to have its incremental state misaligned with the server's. Multiple Eclipse projectsThe situation of ts files referencing others in different Eclipse projects is a different story. In this case, tsserver alone cannot solve all issues for the simple fact that typescript.java is opening one tsserver for each Eclipse project. Of course this is inevitable, since the TS version to use is configured ad project level. In this case the only solution is that the Eclipse builder must be made multi-project aware, so that a project can also be informed about the deltas of other projects that it depends on. There are also other issues caused by not knowing in tsserver which paths may contain a future imported file, and so not knowing in advance which projects are needed for building another. This could be fixed by requiring the user to set Project References explicitly. ConsiderationsI think the above problems are mostly caused by tsserver shortcomings, but in my opinion they need to be addressed for the CoS feature to be realied upon. All in all, tsserver seems to lack good support beyond the scope of single open files. This is bad for Eclipse, which is a workspace-based IDE. This may change, of course, as TypeScript implements features like microsoft/TypeScript#3469. |
For emitted file, we must wait for https://github.com/Microsoft/TypeScript/pull/13915/files |
@lorenzodallavecchia many thanks for your great analyse! Could you create a new issue with your analyse please. I would like to close this issue. I would like to use tsserver for compile on save because VSCode will use it and if typescript.java have some trouble with tsserver, VSCode will have too. I would like to avoid developping some extra feature although tsserver should support it. |
No problem. I will split them in two-three issues, mainly to decouple the "multiple project" problem from the others that may affect all users. I agree that compiling with tsserver is the way to go: for the moment I am still using tsc for reliability over performance, but I would be more than happy to switch to tsserver. |
TypeScript 2.1.0 will provide new command to compile TypeScript files which will improve a lot performances (I think).
The text was updated successfully, but these errors were encountered: