diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index 47b26d92ea..33705dbff0 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -11,6 +11,7 @@ use crate::tokio_util::create_basic_runtime; use deno_core::error::anyhow; use deno_core::error::AnyError; use deno_core::resolve_url; +use deno_core::serde_json::json; use deno_core::ModuleSpecifier; use log::error; use lspower::lsp; @@ -446,6 +447,7 @@ async fn generate_deps_diagnostics( code, source: Some("deno".to_string()), message, + data: Some(json!({ "specifier": specifier })), ..Default::default() }); } else if sources.contains_key(&specifier) { diff --git a/cli/tests/integration_tests_lsp.rs b/cli/tests/integration_tests_lsp.rs index d08da622f5..ad41afadaf 100644 --- a/cli/tests/integration_tests_lsp.rs +++ b/cli/tests/integration_tests_lsp.rs @@ -1362,17 +1362,24 @@ fn lsp_code_actions() { #[test] fn lsp_code_actions_deno_cache() { let mut client = init("initialize_params.json"); - did_open( - &mut client, - json!({ + client + .write_notification("textDocument/didOpen", json!({ "textDocument": { "uri": "file:///a/file.ts", "languageId": "typescript", "version": 1, "text": "import * as a from \"https://deno.land/x/a/mod.ts\";\n\nconsole.log(a);\n" } - }), - ); + })) + .unwrap(); + let (method, _) = client.read_notification::().unwrap(); + assert_eq!(method, "textDocument/publishDiagnostics"); + let (method, _) = client.read_notification::().unwrap(); + assert_eq!(method, "textDocument/publishDiagnostics"); + let (method, params) = client.read_notification().unwrap(); + assert_eq!(method, "textDocument/publishDiagnostics"); + assert_eq!(params, Some(load_fixture("diagnostics_deno_deps.json"))); + let (maybe_res, maybe_err) = client .write_request( "textDocument/codeAction", diff --git a/cli/tests/lsp/diagnostics_deno_deps.json b/cli/tests/lsp/diagnostics_deno_deps.json new file mode 100644 index 0000000000..ec6cc4f516 --- /dev/null +++ b/cli/tests/lsp/diagnostics_deno_deps.json @@ -0,0 +1,25 @@ +{ + "uri": "file:///a/file.ts", + "diagnostics": [ + { + "range": { + "start": { + "line": 0, + "character": 19 + }, + "end": { + "line": 0, + "character": 49 + } + }, + "severity": 1, + "code": "no-cache", + "source": "deno", + "message": "Uncached or missing remote URL: \"https://deno.land/x/a/mod.ts\".", + "data": { + "specifier": "https://deno.land/x/a/mod.ts" + } + } + ], + "version": 1 +}