-
-
Notifications
You must be signed in to change notification settings - Fork 646
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move BSP
QueryRule
registration out of core rules (#21311)
The refactor in #20913 to move BSP out of the core rules (via the new `AuxiliaryGoal` support) did not move the registration of BSP-related `QueryRule`s out of the core rules. This PR remedies that oversight by moving the `QueryRule` registration to the applicable BSP backends.
- Loading branch information
Showing
5 changed files
with
41 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright 2024 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
from __future__ import annotations | ||
|
||
from typing import Iterable | ||
|
||
from pants.bsp.protocol import BSPHandlerMapping | ||
from pants.engine.environment import EnvironmentName | ||
from pants.engine.fs import Workspace | ||
from pants.engine.rules import QueryRule, Rule | ||
from pants.engine.unions import UnionRule | ||
|
||
|
||
# Compute QueryRule's for each handler request/response pair. | ||
# Note: These are necessary because the BSP support is an auxiliary goal that makes | ||
# synchronous requests into the engine. | ||
def compute_handler_query_rules( | ||
rules: Iterable[Rule | UnionRule | QueryRule], | ||
) -> tuple[QueryRule, ...]: | ||
queries: list[QueryRule] = [] | ||
|
||
for rule in rules: | ||
if isinstance(rule, UnionRule): | ||
if rule.union_base == BSPHandlerMapping: | ||
impl = rule.union_member | ||
assert issubclass(impl, BSPHandlerMapping) | ||
queries.append( | ||
QueryRule(impl.response_type, (impl.request_type, Workspace, EnvironmentName)) | ||
) | ||
|
||
return tuple(queries) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters