diff --git a/pyproject.toml b/pyproject.toml index bc36dee..50dd6f4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,6 +34,13 @@ pytest = "^7.4.3" [tool.poetry.scripts] vyper-lsp = 'vyper_lsp.main:main' +[tool.coverage.run] +source = ["vyper_lsp"] +omit = ["vyper_lsp/analyzer/SourceAnalyzer.py", + "vyper_lsp/__init__.py", + "vyper_lsp/__main__.py", + ] + [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" diff --git a/tests/test_debouncer.py b/tests/test_debouncer.py new file mode 100644 index 0000000..3ca1749 --- /dev/null +++ b/tests/test_debouncer.py @@ -0,0 +1,21 @@ +import time +from vyper_lsp.debounce import Debouncer # Import Debouncer from your module + + +def test_debounce(): + result = [] + + def test_function(arg): + result.append(arg) + + debouncer = Debouncer(wait=0.5) + debounced_func = debouncer.debounce(test_function) + + debounced_func("first call") + time.sleep(0.2) # Sleep for less than the debounce period + debounced_func("second call") + time.sleep( + 0.6 + ) # Sleep for more than the debounce period to allow the function to execute + + assert result == ["second call"] diff --git a/tests/test_utils.py b/tests/test_utils.py index fe5cc11..8904b8c 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -24,3 +24,19 @@ def test_get_expression_at_cursor(): assert utils.get_expression_at_cursor(text, 0) == "foo_bar" assert utils.get_expression_at_cursor(text, 4) == "foo_bar" assert utils.get_expression_at_cursor(text, 21) == "self.baz (1,2,3)" + + +def test_get_internal_fn_name_at_cursor(): + text = "self.foo = 123" + assert utils.get_internal_fn_name_at_cursor(text, 0) is None + assert utils.get_internal_fn_name_at_cursor(text, 1) is None + assert utils.get_internal_fn_name_at_cursor(text, 5) is None + assert utils.get_internal_fn_name_at_cursor(text, 12) is None + + text = "foo_bar = self.baz (1,2,3)" + assert utils.get_internal_fn_name_at_cursor(text, 0) is None + assert utils.get_internal_fn_name_at_cursor(text, 4) is None + assert utils.get_internal_fn_name_at_cursor(text, 21) == "baz" + + text = "self.foo(self.bar())" + assert utils.get_internal_fn_name_at_cursor(text, 0) == "foo" diff --git a/vyper_lsp/utils.py b/vyper_lsp/utils.py index 27dff38..4e9551a 100644 --- a/vyper_lsp/utils.py +++ b/vyper_lsp/utils.py @@ -139,9 +139,9 @@ def get_expression_at_cursor(sentence: str, cursor_index: int) -> str: def get_internal_fn_name_at_cursor(sentence: str, cursor_index: int) -> str: # TODO: dont assume the fn call is at the end of the line # REVIEW: make cases like self.foo(self.bar()) work - word = sentence.split("(")[0].split(" ")[-1].strip().split("self.")[-1] - - return word + expression = get_expression_at_cursor(sentence, cursor_index) + if is_internal_fn(expression): + return expression.split(".")[1].split("(")[0].strip() def extract_enum_name(line: str):