From fbde02370acf5aea036a3ee2869ffa434ee7f81b Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Thu, 29 May 2025 04:49:30 +0200 Subject: [PATCH] Set content_type for `view span` output (#15842) # Description Adds the content type for `view span` output. Allows the display hook to add syntax highlighting. # User-Facing Changes `view span` output will now have a content type set. # Tests + Formatting All pass, except for those that never pass on my machine. --- crates/nu-command/src/debug/view_span.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/nu-command/src/debug/view_span.rs b/crates/nu-command/src/debug/view_span.rs index 017cae62cf..64735027a9 100644 --- a/crates/nu-command/src/debug/view_span.rs +++ b/crates/nu-command/src/debug/view_span.rs @@ -1,4 +1,5 @@ use nu_engine::command_prelude::*; +use nu_protocol::{DataSource, PipelineMetadata}; #[derive(Clone)] pub struct ViewSpan; @@ -34,7 +35,7 @@ impl Command for ViewSpan { let start_span: Spanned = call.req(engine_state, stack, 0)?; let end_span: Spanned = call.req(engine_state, stack, 1)?; - if start_span.item < end_span.item { + let source = if start_span.item < end_span.item { let bin_contents = engine_state.get_span_contents(Span::new(start_span.item, end_span.item)); Ok( @@ -49,7 +50,14 @@ impl Command for ViewSpan { help: None, inner: vec![], }) - } + }; + + source.map(|x| { + x.set_metadata(Some(PipelineMetadata { + data_source: DataSource::None, + content_type: Some("application/x-nuscript".into()), + })) + }) } fn examples(&self) -> Vec {