mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 18:53:39 +00:00
commit
361cddc16c
@ -26,22 +26,16 @@ pub(crate) struct CargoTargetSpec {
|
||||
impl CargoTargetSpec {
|
||||
pub(crate) fn runnable_args(
|
||||
snap: &GlobalStateSnapshot,
|
||||
mut spec: Option<CargoTargetSpec>,
|
||||
spec: Option<CargoTargetSpec>,
|
||||
kind: &RunnableKind,
|
||||
cfg: &Option<CfgExpr>,
|
||||
) -> Result<(Vec<String>, Vec<String>)> {
|
||||
let mut args = Vec::new();
|
||||
let mut extra_args = Vec::new();
|
||||
|
||||
let target_required_features =
|
||||
spec.as_mut().map(|spec| mem::take(&mut spec.required_features)).unwrap_or(Vec::new());
|
||||
|
||||
match kind {
|
||||
RunnableKind::Test { test_id, attr } => {
|
||||
args.push("test".to_string());
|
||||
if let Some(spec) = spec {
|
||||
spec.push_to(&mut args, kind);
|
||||
}
|
||||
extra_args.push(test_id.to_string());
|
||||
if let TestId::Path(_) = test_id {
|
||||
extra_args.push("--exact".to_string());
|
||||
@ -53,17 +47,11 @@ impl CargoTargetSpec {
|
||||
}
|
||||
RunnableKind::TestMod { path } => {
|
||||
args.push("test".to_string());
|
||||
if let Some(spec) = spec {
|
||||
spec.push_to(&mut args, kind);
|
||||
}
|
||||
extra_args.push(path.to_string());
|
||||
extra_args.push("--nocapture".to_string());
|
||||
}
|
||||
RunnableKind::Bench { test_id } => {
|
||||
args.push("bench".to_string());
|
||||
if let Some(spec) = spec {
|
||||
spec.push_to(&mut args, kind);
|
||||
}
|
||||
extra_args.push(test_id.to_string());
|
||||
if let TestId::Path(_) = test_id {
|
||||
extra_args.push("--exact".to_string());
|
||||
@ -73,9 +61,6 @@ impl CargoTargetSpec {
|
||||
RunnableKind::DocTest { test_id } => {
|
||||
args.push("test".to_string());
|
||||
args.push("--doc".to_string());
|
||||
if let Some(spec) = spec {
|
||||
spec.push_to(&mut args, kind);
|
||||
}
|
||||
extra_args.push(test_id.to_string());
|
||||
extra_args.push("--nocapture".to_string());
|
||||
}
|
||||
@ -85,12 +70,17 @@ impl CargoTargetSpec {
|
||||
_ => "run",
|
||||
};
|
||||
args.push(subcommand.to_string());
|
||||
if let Some(spec) = spec {
|
||||
spec.push_to(&mut args, kind);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let target_required_features = if let Some(mut spec) = spec {
|
||||
let required_features = mem::take(&mut spec.required_features);
|
||||
spec.push_to(&mut args, kind);
|
||||
required_features
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
let cargo_config = snap.config.cargo();
|
||||
if cargo_config.all_features {
|
||||
args.push("--all-features".to_string());
|
||||
@ -122,9 +112,9 @@ impl CargoTargetSpec {
|
||||
global_state_snapshot: &GlobalStateSnapshot,
|
||||
file_id: FileId,
|
||||
) -> Result<Option<CargoTargetSpec>> {
|
||||
let crate_id = match global_state_snapshot.analysis.crate_for(file_id)?.first() {
|
||||
Some(&crate_id) => crate_id,
|
||||
None => return Ok(None),
|
||||
let crate_id = match &*global_state_snapshot.analysis.crate_for(file_id)? {
|
||||
&[crate_id, ..] => crate_id,
|
||||
_ => return Ok(None),
|
||||
};
|
||||
let (cargo_ws, target) = match global_state_snapshot.cargo_target_for_crate_root(crate_id) {
|
||||
Some(it) => it,
|
||||
|
@ -39,9 +39,9 @@ impl<'a> RequestDispatcher<'a> {
|
||||
f: fn(&mut GlobalState, R::Params) -> Result<R::Result>,
|
||||
) -> Result<&mut Self>
|
||||
where
|
||||
R: lsp_types::request::Request + 'static,
|
||||
R::Params: DeserializeOwned + panic::UnwindSafe + fmt::Debug + 'static,
|
||||
R::Result: Serialize + 'static,
|
||||
R: lsp_types::request::Request,
|
||||
R::Params: DeserializeOwned + panic::UnwindSafe + fmt::Debug,
|
||||
R::Result: Serialize,
|
||||
{
|
||||
let (id, params, panic_context) = match self.parse::<R>() {
|
||||
Some(it) => it,
|
||||
@ -63,8 +63,8 @@ impl<'a> RequestDispatcher<'a> {
|
||||
) -> Result<&mut Self>
|
||||
where
|
||||
R: lsp_types::request::Request + 'static,
|
||||
R::Params: DeserializeOwned + panic::UnwindSafe + fmt::Debug + 'static,
|
||||
R::Result: Serialize + 'static,
|
||||
R::Params: DeserializeOwned + panic::UnwindSafe + fmt::Debug,
|
||||
R::Result: Serialize,
|
||||
{
|
||||
let (id, params, panic_context) = match self.parse::<R>() {
|
||||
Some(it) => it,
|
||||
@ -89,8 +89,8 @@ impl<'a> RequestDispatcher<'a> {
|
||||
) -> &mut Self
|
||||
where
|
||||
R: lsp_types::request::Request + 'static,
|
||||
R::Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug + 'static,
|
||||
R::Result: Serialize + 'static,
|
||||
R::Params: DeserializeOwned + panic::UnwindSafe + Send + fmt::Debug,
|
||||
R::Result: Serialize,
|
||||
{
|
||||
let (id, params, panic_context) = match self.parse::<R>() {
|
||||
Some(it) => it,
|
||||
@ -126,11 +126,11 @@ impl<'a> RequestDispatcher<'a> {
|
||||
|
||||
fn parse<R>(&mut self) -> Option<(lsp_server::RequestId, R::Params, String)>
|
||||
where
|
||||
R: lsp_types::request::Request + 'static,
|
||||
R::Params: DeserializeOwned + fmt::Debug + 'static,
|
||||
R: lsp_types::request::Request,
|
||||
R::Params: DeserializeOwned + fmt::Debug,
|
||||
{
|
||||
let req = match &self.req {
|
||||
Some(req) if req.method == R::METHOD => self.req.take().unwrap(),
|
||||
Some(req) if req.method == R::METHOD => self.req.take()?,
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
@ -159,9 +159,9 @@ fn thread_result_to_response<R>(
|
||||
result: thread::Result<Result<R::Result>>,
|
||||
) -> lsp_server::Response
|
||||
where
|
||||
R: lsp_types::request::Request + 'static,
|
||||
R::Params: DeserializeOwned + 'static,
|
||||
R::Result: Serialize + 'static,
|
||||
R: lsp_types::request::Request,
|
||||
R::Params: DeserializeOwned,
|
||||
R::Result: Serialize,
|
||||
{
|
||||
match result {
|
||||
Ok(result) => result_to_response::<R>(id, result),
|
||||
@ -188,9 +188,9 @@ fn result_to_response<R>(
|
||||
result: Result<R::Result>,
|
||||
) -> lsp_server::Response
|
||||
where
|
||||
R: lsp_types::request::Request + 'static,
|
||||
R::Params: DeserializeOwned + 'static,
|
||||
R::Result: Serialize + 'static,
|
||||
R: lsp_types::request::Request,
|
||||
R::Params: DeserializeOwned,
|
||||
R::Result: Serialize,
|
||||
{
|
||||
match result {
|
||||
Ok(resp) => lsp_server::Response::new_ok(id, &resp),
|
||||
@ -226,8 +226,8 @@ impl<'a> NotificationDispatcher<'a> {
|
||||
f: fn(&mut GlobalState, N::Params) -> Result<()>,
|
||||
) -> Result<&mut Self>
|
||||
where
|
||||
N: lsp_types::notification::Notification + 'static,
|
||||
N::Params: DeserializeOwned + Send + 'static,
|
||||
N: lsp_types::notification::Notification,
|
||||
N::Params: DeserializeOwned + Send,
|
||||
{
|
||||
let not = match self.not.take() {
|
||||
Some(it) => it,
|
||||
|
Loading…
Reference in New Issue
Block a user