forked from extern/nushell
Highlight block and record (#653)
This commit is contained in:
parent
9535e2c309
commit
fe5f65a247
@ -142,6 +142,20 @@ impl Highlighter for NuHighlighter {
|
|||||||
next_token,
|
next_token,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
FlatShape::Record => {
|
||||||
|
// nushell ???
|
||||||
|
output.push((
|
||||||
|
get_shape_color(shape.1.to_string(), &self.config),
|
||||||
|
next_token,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
FlatShape::Block => {
|
||||||
|
// nushell ???
|
||||||
|
output.push((
|
||||||
|
get_shape_color(shape.1.to_string(), &self.config),
|
||||||
|
next_token,
|
||||||
|
))
|
||||||
|
}
|
||||||
FlatShape::Filepath => output.push((
|
FlatShape::Filepath => output.push((
|
||||||
// nushell Path
|
// nushell Path
|
||||||
get_shape_color(shape.1.to_string(), &self.config),
|
get_shape_color(shape.1.to_string(), &self.config),
|
||||||
|
@ -21,6 +21,8 @@ pub fn get_shape_color(shape: String, conf: &Config) -> Style {
|
|||||||
"flatshape_string_interpolation" => Style::new().fg(Color::Cyan).bold(),
|
"flatshape_string_interpolation" => Style::new().fg(Color::Cyan).bold(),
|
||||||
"flatshape_list" => Style::new().fg(Color::Cyan).bold(),
|
"flatshape_list" => Style::new().fg(Color::Cyan).bold(),
|
||||||
"flatshape_table" => Style::new().fg(Color::Blue).bold(),
|
"flatshape_table" => Style::new().fg(Color::Blue).bold(),
|
||||||
|
"flatshape_record" => Style::new().fg(Color::Cyan).bold(),
|
||||||
|
"flatshape_block" => Style::new().fg(Color::Blue).bold(),
|
||||||
"flatshape_filepath" => Style::new().fg(Color::Cyan),
|
"flatshape_filepath" => Style::new().fg(Color::Cyan),
|
||||||
"flatshape_globpattern" => Style::new().fg(Color::Cyan).bold(),
|
"flatshape_globpattern" => Style::new().fg(Color::Cyan).bold(),
|
||||||
"flatshape_variable" => Style::new().fg(Color::Purple),
|
"flatshape_variable" => Style::new().fg(Color::Purple),
|
||||||
|
@ -22,6 +22,8 @@ pub enum FlatShape {
|
|||||||
StringInterpolation,
|
StringInterpolation,
|
||||||
List,
|
List,
|
||||||
Table,
|
Table,
|
||||||
|
Record,
|
||||||
|
Block,
|
||||||
Filepath,
|
Filepath,
|
||||||
GlobPattern,
|
GlobPattern,
|
||||||
Variable,
|
Variable,
|
||||||
@ -48,6 +50,8 @@ impl Display for FlatShape {
|
|||||||
FlatShape::StringInterpolation => write!(f, "flatshape_string_interpolation"),
|
FlatShape::StringInterpolation => write!(f, "flatshape_string_interpolation"),
|
||||||
FlatShape::List => write!(f, "flatshape_string_interpolation"),
|
FlatShape::List => write!(f, "flatshape_string_interpolation"),
|
||||||
FlatShape::Table => write!(f, "flatshape_table"),
|
FlatShape::Table => write!(f, "flatshape_table"),
|
||||||
|
FlatShape::Record => write!(f, "flatshape_record"),
|
||||||
|
FlatShape::Block => write!(f, "flatshape_block"),
|
||||||
FlatShape::Filepath => write!(f, "flatshape_filepath"),
|
FlatShape::Filepath => write!(f, "flatshape_filepath"),
|
||||||
FlatShape::GlobPattern => write!(f, "flatshape_globpattern"),
|
FlatShape::GlobPattern => write!(f, "flatshape_globpattern"),
|
||||||
FlatShape::Variable => write!(f, "flatshape_variable"),
|
FlatShape::Variable => write!(f, "flatshape_variable"),
|
||||||
@ -91,7 +95,48 @@ pub fn flatten_expression(
|
|||||||
output.extend(flatten_expression(working_set, rhs));
|
output.extend(flatten_expression(working_set, rhs));
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
Expr::Block(block_id) => flatten_block(working_set, working_set.get_block(*block_id)),
|
Expr::Block(block_id) => {
|
||||||
|
let outer_span = expr.span;
|
||||||
|
|
||||||
|
let mut output = vec![];
|
||||||
|
|
||||||
|
let flattened = flatten_block(working_set, working_set.get_block(*block_id));
|
||||||
|
|
||||||
|
if let Some(first) = flattened.first() {
|
||||||
|
if first.0.start > outer_span.start {
|
||||||
|
output.push((
|
||||||
|
Span {
|
||||||
|
start: outer_span.start,
|
||||||
|
end: first.0.start,
|
||||||
|
},
|
||||||
|
FlatShape::Block,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let last = if let Some(last) = flattened.last() {
|
||||||
|
if last.0.end < outer_span.end {
|
||||||
|
Some((
|
||||||
|
Span {
|
||||||
|
start: last.0.end,
|
||||||
|
end: outer_span.end,
|
||||||
|
},
|
||||||
|
FlatShape::Table,
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
output.extend(flattened);
|
||||||
|
if let Some(last) = last {
|
||||||
|
output.push(last)
|
||||||
|
}
|
||||||
|
|
||||||
|
output
|
||||||
|
}
|
||||||
Expr::Call(call) => {
|
Expr::Call(call) => {
|
||||||
let mut output = vec![(call.head, FlatShape::InternalCall)];
|
let mut output = vec![(call.head, FlatShape::InternalCall)];
|
||||||
|
|
||||||
@ -273,11 +318,57 @@ pub fn flatten_expression(
|
|||||||
output
|
output
|
||||||
}
|
}
|
||||||
Expr::Record(list) => {
|
Expr::Record(list) => {
|
||||||
|
let outer_span = expr.span;
|
||||||
|
let mut last_end = outer_span.start;
|
||||||
|
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
for l in list {
|
for l in list {
|
||||||
output.extend(flatten_expression(working_set, &l.0));
|
let flattened_lhs = flatten_expression(working_set, &l.0);
|
||||||
output.extend(flatten_expression(working_set, &l.1));
|
let flattened_rhs = flatten_expression(working_set, &l.1);
|
||||||
|
|
||||||
|
if let Some(first) = flattened_lhs.first() {
|
||||||
|
if first.0.start > last_end {
|
||||||
|
output.push((
|
||||||
|
Span {
|
||||||
|
start: last_end,
|
||||||
|
end: first.0.start,
|
||||||
|
},
|
||||||
|
FlatShape::Record,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if let Some(last) = flattened_lhs.last() {
|
||||||
|
last_end = last.0.end;
|
||||||
|
}
|
||||||
|
output.extend(flattened_lhs);
|
||||||
|
|
||||||
|
if let Some(first) = flattened_rhs.first() {
|
||||||
|
if first.0.start > last_end {
|
||||||
|
output.push((
|
||||||
|
Span {
|
||||||
|
start: last_end,
|
||||||
|
end: first.0.start,
|
||||||
|
},
|
||||||
|
FlatShape::Record,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(last) = flattened_rhs.last() {
|
||||||
|
last_end = last.0.end;
|
||||||
|
}
|
||||||
|
|
||||||
|
output.extend(flattened_rhs);
|
||||||
|
}
|
||||||
|
if last_end < outer_span.end {
|
||||||
|
output.push((
|
||||||
|
Span {
|
||||||
|
start: last_end,
|
||||||
|
end: outer_span.end,
|
||||||
|
},
|
||||||
|
FlatShape::Record,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
Expr::Keyword(_, span, expr) => {
|
Expr::Keyword(_, span, expr) => {
|
||||||
|
@ -2702,9 +2702,9 @@ pub fn parse_block_expression(
|
|||||||
error = error.or_else(|| Some(ParseError::Unclosed("}".into(), Span { start: end, end })));
|
error = error.or_else(|| Some(ParseError::Unclosed("}".into(), Span { start: end, end })));
|
||||||
}
|
}
|
||||||
|
|
||||||
let span = Span { start, end };
|
let inner_span = Span { start, end };
|
||||||
|
|
||||||
let source = working_set.get_span_contents(span);
|
let source = working_set.get_span_contents(inner_span);
|
||||||
|
|
||||||
let (output, err) = lex(source, start, &[], &[], true);
|
let (output, err) = lex(source, start, &[], &[], true);
|
||||||
error = error.or(err);
|
error = error.or(err);
|
||||||
@ -3365,8 +3365,8 @@ pub fn parse_record(
|
|||||||
error = error.or_else(|| Some(ParseError::Unclosed("}".into(), Span { start: end, end })));
|
error = error.or_else(|| Some(ParseError::Unclosed("}".into(), Span { start: end, end })));
|
||||||
}
|
}
|
||||||
|
|
||||||
let span = Span { start, end };
|
let inner_span = Span { start, end };
|
||||||
let source = working_set.get_span_contents(span);
|
let source = working_set.get_span_contents(inner_span);
|
||||||
|
|
||||||
let (tokens, err) = lex(source, start, &[b'\n', b'\r', b','], &[b':'], true);
|
let (tokens, err) = lex(source, start, &[b'\n', b'\r', b','], &[b':'], true);
|
||||||
error = error.or(err);
|
error = error.or(err);
|
||||||
|
Loading…
Reference in New Issue
Block a user