Skip to content

Commit

Permalink
Merge pull request #19197 from andylokandy/insta
Browse files Browse the repository at this point in the history
feat: update insta inline snapshot when clicking 'Update Test' runnable
  • Loading branch information
Veykril authored Feb 24, 2025
2 parents b7e7893 + b59b04f commit f63f845
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion crates/ide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub use crate::{
navigation_target::{NavigationTarget, TryToNav, UpmappingResult},
references::ReferenceSearchResult,
rename::RenameError,
runnables::{Runnable, RunnableKind, TestId},
runnables::{Runnable, RunnableKind, TestId, UpdateTest},
signature_help::SignatureHelp,
static_index::{
StaticIndex, StaticIndexedFile, TokenId, TokenStaticData, VendoredLibrariesConfig,
Expand Down
6 changes: 2 additions & 4 deletions crates/rust-analyzer/src/handlers/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,9 +941,7 @@ pub(crate) fn handle_runnables(

let update_test = runnable.update_test;
if let Some(mut runnable) = to_proto::runnable(&snap, runnable)? {
if let Some(runnable) =
to_proto::make_update_runnable(&runnable, &update_test.label(), &update_test.env())
{
if let Some(runnable) = to_proto::make_update_runnable(&runnable, update_test) {
res.push(runnable);
}

Expand Down Expand Up @@ -2158,7 +2156,7 @@ fn runnable_action_links(

if hover_actions_config.update_test && client_commands_config.run_single {
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());
group.commands.push(to_command_link(update_command, r.label.clone()));
}
Expand Down
21 changes: 10 additions & 11 deletions crates/rust-analyzer/src/lsp/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ use ide::{
InlayFieldsToResolve, InlayHint, InlayHintLabel, InlayHintLabelPart, InlayKind, LazyProperty,
Markup, NavigationTarget, ReferenceCategory, RenameError, Runnable, Severity, SignatureHelp,
SnippetEdit, SourceChange, StructureNodeKind, SymbolKind, TextEdit, TextRange, TextSize,
UpdateTest,
};
use ide_db::{assists, rust_doc::format_docs, FxHasher};
use itertools::Itertools;
use paths::{Utf8Component, Utf8Prefix};
use semver::VersionReq;
use serde_json::to_value;
use syntax::SmolStr;
use vfs::AbsPath;

use crate::{
Expand Down Expand Up @@ -1623,8 +1623,7 @@ pub(crate) fn code_lens(
}
if lens_config.update_test && client_commands_config.run_single {
let label = update_test.label();
let env = update_test.env();
if let Some(r) = make_update_runnable(&r, &label, &env) {
if let Some(r) = make_update_runnable(&r, update_test) {
let command = command::run_single(&r, label.unwrap().as_str());
acc.push(lsp_types::CodeLens {
range: annotation_range,
Expand Down Expand Up @@ -1871,22 +1870,22 @@ pub(crate) mod command {

pub(crate) fn make_update_runnable(
runnable: &lsp_ext::Runnable,
label: &Option<SmolStr>,
env: &[(&str, &str)],
update_test: UpdateTest,
) -> Option<lsp_ext::Runnable> {
if !matches!(runnable.args, lsp_ext::RunnableArgs::Cargo(_)) {
return None;
}
let label = label.as_ref()?;
let label = update_test.label()?;

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

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_owned());
}

Some(runnable)
}
Expand Down

0 comments on commit f63f845

Please sign in to comment.