-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Represent a package in Proc Macro Server more reliably
- Loading branch information
1 parent
bf30ab7
commit 31ffcfa
Showing
10 changed files
with
83 additions
and
29 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
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
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 |
---|---|---|
@@ -1,8 +1,40 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Representation of the Scarb package. | ||
/// | ||
/// # Invariants | ||
/// 1. `name` and `discriminator` must refer to the same `CompilationUnitComponent`. | ||
/// 2. `name` must be identical to the one from `scarb-metadata`. | ||
/// At the moment, the package name is obtained by calling `CompilationUnitComponent::cairo_package_name`. | ||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, Hash)] | ||
pub struct Package { | ||
/// Name of the `CompilationUnitComponent` associated with the package. | ||
pub name: String, | ||
/// A `CompilationUnitComponent` discriminator which represents | ||
/// the package uniquely in the workspace. | ||
/// `None` only for corelib. | ||
pub discriminator: Option<String>, | ||
} | ||
|
||
impl Package { | ||
/// Builds a new [`Package`] from `name` and `discriminator` | ||
/// without checking them for consistency. | ||
/// | ||
/// # Safety | ||
/// Communication between PMS and LS relies on the invariant that `name` and `discriminator` | ||
/// refer to the same CU component and are consistent with `scarb-metadata`. | ||
/// The caller must ensure correctness of the provided values. | ||
pub fn new(name: impl AsRef<str>, discriminator: impl AsRef<str>) -> Self { | ||
Self { | ||
name: name.as_ref().to_string(), | ||
discriminator: Some(discriminator.as_ref().to_string()), | ||
} | ||
} | ||
} | ||
|
||
/// A description of the location in the workspace where particular macro is available. | ||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, Hash)] | ||
pub struct ProcMacroScope { | ||
/// Serialized `PackageId` of the package in which context the action occurs. | ||
pub package_id: String, | ||
/// A package in which context the action occurs. | ||
pub package: Package, | ||
} |
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