Skip to content

Commit

Permalink
This one is for Murmel. Merry Xmas
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrabel committed Dec 22, 2023
1 parent 316ac23 commit 2f503ef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
18 changes: 18 additions & 0 deletions pylsp/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import docstring_to_markdown
import jedi
import time
from functools import wraps

JEDI_VERSION = jedi.__version__

Expand Down Expand Up @@ -55,6 +57,22 @@ def run():
return wrapper


def throttle(seconds=1):
"""Throttles calls to a function evey `seconds` seconds."""
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs): # pylint: disable=inconsistent-return-statements
if not hasattr(wrapper, "last_call"):
wrapper.last_call = 0
if time.time() - wrapper.last_call >= seconds:
wrapper.last_call = time.time()
return func(*args, **kwargs)

return wrapper

return decorator


def find_parents(root, path, names):
"""Find files matching the given names relative to the given path.
Expand Down
18 changes: 1 addition & 17 deletions pylsp/plugins/_rope_task_handle.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
from __future__ import annotations

import logging
import time
from functools import wraps

from typing import Callable, ContextManager, List, Optional, Sequence

from rope.base.taskhandle import BaseJobSet, BaseTaskHandle

from pylsp.workspace import Workspace
from pylsp._utils import throttle

log = logging.getLogger(__name__)
Report = Callable[[str, int], None]


def throttle(seconds=1):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs): # pylint: disable=inconsistent-return-statements
if not hasattr(wrapper, "last_call"):
wrapper.last_call = 0
if time.time() - wrapper.last_call >= seconds:
wrapper.last_call = time.time()
return func(*args, **kwargs)

return wrapper

return decorator


class PylspJobSet(BaseJobSet):
count: int = 0
done: int = 0
Expand Down
2 changes: 1 addition & 1 deletion pylsp/plugins/rope_autoimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _reload_cache(
autoimport.generate_modules_cache(task_handle=task_handle)

def is_blocked(self):
return cache.thread and cache.thread.is_alive()
return self.thread and self.thread.is_alive()


@hookimpl
Expand Down

0 comments on commit 2f503ef

Please sign in to comment.