This commit is contained in:
Kira 2025-04-12 20:51:01 +02:00 committed by GitHub
commit 3f38ecbe34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 9 deletions

View File

@ -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),

View File

@ -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,13 @@ 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,
// If this external call is through an alias, then head.span points to the
// name of the alias, but we also need the name of the aliased command. We
// recover this from the span referenced by head.span_id.
FlatShape::External(working_set.get_span(head.span_id)),
));
} else {
flatten_expression_into(working_set, head, output);
}

View File

@ -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",