From a235a2108457936b129b6b2fa145266085a186df Mon Sep 17 00:00:00 2001 From: Hirokazu Hata Date: Sat, 26 Jan 2019 18:31:16 +0900 Subject: [PATCH] Replace crate with pub(crate) --- src/build/cargo_plan.rs | 42 ++++++++++++++++++++--------------------- src/build/external.rs | 30 ++++++++++++++--------------- src/build/plan.rs | 14 +++++++------- src/build/rustc.rs | 2 +- src/server/dispatch.rs | 8 ++++---- src/server/io.rs | 2 +- src/server/message.rs | 12 ++++++------ 7 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/build/cargo_plan.rs b/src/build/cargo_plan.rs index 3bdf7e3cd45..645ac5f4115 100644 --- a/src/build/cargo_plan.rs +++ b/src/build/cargo_plan.rs @@ -43,23 +43,23 @@ use crate::build::PackageArg; /// Main key type by which `Unit`s will be distinguished in the build plan. /// In Target we're mostly interested in TargetKind (Lib, Bin, ...) and name /// (e.g. we can have 2 binary targets with different names). -crate type UnitKey = (PackageId, Target, CompileMode); +pub(crate) type UnitKey = (PackageId, Target, CompileMode); /// Holds the information how exactly the build will be performed for a given /// workspace with given, specified features. #[derive(Debug, Default)] -crate struct CargoPlan { +pub(crate) struct CargoPlan { /// Stores a full Cargo `Unit` data for a first processed unit with a given key. - crate units: HashMap, + pub(crate) units: HashMap, /// Main dependency graph between the simplified units. - crate dep_graph: HashMap>, + pub(crate) dep_graph: HashMap>, /// Reverse dependency graph that's used to construct a dirty compiler call queue. - crate rev_dep_graph: HashMap>, + pub(crate) rev_dep_graph: HashMap>, /// Cached compiler calls used when creating a compiler call queue. - crate compiler_jobs: HashMap, + pub(crate) compiler_jobs: HashMap, /// Calculated input files that unit depend on. - crate input_files: HashMap>, - crate file_key_mapping: HashMap>, + pub(crate) input_files: HashMap>, + pub(crate) file_key_mapping: HashMap>, // An object for finding the package which a file belongs to and this inferring // a package argument. package_map: Option, @@ -69,14 +69,14 @@ crate struct CargoPlan { } impl CargoPlan { - crate fn with_manifest(manifest_path: &Path) -> CargoPlan { + pub(crate) fn with_manifest(manifest_path: &Path) -> CargoPlan { CargoPlan { package_map: Some(PackageMap::new(manifest_path)), ..Default::default() } } - crate fn with_packages(manifest_path: &Path, pkgs: HashSet) -> CargoPlan { + pub(crate) fn with_packages(manifest_path: &Path, pkgs: HashSet) -> CargoPlan { CargoPlan { built_packages: pkgs, ..Self::with_manifest(manifest_path) @@ -85,14 +85,14 @@ impl CargoPlan { /// Returns whether a build plan has cached compiler invocations and dep /// graph so it's at all able to return a job queue via `prepare_work`. - crate fn is_ready(&self) -> bool { + pub(crate) fn is_ready(&self) -> bool { !self.compiler_jobs.is_empty() } /// Cache a given compiler invocation in `ProcessBuilder` for a given /// `PackageId` and `TargetKind` in `Target`, to be used when processing /// cached build plan. - crate fn cache_compiler_job( + pub(crate) fn cache_compiler_job( &mut self, id: PackageId, target: &Target, @@ -103,7 +103,7 @@ impl CargoPlan { self.compiler_jobs.insert(unit_key, cmd.clone()); } - crate fn cache_input_files( + pub(crate) fn cache_input_files( &mut self, id: PackageId, target: &Target, @@ -140,7 +140,7 @@ impl CargoPlan { /// Emplace a given `Unit`, along with its `Unit` dependencies (recursively) /// into the dependency graph as long as the passed `Unit` isn't filtered /// out by the `filter` closure. - crate fn emplace_dep_with_filter( + pub(crate) fn emplace_dep_with_filter( &mut self, unit: &Unit<'_>, cx: &Context<'_, '_>, @@ -349,7 +349,7 @@ impl CargoPlan { } } - crate fn prepare_work + fmt::Debug>( + pub(crate) fn prepare_work + fmt::Debug>( &self, modified: &[T], ) -> WorkStatus { @@ -517,12 +517,12 @@ fn key_from_unit(unit: &Unit<'_>) -> UnitKey { #[derive(Hash, PartialEq, Eq, Debug, Clone)] /// An owned version of `cargo::core::Unit`. -crate struct OwnedUnit { - crate id: PackageId, - crate target: Target, - crate profile: Profile, - crate kind: Kind, - crate mode: CompileMode, +pub(crate) struct OwnedUnit { + pub(crate) id: PackageId, + pub(crate) target: Target, + pub(crate) profile: Profile, + pub(crate) kind: Kind, + pub(crate) mode: CompileMode, } impl<'a> From> for OwnedUnit { diff --git a/src/build/external.rs b/src/build/external.rs index 8fea5039a6f..511de5bbba1 100644 --- a/src/build/external.rs +++ b/src/build/external.rs @@ -171,25 +171,25 @@ fn plan_from_analysis(analysis: &[Analysis], build_dir: &Path) -> Result, +pub(crate) struct RawPlan { + pub(crate) invocations: Vec, } #[derive(Debug, Deserialize)] -crate struct RawInvocation { - crate deps: Vec, - crate outputs: Vec, +pub(crate) struct RawInvocation { + pub(crate) deps: Vec, + pub(crate) outputs: Vec, #[serde(default)] - crate links: BTreeMap, - crate program: String, - crate args: Vec, - crate env: BTreeMap, + pub(crate) links: BTreeMap, + pub(crate) program: String, + pub(crate) args: Vec, + pub(crate) env: BTreeMap, #[serde(default)] - crate cwd: Option, + pub(crate) cwd: Option, } #[derive(Clone, Debug)] -crate struct Invocation { +pub(crate) struct Invocation { deps: Vec, // FIXME: Use arena and store refs instead for ergonomics outputs: Vec, links: BTreeMap, @@ -201,7 +201,7 @@ crate struct Invocation { /// Safe build plan type, invocation dependencies are guaranteed to be inside /// the plan. #[derive(Debug, Default)] -crate struct ExternalPlan { +pub(crate) struct ExternalPlan { units: HashMap, deps: HashMap>, rev_deps: HashMap>, @@ -248,11 +248,11 @@ impl Invocation { } impl ExternalPlan { - crate fn new() -> ExternalPlan { + pub(crate) fn new() -> ExternalPlan { Default::default() } - crate fn with_units(units: Vec) -> ExternalPlan { + pub(crate) fn with_units(units: Vec) -> ExternalPlan { let mut plan = ExternalPlan::new(); for unit in &units { for &dep in &unit.deps { @@ -272,7 +272,7 @@ impl ExternalPlan { self.rev_deps.entry(dep).or_insert_with(HashSet::new).insert(key); } - crate fn try_from_raw(build_dir: &Path, raw: RawPlan) -> Result { + pub(crate) fn try_from_raw(build_dir: &Path, raw: RawPlan) -> Result { // Sanity check, each dependency (index) has to be inside the build plan if raw .invocations diff --git a/src/build/plan.rs b/src/build/plan.rs index 63079a61bf9..40aaaa08652 100644 --- a/src/build/plan.rs +++ b/src/build/plan.rs @@ -20,12 +20,12 @@ use crate::build::{BuildResult, Internals, PackageArg}; use crate::build::cargo_plan::CargoPlan; use crate::build::external::ExternalPlan; -crate trait BuildKey { +pub(crate) trait BuildKey { type Key: Eq + Hash; fn key(&self) -> Self::Key; } -crate trait BuildGraph { +pub(crate) trait BuildGraph { type Unit: BuildKey; fn units(&self) -> Vec<&Self::Unit>; @@ -48,14 +48,14 @@ crate trait BuildGraph { } #[derive(Debug)] -crate enum WorkStatus { +pub(crate) enum WorkStatus { NeedsCargo(PackageArg), Execute(JobQueue), } #[allow(clippy::large_enum_variant)] #[derive(Debug)] -crate enum BuildPlan { +pub(crate) enum BuildPlan { External(ExternalPlan), Cargo(CargoPlan) } @@ -74,7 +74,7 @@ impl BuildPlan { } #[derive(Debug)] -crate struct JobQueue(Vec); +pub(crate) struct JobQueue(Vec); /// Returns an immediately next argument to the one specified in a given /// ProcessBuilder (or `None` if the searched or the next argument could not be found). @@ -93,11 +93,11 @@ fn proc_argument_value>(prc: &ProcessBuilder, key: T) -> Option< } impl JobQueue { - crate fn with_commands(jobs: Vec) -> JobQueue { + pub(crate) fn with_commands(jobs: Vec) -> JobQueue { JobQueue(jobs) } - crate fn dequeue(&mut self) -> Option { + pub(crate) fn dequeue(&mut self) -> Option { self.0.pop() } diff --git a/src/build/rustc.rs b/src/build/rustc.rs index 24c73f85039..d9a41c07bfe 100644 --- a/src/build/rustc.rs +++ b/src/build/rustc.rs @@ -59,7 +59,7 @@ use std::sync::{Arc, Mutex}; use std::process::Command; // Runs a single instance of rustc. Runs in-process. -crate fn rustc( +pub(crate) fn rustc( vfs: &Vfs, args: &[String], envs: &HashMap>, diff --git a/src/server/dispatch.rs b/src/server/dispatch.rs index 6022c40ef11..3bea1ff28e3 100644 --- a/src/server/dispatch.rs +++ b/src/server/dispatch.rs @@ -37,7 +37,7 @@ pub const DEFAULT_REQUEST_TIMEOUT: Duration = Duration::from_millis(3_600_000); macro_rules! define_dispatch_request_enum { ($($request_type:ident),*$(,)*) => { #[allow(clippy::large_enum_variant)] // seems ok for a short lived macro-enum - crate enum DispatchRequest { + pub(crate) enum DispatchRequest { $( $request_type(Request<$request_type>), )* @@ -112,13 +112,13 @@ define_dispatch_request_enum!( /// handle the requests sequentially, without blocking stdin. /// Requests dispatched this way are automatically timed out & avoid /// processing if have already timed out before starting. -crate struct Dispatcher { +pub(crate) struct Dispatcher { sender: mpsc::Sender<(DispatchRequest, InitActionContext, JobToken)>, } impl Dispatcher { /// Creates a new `Dispatcher` starting a new thread and channel - crate fn new(out: O) -> Self { + pub(crate) fn new(out: O) -> Self { let (sender, receiver) = mpsc::channel::<(DispatchRequest, InitActionContext, JobToken)>(); thread::Builder::new() @@ -134,7 +134,7 @@ impl Dispatcher { } /// Sends a request to the dispatch-worker thread, does not block - crate fn dispatch>(&mut self, request: R, ctx: InitActionContext) { + pub(crate) fn dispatch>(&mut self, request: R, ctx: InitActionContext) { let (job, token) = ConcurrentJob::new(); ctx.add_job(job); if let Err(err) = self.sender.send((request.into(), ctx, token)) { diff --git a/src/server/io.rs b/src/server/io.rs index 7b93d4a662d..21c23ebd583 100644 --- a/src/server/io.rs +++ b/src/server/io.rs @@ -195,7 +195,7 @@ pub(super) struct StdioOutput { impl StdioOutput { /// Construct a new `stdout` output. - crate fn new() -> StdioOutput { + pub(crate) fn new() -> StdioOutput { StdioOutput { next_id: Arc::new(AtomicU64::new(1)), } diff --git a/src/server/message.rs b/src/server/message.rs index 77cc65ba8e0..adcaada085a 100644 --- a/src/server/message.rs +++ b/src/server/message.rs @@ -293,13 +293,13 @@ where #[derive(Debug, PartialEq)] pub(super) struct RawMessage { - crate method: String, - crate id: Id, - crate params: serde_json::Value, + pub(crate) method: String, + pub(crate) id: Id, + pub(crate) params: serde_json::Value, } impl RawMessage { - crate fn parse_as_request<'de, R>(&'de self) -> Result, jsonrpc::Error> + pub(crate) fn parse_as_request<'de, R>(&'de self) -> Result, jsonrpc::Error> where R: LSPRequest, ::Params: serde::Deserialize<'de>, @@ -334,7 +334,7 @@ impl RawMessage { } } - crate fn parse_as_notification<'de, T>(&'de self) -> Result, jsonrpc::Error> + pub(crate) fn parse_as_notification<'de, T>(&'de self) -> Result, jsonrpc::Error> where T: LSPNotification, ::Params: serde::Deserialize<'de>, @@ -350,7 +350,7 @@ impl RawMessage { }) } - crate fn try_parse(msg: &str) -> Result, jsonrpc::Error> { + pub(crate) fn try_parse(msg: &str) -> Result, jsonrpc::Error> { // Parse the message. let ls_command: serde_json::Value = serde_json::from_str(msg).map_err(|_| jsonrpc::Error::parse_error())?;