Skip to content

Keep projects open on tsserver via OpenExternalProject #160

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

Merged
merged 3 commits into from
Mar 25, 2017

Conversation

lorenzodallavecchia
Copy link
Contributor

This change makes tsserver aware of existing Eclipse projects, so that it does not forget about project state when all files are closed.
Closes #142.

@@ -91,8 +92,8 @@
* @param insertString
* @throws TypeScriptException
*/
void changeFile(String fileName, int line, int offset, int endLine, int endOffset, String insertString)
throws TypeScriptException;
void changeFile(String fileName, int line, int offset, int endLine, int endOffset,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the same Java Format preferences (Eclipse [built-in].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the correct preferences configured, but somehow the format on save did not include some lines. I'm double-checking that now.

String projectName = projectDir.getCanonicalPath();
List<String> rootFiles = new ArrayList<>();
for (String tsconfigFilePath : getTsconfigFilePaths()) {
rootFiles.add(new File(projectDir, tsconfigFilePath).getCanonicalPath());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use FileUtils.getPath(new File(projectDir, tsconfigFilePath)) to normalize path.

List<String> result = new ArrayList<>(tsconfigBuildPaths.length);
for (ITsconfigBuildPath tsconfigBuildPath : tsconfigBuildPaths) {
IFile tsconfigFile = tsconfigBuildPath.getTsconfigFile();
result.add(tsconfigFile.getLocation().makeRelativeTo(tsconfigFile.getProject().getLocation()).toString());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use WorkbenchResourceUtil.getRelativePath(tsconfigFile, tsconfigFile.getProject())

@angelozerr
Copy link
Owner

Wow great PR @lorenzodallavecchia! Thanks! I have added some little comments. Please fix it.

Required requests are use to have some requests waiting for the response
to other requests. This would be required for openExternalProject (see
angelozerr#142).

Also adjusted the code so that:
- async methods return CompletableFuture and never throw,
- sync methods block for the future result and throw in case of error.
The server can now correctly handle files that are not open, including
finding references, etc.
The performance should also be better, since the project is not
recreated on the server each time the "first" file is opened.

Closes angelozerr#142
This is no longer needed because the server does not loose track of
files. Reverts commit babde9c.
@angelozerr angelozerr force-pushed the master branch 2 times, most recently from 302ce8b to d0129a1 Compare March 25, 2017 12:00
@angelozerr angelozerr added this to the 1.2.0 milestone Mar 25, 2017
@angelozerr angelozerr merged commit fc3d75f into angelozerr:master Mar 25, 2017
@angelozerr
Copy link
Owner

Thanks a lot @lorenzodallavecchia ! Very cool PR.

@angelozerr
Copy link
Owner

@lorenzodallavecchia now when I open file, the editor is freezing because of waitForFuture. I would like really avoid freezing editor. Could you fix that please?

@angelozerr
Copy link
Owner

@lorenzodallavecchia I have uncomment the use of waitForFuture to avoid freeze of editor. Don't hesitate to do PR if you find a better solution. I would like to avoid freezing the editor.

angelozerr added a commit that referenced this pull request Mar 25, 2017
angelozerr added a commit that referenced this pull request Mar 25, 2017
@angelozerr
Copy link
Owner

@lorenzodallavecchia I'm really sorry. I have reverted your PR because the editor froze every time. And sometimes it freezees Eclipse IDE (I had to kill it).

I would like to do a release this month, so I would like to have a stable version. I would like to integrate your PR but not for 1.2.0 and study why there are so many freeze. Hope you will understand.

@lorenzodallavecchia
Copy link
Contributor Author

@angelozerr don't worry: I understand.
I am perfectly fine with that feature not landing in 1.2.0, but I hope it will land eventually because the current issues with language services as well as issues #143 and #144 are preventing me from using compile on save, which is far superior to tsc-based build on save.

The freezing problem is really strange I did test opening and closing editors many times and experienced absolutely no freezing. Also, that waiting stuff should not actually change anything compared to now because:

  • if the caller was using CompletableFuture (the most common case), than the caller would just be waiting for a chain of two completion stages instead of one,

  • if the caller was using get on the future to wait for the result, it was already waiting before my change.

So, overall really really strange.
Could you provide some directions to reproduce the freezing problem?

@angelozerr
Copy link
Owner

@lorenzodallavecchia I will try to investigate more but my "main" project that I test is https://github.com/Microsoft/vscode which is big. For instance when I open https://github.com/Microsoft/vscode/blob/master/extensions/javascript/src/features/packageJSONContribution.ts there is a little freeze. After when I navigate quicly (must find what I do exactly), Eclipse IS freeze and I must kill it.

@lorenzodallavecchia
Copy link
Contributor Author

Hi @angelozerr, I finally had time to look into this issue again.

I tried checking out https://github.com/Microsoft/vscode into a single Eclipse project. Then I opened many files (up to 60 at the same time) and navigated back and forth using Ctrl+click and outlines.
Apart from the initial wait (which I think is due to the project being large), I experienced no freezing at all.
I'm really puzzled.

Can you give me other pointers about how to reproduce the issue?

Otherwise I think I would have to remake this PR without the CompletableFuture change: it would be more fragile but still hopefully able to fix #142.

@angelozerr
Copy link
Owner

Hi @lorenzodallavecchia ! Glad to have your news:)

To be honnest with you, I had tested quicly, but I would like really avoid having freezing when user open an editor even if tsserver is not available. Today it works like this. The only freeze that it exists today is when user open completion, hyperlink but for other features (outline, mark occurences, etc), the editor doesn't freeze.

For completion, Oxygen should provide an async completion (hope it will resolve the freeze problem). For Hyperlink, hope Eclipse guys will fix that.

I will b every glad to have a PR, but please avoid having freeze even the first time when editor is opened. Hope you will understand my wish.

I'm very busy with other topics like autoimport with completion, integrates angular language service (inside HTML) and CodeLens, so it's difficult for me to help you with your issue. Any PR are welcome!

@lorenzodallavecchia
Copy link
Contributor Author

Thanks for helping out @angelozerr.

I completely agree with the design principle of postponing waits as much as possible.
Since I was trying with smaller projects, the "first-time" wait was not present. Now that I see that, I'm am convinced too that chaining a wait before file opening is not a wise thing to do.

I think I will investigate inside tsserver to be sure that even if openExternalProject finishes after openFile, the server state remains consistent.

@angelozerr
Copy link
Owner

angelozerr commented May 23, 2017

@lorenzodallavecchia I think you should study too the VSCode TypeScript client. For instance https://github.com/Microsoft/vscode/blob/master/extensions/typescript/src/typescriptServiceClient.ts#L697 which consumes ExternalProjectCompilerOptions

@lorenzodallavecchia
Copy link
Contributor Author

Ok @angelozerr, I finally have a clear understanding of this problem.

First of all, VSCode is not using openExternalProject. That means the server is automatically picking up the tsconfig.json files that are closest to the edited files. Since the VSCode source is made up of many small projects, the language server is fast, since it only has to manage small projects and only a few at once (no more than the number of open files).
The downside is that there is no cross-project error checking in VSCode (exactly what I would like to have in Eclipse).

The fix I proposed in this PR was causing a slowdown when editing VSCode because it caused all TS projects to be loaded when opening just a single file. While this enables cross-project checking, it also wastes a lot of resources.
The situation was acceptable in my tests because I mostly use Eclipse projects containing only one tsconfig.json, so the cost of loading a single file is the same.

I tried removing the wait for Future values, but that only moved the problem to the subsequent tsserver calls. For example, the Outline was taking 15 seconds to appear! Ditto for the content assistant. Of course, that is not acceptable.

Unfortunately, this situation is a limitation of TypeScript and I think we would have to wait for them to implement microsoft/TypeScript#3469. That issue will introduce a way for a tsconfig.json file to reference another and have cross-project checking without impacting performance.

@angelozerr
Copy link
Owner

Many thank's @lorenzodallavecchia for your great feedback!

If I have understood, we must wait for microsoft/TypeScript#3469 to fix this issue.

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

Successfully merging this pull request may close these issues.

Language services require at least one open file
2 participants