Skip to content

Commit

Permalink
Implement initial InputBundle support
Browse files Browse the repository at this point in the history
now supports compiling with local imports, i.e. creates a
FileSystemInputBundle with the parent directory of the contract being
compiled
  • Loading branch information
z80dev committed Aug 9, 2024
1 parent 44df97a commit 5b38d3d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
9 changes: 8 additions & 1 deletion vyper_lsp/analyzer/AstAnalyzer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from pathlib import Path
import re
from typing import List, Optional
import warnings
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions vyper_lsp/ast.py
Original file line number Diff line number Diff line change
@@ -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")

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion vyper_lsp/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
from pathlib import Path
from typing import Optional, List
import logging
from .logging import LanguageServerLogHandler
Expand Down Expand Up @@ -69,7 +70,7 @@ def _check_minimum_vyper_version():

@debouncer.debounce
def validate_doc(
ls,
ls: LanguageServer,
params: DidOpenTextDocumentParams
| DidChangeTextDocumentParams
| DidSaveTextDocumentParams,
Expand Down
4 changes: 0 additions & 4 deletions vyper_lsp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 5b38d3d

Please sign in to comment.