diff --git a/pyproject.toml b/pyproject.toml index 9f1ef50..ef6ea0b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "vyper-lsp" -version = "0.0.3" +version = "0.0.5" description = "Language server for Vyper, a pythonic smart contract language" authors = ["z80 "] license = "MIT" diff --git a/vyper_lsp/navigation.py b/vyper_lsp/navigation.py index 4d3bb24..f87b5e8 100644 --- a/vyper_lsp/navigation.py +++ b/vyper_lsp/navigation.py @@ -1,3 +1,4 @@ +import logging import re from lsprotocol.types import Position, Range from typing import List, Optional @@ -9,6 +10,8 @@ ENUM_VARIANT_PATTERN = re.compile(r"([a-zA-Z_][a-zA-Z0-9_]*)\.([a-zA-Z_][a-zA-Z0-9_]*)") +logger = logging.getLogger("vyper-lsp") + # this class should abstract away all the AST stuff # and just provide a simple interface for navigation @@ -167,10 +170,14 @@ def find_declaration(self, document: Document, pos: Position) -> Optional[Range] def find_implementation(self, document: Document, pos: Position) -> Optional[Range]: og_line = document.lines[pos.line] + logger.info(f"finding implementation for {og_line}") word = get_word_at_cursor(og_line, pos.character) expression = get_expression_at_cursor(og_line, pos.character) + logger.info(f"word: {word}") + logger.info(f"expression: {expression}") if "(" not in expression: + logger.info("no parens in expression") return None if expression.startswith("self."): diff --git a/vyper_lsp/utils.py b/vyper_lsp/utils.py index 750805e..f0875cf 100644 --- a/vyper_lsp/utils.py +++ b/vyper_lsp/utils.py @@ -78,7 +78,7 @@ def _check_if_cursor_is_within_parenthesis(sentence: str, cursor_index: int) -> while end < len(sentence) and sentence[end] != ")": end += 1 - if start < cursor_index and cursor_index < end: + if start != 0 and start < cursor_index and cursor_index < end: return True return False @@ -89,9 +89,11 @@ def _get_entire_function_call(sentence: str, cursor_index: int) -> str: # Find the start of the word # only skip spaces if we're within the parenthesis + logger.info(sentence[start]) while start > 0 and sentence[start - 1] != "(": start -= 1 + logger.info(sentence[start]) while start > 0 and sentence[start - 1] != " ": start -= 1 @@ -100,11 +102,13 @@ def _get_entire_function_call(sentence: str, cursor_index: int) -> str: end += 1 fn_call = sentence[start:end] + logger.info(fn_call) return fn_call def get_expression_at_cursor(sentence: str, cursor_index: int) -> str: if _check_if_cursor_is_within_parenthesis(sentence, cursor_index): + logger.info("cursor is within parenthesis") return _get_entire_function_call(sentence, cursor_index) # does the same thing as get_word_at_cursor but includes . and [ and ] in the expression