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