From 0b71eb201c15464c7fd9583c2525bcce73e7faf9 Mon Sep 17 00:00:00 2001 From: zc he Date: Sat, 11 Jan 2025 22:03:53 +0800 Subject: [PATCH] fix(lsp): PWD env_var (#14805) # Description This PR fixes an issue introduced by #14770 , as shown in https://github.com/nushell/nushell/pull/14802#issuecomment-2585270161 # User-Facing Changes # Tests + Formatting # After Submitting --- crates/nu-lsp/src/diagnostics.rs | 24 ++++++++++++++++++++++++ crates/nu-lsp/src/lib.rs | 3 ++- tests/fixtures/lsp/diagnostics/pwd.nu | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/lsp/diagnostics/pwd.nu diff --git a/crates/nu-lsp/src/diagnostics.rs b/crates/nu-lsp/src/diagnostics.rs index b6bf751fa..cdb6a3596 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 60a214ac7..0bf83e6df 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 000000000..fed8808e2 --- /dev/null +++ b/tests/fixtures/lsp/diagnostics/pwd.nu @@ -0,0 +1 @@ +const toolkit_dir = path self .