Skip to content

Commit

Permalink
🎨 Format LSP compiler & Sake code
Browse files Browse the repository at this point in the history
  • Loading branch information
michprev committed Nov 20, 2024
1 parent 8946e02 commit 300ce8a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 22 deletions.
75 changes: 56 additions & 19 deletions wake/lsp/lsp_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,13 @@ async def wait_subprocess_response(

for command_type, data in subprocess.responses.values():
if command_type == SubprocessCommandType.DETECTORS_FAILURE:
await self.__server.log_message(f"Detectors error: {data}", MessageType.ERROR)
await self.__server.log_message(
f"Detectors error: {data}", MessageType.ERROR
)
elif command_type == SubprocessCommandType.PRINTERS_FAILURE:
await self.__server.log_message(f"Printers error: {data}", MessageType.ERROR)
await self.__server.log_message(
f"Printers error: {data}", MessageType.ERROR
)

raise RuntimeError("Subprocess has terminated unexpectedly")

Expand Down Expand Up @@ -1163,7 +1167,10 @@ async def _handle_change(
if self.__perform_files_discovery:
while True:
try:
for f in glob.iglob(str(self.__config.project_root_path / "**/*.sol"), recursive=True):
for f in glob.iglob(
str(self.__config.project_root_path / "**/*.sol"),
recursive=True,
):
file = Path(f)
if not self.__file_excluded(file) and file.is_file():
self.__discovered_files.add(file.resolve())
Expand Down Expand Up @@ -1517,7 +1524,9 @@ async def bytecode_compile(
handler = LspLoggingHandler(logging_buffer)
logger.addHandler(handler)

compilation_units = self.__compiler.build_compilation_units_maximize(graph, logger)
compilation_units = self.__compiler.build_compilation_units_maximize(
graph, logger
)

for log in logging_buffer:
await self.__server.log_message(log[0], log[1])
Expand Down Expand Up @@ -1651,7 +1660,14 @@ async def bytecode_compile(
if progress_token is not None:
await self.__server.progress_end(progress_token)

return True, contract_info, asts, errors, skipped_source_units, source_units_to_paths
return (
True,
contract_info,
asts,
errors,
skipped_source_units,
source_units_to_paths,
)

async def __compile(
self,
Expand Down Expand Up @@ -1735,7 +1751,9 @@ async def __compile(
handler = LspLoggingHandler(logging_buffer)
logger.addHandler(handler)

compilation_units = self.__compiler.build_compilation_units_maximize(graph, logger)
compilation_units = self.__compiler.build_compilation_units_maximize(
graph, logger
)

for log in logging_buffer:
await self.__server.log_message(log[0], log[1])
Expand Down Expand Up @@ -1819,11 +1837,17 @@ async def __compile(
# however, there may be other CUs compiling this file (for different subprojects) where compilation was successful
# to prevent the case where files from different subprojects depending on this file would be left orphaned,
# we need to remove them from the build as well
files = {source_units_to_paths[to] for (_, to) in nx.edge_bfs(graph, [
source_unit_name
for source_unit_name in graph.nodes
if graph.nodes[source_unit_name]["path"] == file
])}
files = {
source_units_to_paths[to]
for (_, to) in nx.edge_bfs(
graph,
[
source_unit_name
for source_unit_name in graph.nodes
if graph.nodes[source_unit_name]["path"] == file
],
)
}
files.add(file)

for file in files:
Expand Down Expand Up @@ -2039,11 +2063,17 @@ async def __compile(
# however, there may be other CUs compiling this file (for different subprojects) where compilation was successful
# to prevent the case where files from different subprojects depending on this file would be left orphaned,
# we need to remove them from the build as well
files = {source_units_to_paths[to] for (_, to) in nx.edge_bfs(graph, [
source_unit_name
for source_unit_name in graph.nodes
if graph.nodes[source_unit_name]["path"] == file
])}
files = {
source_units_to_paths[to]
for (_, to) in nx.edge_bfs(
graph,
[
source_unit_name
for source_unit_name in graph.nodes
if graph.nodes[source_unit_name]["path"] == file
],
)
}
files.add(file)

for file in files:
Expand Down Expand Up @@ -2105,7 +2135,9 @@ def index_new_nodes():
# file was already processed
# index AST + register (possibly new) source unit name
self.__ir_reference_resolver.index_nodes(ast, path, cu.hash)
self.__source_units[path]._source_unit_names.add(ast.absolute_path)
self.__source_units[path]._source_unit_names.add(
ast.absolute_path
)
continue
elif cu not in compilation_units_per_file[path]:
# file recompiled but canonical AST not indexed yet
Expand All @@ -2119,7 +2151,9 @@ def index_new_nodes():
self.__ir_reference_resolver.index_nodes(ast, path, cu.hash)

for prev_ast, prev_cu_hash in ast_index[path]:
self.__ir_reference_resolver.index_nodes(prev_ast, path, prev_cu_hash)
self.__ir_reference_resolver.index_nodes(
prev_ast, path, prev_cu_hash
)

interval_tree = IntervalTree()
init = IrInitTuple(
Expand Down Expand Up @@ -2421,7 +2455,10 @@ async def __compilation_loop(self):
# perform Solidity files discovery
while True:
try:
for f in glob.iglob(str(self.__config.project_root_path / "**/*.sol"), recursive=True):
for f in glob.iglob(
str(self.__config.project_root_path / "**/*.sol"),
recursive=True,
):
file = Path(f)
if not self.__file_excluded(file) and file.is_file():
self.__discovered_files.add(file.resolve())
Expand Down
4 changes: 1 addition & 3 deletions wake/lsp/sake.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,7 @@ async def compile(self) -> SakeCompilationResult:
"big",
)
metadata = bytes.fromhex(
info.evm.deployed_bytecode.object[
-metadata_length * 2 - 4 : -4
]
info.evm.deployed_bytecode.object[-metadata_length * 2 - 4 : -4]
)
self.fqn_by_metadata[metadata] = fqn

Expand Down

0 comments on commit 300ce8a

Please sign in to comment.