diff options
Diffstat (limited to 'cli/lsp/diagnostics.rs')
-rw-r--r-- | cli/lsp/diagnostics.rs | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index 0bee08c1d..fd4142fd9 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -871,9 +871,9 @@ pub enum DenoDiagnostic { /// remapped to an import map import specifier. ImportMapRemap { from: String, to: String }, /// The import assertion type is incorrect. - InvalidAssertType(String), - /// A module requires an assertion type to be a valid import. - NoAssertType, + InvalidAttributeType(String), + /// A module requires an attribute type to be a valid import. + NoAttributeType, /// A remote module was not found in the cache. NoCache(ModuleSpecifier), /// A remote npm package reference was not found in the cache. @@ -897,8 +897,8 @@ impl DenoDiagnostic { match self { Self::DenoWarn(_) => "deno-warn", Self::ImportMapRemap { .. } => "import-map-remap", - Self::InvalidAssertType(_) => "invalid-assert-type", - Self::NoAssertType => "no-assert-type", + Self::InvalidAttributeType(_) => "invalid-attribute-type", + Self::NoAttributeType => "no-attribute-type", Self::NoCache(_) => "no-cache", Self::NoCacheNpm(_, _) => "no-cache-npm", Self::NoLocal(_) => "no-local", @@ -958,15 +958,15 @@ impl DenoDiagnostic { ..Default::default() } } - "no-assert-type" => lsp::CodeAction { - title: "Insert import assertion.".to_string(), + "no-attribute-type" => lsp::CodeAction { + title: "Insert import attribute.".to_string(), kind: Some(lsp::CodeActionKind::QUICKFIX), diagnostics: Some(vec![diagnostic.clone()]), edit: Some(lsp::WorkspaceEdit { changes: Some(HashMap::from([( specifier.clone(), vec![lsp::TextEdit { - new_text: " assert { type: \"json\" }".to_string(), + new_text: " with { type: \"json\" }".to_string(), range: lsp::Range { start: diagnostic.range.end, end: diagnostic.range.end, @@ -1069,7 +1069,7 @@ impl DenoDiagnostic { "import-map-remap" | "no-cache" | "no-cache-npm" - | "no-assert-type" + | "no-attribute-type" | "redirect" | "import-node-prefix-missing" ) @@ -1084,8 +1084,8 @@ impl DenoDiagnostic { let (severity, message, data) = match self { Self::DenoWarn(message) => (lsp::DiagnosticSeverity::WARNING, message.to_string(), None), Self::ImportMapRemap { from, to } => (lsp::DiagnosticSeverity::HINT, format!("The import specifier can be remapped to \"{to}\" which will resolve it via the active import map."), Some(json!({ "from": from, "to": to }))), - Self::InvalidAssertType(assert_type) => (lsp::DiagnosticSeverity::ERROR, format!("The module is a JSON module and expected an assertion type of \"json\". Instead got \"{assert_type}\"."), None), - Self::NoAssertType => (lsp::DiagnosticSeverity::ERROR, "The module is a JSON module and not being imported with an import assertion. Consider adding `assert { type: \"json\" }` to the import statement.".to_string(), None), + Self::InvalidAttributeType(assert_type) => (lsp::DiagnosticSeverity::ERROR, format!("The module is a JSON module and expected an attribute type of \"json\". Instead got \"{assert_type}\"."), None), + Self::NoAttributeType => (lsp::DiagnosticSeverity::ERROR, "The module is a JSON module and not being imported with an import attribute. Consider adding `with { type: \"json\" }` to the import statement.".to_string(), None), Self::NoCache(specifier) => (lsp::DiagnosticSeverity::ERROR, format!("Uncached or missing remote URL: {specifier}"), Some(json!({ "specifier": specifier }))), Self::NoCacheNpm(pkg_req, specifier) => (lsp::DiagnosticSeverity::ERROR, format!("Uncached or missing npm package: {}", pkg_req), Some(json!({ "specifier": specifier }))), Self::NoLocal(specifier) => (lsp::DiagnosticSeverity::ERROR, format!("Unable to load a local module: {specifier}\n Please check the file path."), None), @@ -1144,15 +1144,16 @@ fn diagnose_resolution( match maybe_assert_type { // The module has the correct assertion type, no diagnostic Some("json") => (), - // The dynamic import statement is missing an assertion type, which + // 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. None if is_dynamic => (), // The module has an incorrect assertion type, diagnostic - Some(assert_type) => diagnostics - .push(DenoDiagnostic::InvalidAssertType(assert_type.to_string())), - // The module is missing an assertion type, diagnostic - None => diagnostics.push(DenoDiagnostic::NoAssertType), + Some(assert_type) => diagnostics.push( + DenoDiagnostic::InvalidAttributeType(assert_type.to_string()), + ), + // The module is missing an attribute type, diagnostic + None => diagnostics.push(DenoDiagnostic::NoAttributeType), } } } else if let Ok(pkg_ref) = @@ -1249,7 +1250,7 @@ fn diagnose_dependency( &dependency.maybe_code }, dependency.is_dynamic, - dependency.maybe_assert_type.as_deref(), + dependency.maybe_attribute_type.as_deref(), ) .iter() .flat_map(|diag| { @@ -1278,7 +1279,7 @@ fn diagnose_dependency( snapshot, &dependency.maybe_type, dependency.is_dynamic, - dependency.maybe_assert_type.as_deref(), + dependency.maybe_attribute_type.as_deref(), ) .iter() .map(|diag| diag.to_lsp_diagnostic(&range)), |