-
Notifications
You must be signed in to change notification settings - Fork 219
Report autoimport progress #305
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
12b2010
feat: autoimport-progress
bagel897 7eb3092
Update task handle
bagel897 f070678
Refactor and improve
bagel897 4133168
backwards compatible fstrings
bagel897 1898683
default job_name
bagel897 a4b9858
format: reformat
bagel897 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 hidden or 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,102 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from typing import Callable, ContextManager, List, Optional, Sequence | ||
|
||
from rope.base.taskhandle import BaseJobSet, BaseTaskHandle | ||
|
||
from pylsp.workspace import Workspace | ||
|
||
log = logging.getLogger(__name__) | ||
Report = Callable[[str, int], None] | ||
|
||
|
||
class PylspJobSet(BaseJobSet): | ||
count: int = 0 | ||
done: int = 0 | ||
_reporter: Report | ||
_report_iter: ContextManager | ||
job_name: str = "" | ||
|
||
def __init__(self, count: Optional[int], report_iter: ContextManager): | ||
if count is not None: | ||
self.count = count | ||
self._reporter = report_iter.__enter__() | ||
self._report_iter = report_iter | ||
|
||
def started_job(self, name: Optional[str]) -> None: | ||
if name: | ||
self.job_name = name | ||
|
||
def finished_job(self) -> None: | ||
self.done += 1 | ||
if self.get_percent_done() is not None and int(self.get_percent_done()) >= 100: | ||
if self._report_iter is None: | ||
return | ||
self._report_iter.__exit__(None, None, None) | ||
self._report_iter = None | ||
else: | ||
self._report() | ||
|
||
def check_status(self) -> None: | ||
pass | ||
|
||
def get_percent_done(self) -> Optional[float]: | ||
if self.count == 0: | ||
return 0 | ||
return (self.done / self.count) * 100 | ||
|
||
def increment(self) -> None: | ||
""" | ||
Increment the number of tasks to complete. | ||
|
||
This is used if the number is not known ahead of time. | ||
""" | ||
self.count += 1 | ||
self._report() | ||
|
||
def _report(self): | ||
percent = int(self.get_percent_done()) | ||
message = f"{self.job_name} {self.done}/{self.count}" | ||
log.debug(f"Reporting {message} {percent}%") | ||
self._reporter(message, percent) | ||
|
||
|
||
class PylspTaskHandle(BaseTaskHandle): | ||
name: str | ||
observers: List | ||
job_sets: List[PylspJobSet] | ||
stopped: bool | ||
workspace: Workspace | ||
_report: Callable[[str, str], None] | ||
|
||
def __init__(self, workspace: Workspace): | ||
self.workspace = workspace | ||
self.job_sets = [] | ||
self.observers = [] | ||
|
||
def create_jobset(self, name="JobSet", count: Optional[int] = None): | ||
report_iter = self.workspace.report_progress(name, None, None) | ||
result = PylspJobSet(count, report_iter) | ||
self.job_sets.append(result) | ||
self._inform_observers() | ||
return result | ||
|
||
def stop(self) -> None: | ||
pass | ||
|
||
def current_jobset(self) -> Optional[BaseJobSet]: | ||
pass | ||
|
||
def add_observer(self) -> None: | ||
pass | ||
|
||
def is_stopped(self) -> bool: | ||
pass | ||
|
||
def get_jobsets(self) -> Sequence[BaseJobSet]: | ||
pass | ||
|
||
def _inform_observers(self) -> None: | ||
for observer in self.observers: | ||
observer() |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.