From f8cf6090f4f9b48f2c970b8d3a037c9beb9413a3 Mon Sep 17 00:00:00 2001 From: z80 Date: Thu, 8 Aug 2024 21:07:49 -0400 Subject: [PATCH] fix: fallback to scanning through doc in sig line numbers may change during editing, and often a signature lookup happens on a new line, so the line number no longer lines up with the right definition. when this happens, we fall back to scanning through the doc. if this becomes a performance hotspot it may be worth optimizing where we start scanning from, and wrap-around --- vyper_lsp/analyzer/AstAnalyzer.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vyper_lsp/analyzer/AstAnalyzer.py b/vyper_lsp/analyzer/AstAnalyzer.py index acad648..1a06a30 100644 --- a/vyper_lsp/analyzer/AstAnalyzer.py +++ b/vyper_lsp/analyzer/AstAnalyzer.py @@ -71,10 +71,13 @@ def signature_help( expression = get_expression_at_cursor( current_line, params.position.character - 1 ) + # TODO: Implement checking external functions, module functions, and interfaces fn_name = get_internal_fn_name_at_cursor( current_line, params.position.character - 1 ) + # this returns for all external functions + # TODO: Implement checking interfaces if not expression.startswith("self."): return None @@ -85,6 +88,15 @@ def signature_help( fn_name = node.name parameters = [] line = doc.lines[node.lineno - 1] + + decl_str = f"def {fn_name}(" + search_start_line_no = 0 + + while not line.startswith(decl_str): + line = doc.lines[search_start_line_no] + search_start_line_no += 1 + + fn_label = line.removeprefix("def ").removesuffix(":\n") for arg in node.args.args: