mirror of
https://github.com/nushell/nushell.git
synced 2025-06-20 18:08:36 +02:00
Fix highlighting of aliases to external commands
This commit is contained in:
parent
bf1f2d5ebd
commit
df798b657c
@ -30,9 +30,8 @@ impl Highlighter for NuHighlighter {
|
|||||||
// externals may slow down things too much.
|
// externals may slow down things too much.
|
||||||
if highlight_resolved_externals {
|
if highlight_resolved_externals {
|
||||||
for (span, shape) in shapes.iter_mut() {
|
for (span, shape) in shapes.iter_mut() {
|
||||||
if *shape == FlatShape::External {
|
if let FlatShape::External(aliased_command_span) = *shape {
|
||||||
let str_contents =
|
let str_contents = working_set.get_span_contents(aliased_command_span);
|
||||||
working_set.get_span_contents(Span::new(span.start, span.end));
|
|
||||||
|
|
||||||
let str_word = String::from_utf8_lossy(str_contents).to_string();
|
let str_word = String::from_utf8_lossy(str_contents).to_string();
|
||||||
let paths = env::path_str(&self.engine_state, &self.stack, *span).ok();
|
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::Float => add_colored_token(&shape.1, next_token),
|
||||||
FlatShape::Range => 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::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::ExternalArg => add_colored_token(&shape.1, next_token),
|
||||||
FlatShape::ExternalResolved => 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),
|
FlatShape::Keyword => add_colored_token(&shape.1, next_token),
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use core::str;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::{
|
ast::{
|
||||||
Argument, Block, Expr, Expression, ExternalArgument, ImportPatternMember, ListItem,
|
Argument, Block, Expr, Expression, ExternalArgument, ImportPatternMember, ListItem,
|
||||||
@ -5,7 +6,7 @@ use nu_protocol::{
|
|||||||
RecordItem,
|
RecordItem,
|
||||||
},
|
},
|
||||||
engine::StateWorkingSet,
|
engine::StateWorkingSet,
|
||||||
DeclId, Span, SyntaxShape, VarId,
|
DeclId, GetSpan, Span, SyntaxShape, VarId,
|
||||||
};
|
};
|
||||||
use std::fmt::{Display, Formatter, Result};
|
use std::fmt::{Display, Formatter, Result};
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ pub enum FlatShape {
|
|||||||
Custom(DeclId),
|
Custom(DeclId),
|
||||||
DateTime,
|
DateTime,
|
||||||
Directory,
|
Directory,
|
||||||
External,
|
External(Span),
|
||||||
ExternalArg,
|
ExternalArg,
|
||||||
ExternalResolved,
|
ExternalResolved,
|
||||||
Filepath,
|
Filepath,
|
||||||
@ -58,7 +59,7 @@ impl FlatShape {
|
|||||||
FlatShape::Custom(_) => "shape_custom",
|
FlatShape::Custom(_) => "shape_custom",
|
||||||
FlatShape::DateTime => "shape_datetime",
|
FlatShape::DateTime => "shape_datetime",
|
||||||
FlatShape::Directory => "shape_directory",
|
FlatShape::Directory => "shape_directory",
|
||||||
FlatShape::External => "shape_external",
|
FlatShape::External(_) => "shape_external",
|
||||||
FlatShape::ExternalArg => "shape_externalarg",
|
FlatShape::ExternalArg => "shape_externalarg",
|
||||||
FlatShape::ExternalResolved => "shape_external_resolved",
|
FlatShape::ExternalResolved => "shape_external_resolved",
|
||||||
FlatShape::Filepath => "shape_filepath",
|
FlatShape::Filepath => "shape_filepath",
|
||||||
@ -326,7 +327,10 @@ fn flatten_expression_into(
|
|||||||
}
|
}
|
||||||
Expr::ExternalCall(head, args) => {
|
Expr::ExternalCall(head, args) => {
|
||||||
if let Expr::String(..) | Expr::GlobPattern(..) = &head.expr {
|
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 {
|
} else {
|
||||||
flatten_expression_into(working_set, head, output);
|
flatten_expression_into(working_set, head, output);
|
||||||
}
|
}
|
||||||
|
@ -403,7 +403,7 @@ pub fn hover(engine_state: &mut EngineState, file_path: &str, location: &Value)
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
FlatShape::External => println!(
|
FlatShape::External(_) => println!(
|
||||||
"{}",
|
"{}",
|
||||||
json!({
|
json!({
|
||||||
"hover": "external",
|
"hover": "external",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user