fix(lsp): do not error for bytes or text import of json module (#30137)
Some checks are pending
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / build libs (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions

Closes https://github.com/denoland/deno/issues/30101
This commit is contained in:
David Sherret 2025-07-17 19:09:16 -04:00 committed by GitHub
parent 61a7913a8b
commit 3b59689df6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 52 additions and 1 deletions

View file

@ -1576,7 +1576,7 @@ fn diagnose_resolution(
if module.media_type == MediaType::Json {
match maybe_assert_type {
// The module has the correct assertion type, no diagnostic
Some("json") => (),
Some("json" | "text" | "bytes") => (),
// The dynamic import statement is missing an attribute type, which
// we might not be able to statically detect, therefore we will
// not provide a potentially incorrect diagnostic.

View file

@ -18902,3 +18902,54 @@ fn do_not_auto_import_from_definitely_typed() {
client.shutdown();
}
}
#[test]
#[timeout(300_000)]
fn lsp_import_json_module_import_attribute_variations() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let temp_dir = context.temp_dir().path();
temp_dir.join("deno.json").write_json(&json!({
"unstable": ["raw-imports"]
}));
temp_dir.join("file.json").write_json(&json!({}));
let mut client = context.new_lsp_command().build();
client.initialize_default();
for type_text in ["bytes", "text", "json"] {
let diagnostics = client.did_open(json!({
"textDocument": {
"uri": temp_dir.join(format!("{}.ts", type_text)).uri_file(),
"languageId": "typescript",
"version": 1,
"text": format!("import data from './file.json' with {{ type: '{}' }};\nconsole.log(data);\n", type_text)
}
}));
assert_eq!(json!(diagnostics.all()), json!([]));
}
let diagnostics = client.did_open(json!({
"textDocument": {
"uri": temp_dir.join("missing.ts").uri_file(),
"languageId": "typescript",
"version": 1,
"text": "import data from './file.json';\nconsole.log(data);\n",
}
}));
assert_eq!(
json!(diagnostics.all()),
json!([{
"range": {
"start": {
"line": 0,
"character": 17,
},
"end": {
"line": 0,
"character": 30,
},
},
"severity": 1,
"code": "no-attribute-type",
"source": "deno",
"message": "The module is a JSON module and not being imported with an import attribute. Consider adding `with { type: \"json\" }` to the import statement."
}])
);
}