diff --git a/vyper_lsp/analyzer/AstAnalyzer.py b/vyper_lsp/analyzer/AstAnalyzer.py index 91799a3..8d38421 100644 --- a/vyper_lsp/analyzer/AstAnalyzer.py +++ b/vyper_lsp/analyzer/AstAnalyzer.py @@ -1,4 +1,5 @@ import logging +from pathlib import Path import re from typing import List, Optional import warnings @@ -14,6 +15,7 @@ ) from pygls.workspace import Document from vyper.compiler import CompilerData +from vyper.compiler.input_bundle import FilesystemInputBundle from vyper.exceptions import VyperException from vyper.ast import nodes from vyper_lsp.analyzer.BaseAnalyzer import Analyzer @@ -278,7 +280,12 @@ def get_diagnostics(self, doc: Document) -> List[Diagnostic]: warnings.simplefilter("always") with warnings.catch_warnings(record=True) as w: try: - compiler_data = CompilerData(doc.source) + uri = doc.uri + # uri withouth file:// + uri_processed = uri.replace("file://", "") + uri_path = Path(uri_processed) + uri_parent_path = uri_path.parent + compiler_data = CompilerData(doc.source, input_bundle=FilesystemInputBundle([uri_parent_path])) compiler_data.annotated_vyper_module except VyperException as e: # make message string include class name diff --git a/vyper_lsp/ast.py b/vyper_lsp/ast.py index e16da1a..ce45b40 100644 --- a/vyper_lsp/ast.py +++ b/vyper_lsp/ast.py @@ -1,9 +1,12 @@ import copy import logging +from pathlib import Path from typing import Optional, List from lsprotocol.types import Position +from pygls.workspace import Document from vyper.ast import VyperNode, nodes from vyper.compiler import CompilerData +from vyper.compiler.input_bundle import FilesystemInputBundle logger = logging.getLogger("vyper-lsp") @@ -23,11 +26,16 @@ def from_node(cls, node: VyperNode): ast.ast_data_folded = node return ast - def update_ast(self, document): - self.build_ast(document.source) + def update_ast(self, doc: Document): + self.build_ast(doc) - def build_ast(self, src: str): - compiler_data = CompilerData(src) + def build_ast(self, doc: Document): + src = doc.source + uri = doc.uri + processed_uri = uri.replace("file://", "") + uri_path = Path(processed_uri) + uri_parent_path = uri_path.parent + compiler_data = CompilerData(src, input_bundle=FilesystemInputBundle([uri_parent_path])) try: # unforunately we need this deep copy so the ast doesnt change # out from under us when folding stuff happens diff --git a/vyper_lsp/main.py b/vyper_lsp/main.py index 88c1af2..f902345 100755 --- a/vyper_lsp/main.py +++ b/vyper_lsp/main.py @@ -1,4 +1,5 @@ import argparse +from pathlib import Path from typing import Optional, List import logging from .logging import LanguageServerLogHandler @@ -69,7 +70,7 @@ def _check_minimum_vyper_version(): @debouncer.debounce def validate_doc( - ls, + ls: LanguageServer, params: DidOpenTextDocumentParams | DidChangeTextDocumentParams | DidSaveTextDocumentParams, diff --git a/vyper_lsp/utils.py b/vyper_lsp/utils.py index 0bcf93f..abbda68 100644 --- a/vyper_lsp/utils.py +++ b/vyper_lsp/utils.py @@ -24,10 +24,6 @@ def get_source(filepath): return filepath.read_text() -def get_compiler_data(filepath): - source = get_source(filepath) - return CompilerData(source) - # detect if current line is a variable declaration def is_var_declaration(line):