This repository has been archived by the owner on Apr 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
Better progress reporting #96
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/LanguageServer/Impl/Implementation/AnalysisProgressReporter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Python Tools for Visual Studio | ||
// Copyright(c) Microsoft Corporation | ||
// All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the License); you may not use | ||
// this file except in compliance with the License. You may obtain a copy of the | ||
// License at http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS | ||
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY | ||
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
// MERCHANTABLITY OR NON-INFRINGEMENT. | ||
// | ||
// See the Apache Version 2.0 License for specific language governing | ||
// permissions and limitations under the License. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.PythonTools.Analysis.Infrastructure; | ||
|
||
namespace Microsoft.Python.LanguageServer.Implementation { | ||
sealed class AnalysisProgressReporter : IDisposable { | ||
private readonly DisposableBag _disposables = new DisposableBag(nameof(AnalysisProgressReporter)); | ||
private readonly IProgressService _progressService; | ||
private readonly ILogger _logger; | ||
private readonly Server _server; | ||
private readonly object _lock = new object(); | ||
private IProgress _progress; | ||
private Task _queueMonitoringTask; | ||
|
||
public AnalysisProgressReporter(Server server, IProgressService progressService, ILogger logger) { | ||
_progressService = progressService; | ||
_logger = logger; | ||
|
||
_server = server; | ||
_server.OnAnalysisQueued += OnAnalysisQueued; | ||
_server.OnAnalysisComplete += OnAnalysisComplete; | ||
_disposables | ||
.Add(() => _server.OnAnalysisQueued -= OnAnalysisQueued) | ||
.Add(() => _server.OnAnalysisComplete -= OnAnalysisComplete) | ||
.Add(() => _progress?.Dispose()); | ||
} | ||
|
||
public void Dispose() => _disposables.TryDispose(); | ||
|
||
private void OnAnalysisQueued(object sender, AnalysisQueuedEventArgs e) { | ||
lock (_lock) { | ||
UpdateProgressMessage(); | ||
_queueMonitoringTask = _queueMonitoringTask ?? QueueMonitoringTask(); | ||
} | ||
} | ||
private void OnAnalysisComplete(object sender, AnalysisCompleteEventArgs e) { | ||
lock (_lock) { | ||
UpdateProgressMessage(); | ||
} | ||
} | ||
|
||
private void UpdateProgressMessage() { | ||
var count = _server.EstimateRemainingWork(); | ||
if (count > 0) { | ||
_progress = _progress ?? _progressService.BeginProgress(); | ||
_progress.Report(count == 1 | ||
? Resources.AnalysisProgress_SingleItemRemaining | ||
: Resources.AnalysisProgress_MultipleItemsRemaining.FormatInvariant(count)).DoNotWait(); | ||
} else { | ||
EndProgress(); | ||
} | ||
} | ||
|
||
private async Task QueueMonitoringTask() { | ||
try { | ||
await _server.WaitForCompleteAnalysisAsync(); | ||
} finally { | ||
EndProgress(); | ||
} | ||
} | ||
|
||
private void EndProgress() { | ||
lock (_lock) { | ||
_progress?.Dispose(); | ||
_progress = null; | ||
_queueMonitoringTask = null; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If those strings go directly to the client, how do we choose the culture?
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.
It is to be determined.... Unfortunately, LSP does not specify locale, so we'll have to add some custom notification. Which reminds me to file #98
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.
Can't we have those strings on VSC side and provide only numbers?
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.
VSC is not the only client. LSP is public and supported by Eclipse, Vim, Emacs and more. So there is actually a plan to try LS with one of those.
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, but isn't this part of the LS protocol is python specific and we will have to add something to the client-side anyway?
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.
Something like
python/setLocale
. If client doesn't send it, we'll just use English. Also, clients typically expect string in exceptions which they display in UI. We throw with descriptive message when we cannot rename, for example.