mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
feat: update insta inline snapshot when clicks 'Update Test' runnable
This commit is contained in:
parent
88fbdcd510
commit
03c24d7c28
@ -104,7 +104,7 @@ pub use crate::{
|
|||||||
navigation_target::{NavigationTarget, TryToNav, UpmappingResult},
|
navigation_target::{NavigationTarget, TryToNav, UpmappingResult},
|
||||||
references::ReferenceSearchResult,
|
references::ReferenceSearchResult,
|
||||||
rename::RenameError,
|
rename::RenameError,
|
||||||
runnables::{Runnable, RunnableKind, TestId},
|
runnables::{Runnable, RunnableKind, TestId, UpdateTest},
|
||||||
signature_help::SignatureHelp,
|
signature_help::SignatureHelp,
|
||||||
static_index::{
|
static_index::{
|
||||||
StaticIndex, StaticIndexedFile, TokenId, TokenStaticData, VendoredLibrariesConfig,
|
StaticIndex, StaticIndexedFile, TokenId, TokenStaticData, VendoredLibrariesConfig,
|
||||||
|
@ -941,9 +941,7 @@ pub(crate) fn handle_runnables(
|
|||||||
|
|
||||||
let update_test = runnable.update_test;
|
let update_test = runnable.update_test;
|
||||||
if let Some(mut runnable) = to_proto::runnable(&snap, runnable)? {
|
if let Some(mut runnable) = to_proto::runnable(&snap, runnable)? {
|
||||||
if let Some(runnable) =
|
if let Some(runnable) = to_proto::make_update_runnable(&runnable, update_test) {
|
||||||
to_proto::make_update_runnable(&runnable, &update_test.label(), &update_test.env())
|
|
||||||
{
|
|
||||||
res.push(runnable);
|
res.push(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2158,7 +2156,7 @@ fn runnable_action_links(
|
|||||||
|
|
||||||
if hover_actions_config.update_test && client_commands_config.run_single {
|
if hover_actions_config.update_test && client_commands_config.run_single {
|
||||||
let label = update_test.label();
|
let label = update_test.label();
|
||||||
if let Some(r) = to_proto::make_update_runnable(&r, &label, &update_test.env()) {
|
if let Some(r) = to_proto::make_update_runnable(&r, update_test) {
|
||||||
let update_command = to_proto::command::run_single(&r, label.unwrap().as_str());
|
let update_command = to_proto::command::run_single(&r, label.unwrap().as_str());
|
||||||
group.commands.push(to_command_link(update_command, r.label.clone()));
|
group.commands.push(to_command_link(update_command, r.label.clone()));
|
||||||
}
|
}
|
||||||
|
@ -14,13 +14,13 @@ use ide::{
|
|||||||
InlayFieldsToResolve, InlayHint, InlayHintLabel, InlayHintLabelPart, InlayKind, LazyProperty,
|
InlayFieldsToResolve, InlayHint, InlayHintLabel, InlayHintLabelPart, InlayKind, LazyProperty,
|
||||||
Markup, NavigationTarget, ReferenceCategory, RenameError, Runnable, Severity, SignatureHelp,
|
Markup, NavigationTarget, ReferenceCategory, RenameError, Runnable, Severity, SignatureHelp,
|
||||||
SnippetEdit, SourceChange, StructureNodeKind, SymbolKind, TextEdit, TextRange, TextSize,
|
SnippetEdit, SourceChange, StructureNodeKind, SymbolKind, TextEdit, TextRange, TextSize,
|
||||||
|
UpdateTest,
|
||||||
};
|
};
|
||||||
use ide_db::{assists, rust_doc::format_docs, FxHasher};
|
use ide_db::{assists, rust_doc::format_docs, FxHasher};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use paths::{Utf8Component, Utf8Prefix};
|
use paths::{Utf8Component, Utf8Prefix};
|
||||||
use semver::VersionReq;
|
use semver::VersionReq;
|
||||||
use serde_json::to_value;
|
use serde_json::to_value;
|
||||||
use syntax::SmolStr;
|
|
||||||
use vfs::AbsPath;
|
use vfs::AbsPath;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -1623,8 +1623,7 @@ pub(crate) fn code_lens(
|
|||||||
}
|
}
|
||||||
if lens_config.update_test && client_commands_config.run_single {
|
if lens_config.update_test && client_commands_config.run_single {
|
||||||
let label = update_test.label();
|
let label = update_test.label();
|
||||||
let env = update_test.env();
|
if let Some(r) = make_update_runnable(&r, update_test) {
|
||||||
if let Some(r) = make_update_runnable(&r, &label, &env) {
|
|
||||||
let command = command::run_single(&r, label.unwrap().as_str());
|
let command = command::run_single(&r, label.unwrap().as_str());
|
||||||
acc.push(lsp_types::CodeLens {
|
acc.push(lsp_types::CodeLens {
|
||||||
range: annotation_range,
|
range: annotation_range,
|
||||||
@ -1871,22 +1870,22 @@ pub(crate) mod command {
|
|||||||
|
|
||||||
pub(crate) fn make_update_runnable(
|
pub(crate) fn make_update_runnable(
|
||||||
runnable: &lsp_ext::Runnable,
|
runnable: &lsp_ext::Runnable,
|
||||||
label: &Option<SmolStr>,
|
update_test: UpdateTest,
|
||||||
env: &[(&str, &str)],
|
|
||||||
) -> Option<lsp_ext::Runnable> {
|
) -> Option<lsp_ext::Runnable> {
|
||||||
if !matches!(runnable.args, lsp_ext::RunnableArgs::Cargo(_)) {
|
let label = update_test.label()?;
|
||||||
return None;
|
|
||||||
}
|
|
||||||
let label = label.as_ref()?;
|
|
||||||
|
|
||||||
let mut runnable = runnable.clone();
|
let mut runnable = runnable.clone();
|
||||||
runnable.label = format!("{} + {}", runnable.label, label);
|
runnable.label = format!("{} + {}", runnable.label, label);
|
||||||
|
|
||||||
let lsp_ext::RunnableArgs::Cargo(r) = &mut runnable.args else {
|
let lsp_ext::RunnableArgs::Cargo(r) = &mut runnable.args else {
|
||||||
unreachable!();
|
return None;
|
||||||
};
|
};
|
||||||
|
|
||||||
r.environment.extend(env.iter().map(|(k, v)| (k.to_string(), v.to_string())));
|
r.environment.extend(update_test.env().iter().map(|(k, v)| (k.to_string(), v.to_string())));
|
||||||
|
|
||||||
|
if update_test.insta {
|
||||||
|
r.cargo_args.insert(0, "insta".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
Some(runnable)
|
Some(runnable)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user