From a2e335dcd72ae9edc4f1d98d2855d84eaaea4817 Mon Sep 17 00:00:00 2001 From: Bahex Date: Tue, 11 Feb 2025 00:26:02 +0300 Subject: [PATCH] fix block spans for the module keyword (#15078) # Description I noticed that the following code snippet wasn't being highlighted correctly. Spans used for parsing contents of the block was also incorrectly used for the expression. # User-Facing Changes The block following the module keyword is now highlighted correctly. | Before | After | |--------|--------| | ![image](https://github.com/user-attachments/assets/8d1040f5-5002-4880-bb71-47549a67a804) | ![image](https://github.com/user-attachments/assets/0dc28e25-2da3-4411-82ae-3e4e129fd42f) | # Tests + Formatting - :green_circle: toolkit fmt - :green_circle: toolkit clippy - :green_circle: toolkit test - :green_circle: toolkit test stdlib # After Submitting N/A --- crates/nu-parser/src/parse_keywords.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/crates/nu-parser/src/parse_keywords.rs b/crates/nu-parser/src/parse_keywords.rs index 057443c141..cbd26e1a1f 100644 --- a/crates/nu-parser/src/parse_keywords.rs +++ b/crates/nu-parser/src/parse_keywords.rs @@ -2227,15 +2227,15 @@ pub fn parse_module( let module_name = module_name_or_path; - let block_span = spans[split_id + 1]; - let block_bytes = working_set.get_span_contents(block_span); - let mut start = block_span.start; - let mut end = block_span.end; + let block_expr_span = spans[split_id + 1]; + let block_bytes = working_set.get_span_contents(block_expr_span); + let mut start = block_expr_span.start; + let mut end = block_expr_span.end; if block_bytes.starts_with(b"{") { start += 1; } else { - working_set.error(ParseError::Expected("block", block_span)); + working_set.error(ParseError::Expected("block", block_expr_span)); return (garbage_pipeline(working_set, spans), None); } @@ -2245,17 +2245,22 @@ pub fn parse_module( working_set.error(ParseError::Unclosed("}".into(), Span::new(end, end))); } - let block_span = Span::new(start, end); + let block_content_span = Span::new(start, end); let (block, module, inner_comments) = - parse_module_block(working_set, block_span, module_name.as_bytes()); + parse_module_block(working_set, block_content_span, module_name.as_bytes()); let block_id = working_set.add_block(Arc::new(block)); module_comments.extend(inner_comments); let module_id = working_set.add_module(&module_name, module, module_comments); - let block_expr = Expression::new(working_set, Expr::Block(block_id), block_span, Type::Any); + let block_expr = Expression::new( + working_set, + Expr::Block(block_id), + block_expr_span, + Type::Any, + ); let module_decl_id = working_set .find_decl(b"module")