Skip to content

Commit 49116c6

Browse files
authored
Merge pull request #19197 from andylokandy/insta
feat: update insta inline snapshot when clicking 'Update Test' runnable
2 parents a4bd32c + 2b6ea13 commit 49116c6

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

src/tools/rust-analyzer/crates/ide/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub use crate::{
104104
navigation_target::{NavigationTarget, TryToNav, UpmappingResult},
105105
references::ReferenceSearchResult,
106106
rename::RenameError,
107-
runnables::{Runnable, RunnableKind, TestId},
107+
runnables::{Runnable, RunnableKind, TestId, UpdateTest},
108108
signature_help::SignatureHelp,
109109
static_index::{
110110
StaticIndex, StaticIndexedFile, TokenId, TokenStaticData, VendoredLibrariesConfig,

src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -941,9 +941,7 @@ pub(crate) fn handle_runnables(
941941

942942
let update_test = runnable.update_test;
943943
if let Some(mut runnable) = to_proto::runnable(&snap, runnable)? {
944-
if let Some(runnable) =
945-
to_proto::make_update_runnable(&runnable, &update_test.label(), &update_test.env())
946-
{
944+
if let Some(runnable) = to_proto::make_update_runnable(&runnable, update_test) {
947945
res.push(runnable);
948946
}
949947

@@ -2158,7 +2156,7 @@ fn runnable_action_links(
21582156

21592157
if hover_actions_config.update_test && client_commands_config.run_single {
21602158
let label = update_test.label();
2161-
if let Some(r) = to_proto::make_update_runnable(&r, &label, &update_test.env()) {
2159+
if let Some(r) = to_proto::make_update_runnable(&r, update_test) {
21622160
let update_command = to_proto::command::run_single(&r, label.unwrap().as_str());
21632161
group.commands.push(to_command_link(update_command, r.label.clone()));
21642162
}

src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ use ide::{
1414
InlayFieldsToResolve, InlayHint, InlayHintLabel, InlayHintLabelPart, InlayKind, LazyProperty,
1515
Markup, NavigationTarget, ReferenceCategory, RenameError, Runnable, Severity, SignatureHelp,
1616
SnippetEdit, SourceChange, StructureNodeKind, SymbolKind, TextEdit, TextRange, TextSize,
17+
UpdateTest,
1718
};
1819
use ide_db::{assists, rust_doc::format_docs, FxHasher};
1920
use itertools::Itertools;
2021
use paths::{Utf8Component, Utf8Prefix};
2122
use semver::VersionReq;
2223
use serde_json::to_value;
23-
use syntax::SmolStr;
2424
use vfs::AbsPath;
2525

2626
use crate::{
@@ -1623,8 +1623,7 @@ pub(crate) fn code_lens(
16231623
}
16241624
if lens_config.update_test && client_commands_config.run_single {
16251625
let label = update_test.label();
1626-
let env = update_test.env();
1627-
if let Some(r) = make_update_runnable(&r, &label, &env) {
1626+
if let Some(r) = make_update_runnable(&r, update_test) {
16281627
let command = command::run_single(&r, label.unwrap().as_str());
16291628
acc.push(lsp_types::CodeLens {
16301629
range: annotation_range,
@@ -1871,22 +1870,22 @@ pub(crate) mod command {
18711870

18721871
pub(crate) fn make_update_runnable(
18731872
runnable: &lsp_ext::Runnable,
1874-
label: &Option<SmolStr>,
1875-
env: &[(&str, &str)],
1873+
update_test: UpdateTest,
18761874
) -> Option<lsp_ext::Runnable> {
1877-
if !matches!(runnable.args, lsp_ext::RunnableArgs::Cargo(_)) {
1878-
return None;
1879-
}
1880-
let label = label.as_ref()?;
1875+
let label = update_test.label()?;
18811876

18821877
let mut runnable = runnable.clone();
18831878
runnable.label = format!("{} + {}", runnable.label, label);
18841879

18851880
let lsp_ext::RunnableArgs::Cargo(r) = &mut runnable.args else {
1886-
unreachable!();
1881+
return None;
18871882
};
18881883

1889-
r.environment.extend(env.iter().map(|(k, v)| (k.to_string(), v.to_string())));
1884+
r.environment.extend(update_test.env().iter().map(|(k, v)| (k.to_string(), v.to_string())));
1885+
1886+
if update_test.insta {
1887+
r.cargo_args.insert(0, "insta".to_owned());
1888+
}
18901889

18911890
Some(runnable)
18921891
}

0 commit comments

Comments
 (0)