-
Notifications
You must be signed in to change notification settings - Fork 676
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
Improve startup performance in VS Code #4634
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ public sealed partial class LanguageServer : IDisposable { | |
private readonly CancellationTokenSource _sessionTokenSource = new CancellationTokenSource(); | ||
private readonly RestTextConverter _textConverter = new RestTextConverter(); | ||
private readonly Dictionary<Uri, Diagnostic[]> _pendingDiagnostic = new Dictionary<Uri, Diagnostic[]>(); | ||
private ManualResetEventSlim _initComplete = new ManualResetEventSlim(false); | ||
private readonly object _lock = new object(); | ||
|
||
private IUIService _ui; | ||
|
@@ -153,6 +154,9 @@ private void OnUnregisterCapability(object sender, UnregisterCapabilityEventArgs | |
#region Workspace | ||
[JsonRpcMethod("workspace/didChangeConfiguration")] | ||
public async Task DidChangeConfiguration(JToken token, CancellationToken cancellationToken) { | ||
// Change configuration comes right after the initialization | ||
WaitForServerInitComplete(cancellationToken); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It yields, we get next request. So we end up receiving requests without having initialization complete. One option to add await CompleteInitialization to sync context and call it before any request. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It called sequentially but I do see the yield. Perhaps our sync context is incorrect. |
||
|
||
var settings = new LanguageServerSettings(); | ||
|
||
var rootSection = token["settings"]; | ||
|
@@ -212,8 +216,9 @@ public Task<object> ExecuteCommand(JToken token) | |
|
||
#region TextDocument | ||
[JsonRpcMethod("textDocument/didOpen")] | ||
public Task DidOpenTextDocument(JToken token) { | ||
public Task DidOpenTextDocument(JToken token, CancellationToken cancellationToken) { | ||
_idleTimeTracker?.NotifyUserActivity(); | ||
WaitForServerInitComplete(cancellationToken); | ||
return _server.DidOpenTextDocument(ToObject<DidOpenTextDocumentParams>(token)); | ||
} | ||
|
||
|
@@ -426,6 +431,11 @@ private void PublishPendingDiagnostics() { | |
} | ||
} | ||
|
||
private void WaitForServerInitComplete(CancellationToken token) { | ||
_server.CompleteInitialization.ContinueWith(t => _initComplete.Set()).DoNotWait(); | ||
_initComplete.Wait(token); | ||
} | ||
|
||
private sealed class IdleTimeTracker : IDisposable { | ||
private readonly int _delay; | ||
private readonly Action _action; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't safe. Awaiter may reach
CompleteInitialization
before it is replaced. I'd rather go withTaskCompetionSource
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although point here is NOT to await on DoInitializeAsync and just let it run. Awaiting blocks VSC startup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, nothing ever called until
initialized
returns. So I don't think the task can be replaced easily.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So do I get it right that you want to wait for initialization to complete on the first request after initialization, rather than during initialization request itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. Those are 'open file' and 'change config' - they come after the init. Actually we need to debug why sync context does not wait for completions - or, rather, the StreamJsonRpc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might need to use alternative implementation (from R/vsc) instead of sync context which actually makes sure requests do complete sequentially. See https://github.com/MikhailArkhipov/PTVS/blob/sync/Python/Product/VSCode/AnalysisVsc/LanguageServerProxy.cs