mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 12:49:10 +00:00
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
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:
parent
61a7913a8b
commit
3b59689df6
2 changed files with 52 additions and 1 deletions
|
@ -1576,7 +1576,7 @@ fn diagnose_resolution(
|
||||||
if module.media_type == MediaType::Json {
|
if module.media_type == MediaType::Json {
|
||||||
match maybe_assert_type {
|
match maybe_assert_type {
|
||||||
// The module has the correct assertion type, no diagnostic
|
// 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
|
// The dynamic import statement is missing an attribute type, which
|
||||||
// we might not be able to statically detect, therefore we will
|
// we might not be able to statically detect, therefore we will
|
||||||
// not provide a potentially incorrect diagnostic.
|
// not provide a potentially incorrect diagnostic.
|
||||||
|
|
|
@ -18902,3 +18902,54 @@ fn do_not_auto_import_from_definitely_typed() {
|
||||||
client.shutdown();
|
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."
|
||||||
|
}])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue