diff --git a/crates/nu-lsp/src/workspace.rs b/crates/nu-lsp/src/workspace.rs index 979f09a42b..dc3bb7330a 100644 --- a/crates/nu-lsp/src/workspace.rs +++ b/crates/nu-lsp/src/workspace.rs @@ -373,6 +373,8 @@ mod tests { ReferenceContext, ReferenceParams, TextDocumentIdentifier, TextDocumentPositionParams, Uri, WorkDoneProgressParams, WorkspaceFolder, }; + use nu_parser::parse; + use nu_protocol::engine::StateWorkingSet; use nu_test_support::fs::fixtures; use crate::path_to_uri; @@ -774,4 +776,31 @@ mod tests { panic!() } } + + #[test] + fn existence_of_module_block() { + let mut script_path = fixtures(); + script_path.push("lsp"); + script_path.push("workspace"); + let mut engine_state = nu_cmd_lang::create_default_context(); + engine_state.add_env_var( + "PWD".into(), + nu_protocol::Value::test_string(script_path.to_str().unwrap()), + ); + script_path.push("bar.nu"); + let mut working_set = StateWorkingSet::new(&engine_state); + parse( + &mut working_set, + script_path.to_str(), + std::fs::read(script_path.clone()).unwrap().as_slice(), + false, + ); + + script_path.pop(); + script_path.push("foo.nu"); + let span_foo = working_set + .get_span_for_filename(script_path.to_str().unwrap()) + .unwrap(); + assert!(working_set.find_block_by_span(span_foo).is_some()) + } } diff --git a/crates/nu-parser/src/parse_keywords.rs b/crates/nu-parser/src/parse_keywords.rs index 0830545075..997084569b 100644 --- a/crates/nu-parser/src/parse_keywords.rs +++ b/crates/nu-parser/src/parse_keywords.rs @@ -1742,6 +1742,7 @@ pub fn parse_module_block( let mut module = Module::from_span(module_name.to_vec(), span); let mut block = Block::new_with_capacity(output.block.len()); + block.span = Some(span); for pipeline in output.block.iter() { if pipeline.commands.len() == 1 {