summaryrefslogtreecommitdiff
path: root/cli/lsp/diagnostics.rs
diff options
context:
space:
mode:
authorHajime-san <41257923+Hajime-san@users.noreply.github.com>2024-03-28 00:58:18 +0900
committerGitHub <noreply@github.com>2024-03-27 15:58:18 +0000
commitfeb744cebd37263026893c7e7c4852daa5df24d0 (patch)
tree99f8da702a85406acec872494a760c538025354e /cli/lsp/diagnostics.rs
parent3462248571fd3193106a0427b3d8f585f9716c48 (diff)
fix(lsp): decoding percent-encoding(non-ASCII) file path correctly (#22582)
Diffstat (limited to 'cli/lsp/diagnostics.rs')
-rw-r--r--cli/lsp/diagnostics.rs51
1 files changed, 49 insertions, 2 deletions
diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs
index e3b922ba8..03d962741 100644
--- a/cli/lsp/diagnostics.rs
+++ b/cli/lsp/diagnostics.rs
@@ -21,6 +21,7 @@ use crate::graph_util::enhanced_resolution_error_message;
use crate::lsp::lsp_custom::DiagnosticBatchNotificationParams;
use crate::resolver::SloppyImportsResolution;
use crate::resolver::SloppyImportsResolver;
+use crate::util::path::to_percent_decoded_str;
use deno_ast::MediaType;
use deno_core::anyhow::anyhow;
@@ -1212,8 +1213,10 @@ impl DenoDiagnostic {
specifier: &ModuleSpecifier,
sloppy_resolution: SloppyImportsResolution,
) -> String {
- let mut message =
- format!("Unable to load a local module: {}\n", specifier);
+ let mut message = format!(
+ "Unable to load a local module: {}\n",
+ to_percent_decoded_str(specifier.as_ref())
+ );
if let Some(additional_message) =
sloppy_resolution.as_suggestion_message()
{
@@ -1971,6 +1974,50 @@ let c: number = "a";
);
}
+ #[tokio::test]
+ async fn unable_to_load_a_local_module() {
+ let temp_dir = TempDir::new();
+ let (snapshot, _) = setup(
+ &temp_dir,
+ &[(
+ "file:///a.ts",
+ r#"
+ import { 東京 } from "./🦕.ts";
+ "#,
+ 1,
+ LanguageId::TypeScript,
+ )],
+ None,
+ )
+ .await;
+ let config = mock_config();
+ let token = CancellationToken::new();
+ let actual = generate_deno_diagnostics(&snapshot, &config, token);
+ assert_eq!(actual.len(), 1);
+ let record = actual.first().unwrap();
+ assert_eq!(
+ json!(record.versioned.diagnostics),
+ json!([
+ {
+ "range": {
+ "start": {
+ "line": 1,
+ "character": 27
+ },
+ "end": {
+ "line": 1,
+ "character": 35
+ }
+ },
+ "severity": 1,
+ "code": "no-local",
+ "source": "deno",
+ "message": "Unable to load a local module: file:///🦕.ts\nPlease check the file path.",
+ }
+ ])
+ );
+ }
+
#[test]
fn test_specifier_text_for_redirected() {
#[track_caller]