From df798b657c414d21768734b6daf632a0397e6624 Mon Sep 17 00:00:00 2001 From: Kira Date: Mon, 24 Mar 2025 23:07:41 +0100 Subject: [PATCH] Fix highlighting of aliases to external commands --- crates/nu-cli/src/syntax_highlight.rs | 7 +++---- crates/nu-parser/src/flatten.rs | 12 ++++++++---- src/ide.rs | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/crates/nu-cli/src/syntax_highlight.rs b/crates/nu-cli/src/syntax_highlight.rs index 283a06f97e..1212a484bd 100644 --- a/crates/nu-cli/src/syntax_highlight.rs +++ b/crates/nu-cli/src/syntax_highlight.rs @@ -30,9 +30,8 @@ impl Highlighter for NuHighlighter { // externals may slow down things too much. if highlight_resolved_externals { for (span, shape) in shapes.iter_mut() { - if *shape == FlatShape::External { - let str_contents = - working_set.get_span_contents(Span::new(span.start, span.end)); + if let FlatShape::External(aliased_command_span) = *shape { + let str_contents = working_set.get_span_contents(aliased_command_span); let str_word = String::from_utf8_lossy(str_contents).to_string(); let paths = env::path_str(&self.engine_state, &self.stack, *span).ok(); @@ -99,7 +98,7 @@ impl Highlighter for NuHighlighter { FlatShape::Float => add_colored_token(&shape.1, next_token), FlatShape::Range => add_colored_token(&shape.1, next_token), FlatShape::InternalCall(_) => add_colored_token(&shape.1, next_token), - FlatShape::External => add_colored_token(&shape.1, next_token), + FlatShape::External(_) => add_colored_token(&shape.1, next_token), FlatShape::ExternalArg => add_colored_token(&shape.1, next_token), FlatShape::ExternalResolved => add_colored_token(&shape.1, next_token), FlatShape::Keyword => add_colored_token(&shape.1, next_token), diff --git a/crates/nu-parser/src/flatten.rs b/crates/nu-parser/src/flatten.rs index c49b1720df..8411025272 100644 --- a/crates/nu-parser/src/flatten.rs +++ b/crates/nu-parser/src/flatten.rs @@ -1,3 +1,4 @@ +use core::str; use nu_protocol::{ ast::{ Argument, Block, Expr, Expression, ExternalArgument, ImportPatternMember, ListItem, @@ -5,7 +6,7 @@ use nu_protocol::{ RecordItem, }, engine::StateWorkingSet, - DeclId, Span, SyntaxShape, VarId, + DeclId, GetSpan, Span, SyntaxShape, VarId, }; use std::fmt::{Display, Formatter, Result}; @@ -18,7 +19,7 @@ pub enum FlatShape { Custom(DeclId), DateTime, Directory, - External, + External(Span), ExternalArg, ExternalResolved, Filepath, @@ -58,7 +59,7 @@ impl FlatShape { FlatShape::Custom(_) => "shape_custom", FlatShape::DateTime => "shape_datetime", FlatShape::Directory => "shape_directory", - FlatShape::External => "shape_external", + FlatShape::External(_) => "shape_external", FlatShape::ExternalArg => "shape_externalarg", FlatShape::ExternalResolved => "shape_external_resolved", FlatShape::Filepath => "shape_filepath", @@ -326,7 +327,10 @@ fn flatten_expression_into( } Expr::ExternalCall(head, args) => { if let Expr::String(..) | Expr::GlobPattern(..) = &head.expr { - output.push((head.span, FlatShape::External)); + output.push(( + head.span, + FlatShape::External(working_set.get_span(head.span_id)), + )); } else { flatten_expression_into(working_set, head, output); } diff --git a/src/ide.rs b/src/ide.rs index 8d64fdd487..33ad7efdcf 100644 --- a/src/ide.rs +++ b/src/ide.rs @@ -403,7 +403,7 @@ pub fn hover(engine_state: &mut EngineState, file_path: &str, location: &Value) } }) ), - FlatShape::External => println!( + FlatShape::External(_) => println!( "{}", json!({ "hover": "external",