diff --git a/crates/nu-lsp/src/diagnostics.rs b/crates/nu-lsp/src/diagnostics.rs index b6bf751fa5..cdb6a35962 100644 --- a/crates/nu-lsp/src/diagnostics.rs +++ b/crates/nu-lsp/src/diagnostics.rs @@ -118,4 +118,28 @@ mod tests { }) ); } + + #[test] + fn publish_diagnostics_none() { + let (client_connection, _recv) = initialize_language_server(); + + let mut script = fixtures(); + script.push("lsp"); + script.push("diagnostics"); + script.push("pwd.nu"); + let script = path_to_uri(&script); + + let notification = open_unchecked(&client_connection, script.clone()); + + assert_json_eq!( + notification, + serde_json::json!({ + "method": "textDocument/publishDiagnostics", + "params": { + "uri": script, + "diagnostics": [] + } + }) + ); + } } diff --git a/crates/nu-lsp/src/lib.rs b/crates/nu-lsp/src/lib.rs index 60a214ac7a..0bf83e6dfe 100644 --- a/crates/nu-lsp/src/lib.rs +++ b/crates/nu-lsp/src/lib.rs @@ -189,7 +189,8 @@ impl LanguageServer { pub fn new_engine_state(&self) -> EngineState { let mut engine_state = self.engine_state.clone(); - engine_state.add_env_var("PWD".into(), Value::test_string(".")); + let cwd = std::env::current_dir().expect("Could not get current working directory."); + engine_state.add_env_var("PWD".into(), Value::test_string(cwd.to_string_lossy())); engine_state } diff --git a/tests/fixtures/lsp/diagnostics/pwd.nu b/tests/fixtures/lsp/diagnostics/pwd.nu new file mode 100644 index 0000000000..fed8808e22 --- /dev/null +++ b/tests/fixtures/lsp/diagnostics/pwd.nu @@ -0,0 +1 @@ +const toolkit_dir = path self .