Skip to content

Commit

Permalink
bugfix: error in parentheses detection
Browse files Browse the repository at this point in the history
  • Loading branch information
z80dev committed Nov 14, 2023
1 parent b34df8c commit bba57e0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <z80@ophy.xyz>"]
license = "MIT"
Expand Down
7 changes: 7 additions & 0 deletions vyper_lsp/navigation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import re
from lsprotocol.types import Position, Range
from typing import List, Optional
Expand All @@ -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
Expand Down Expand Up @@ -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."):
Expand Down
6 changes: 5 additions & 1 deletion vyper_lsp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit bba57e0

Please sign in to comment.