summaryrefslogtreecommitdiff
path: root/cli/tools/doc.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-02-08 20:40:26 -0500
committerGitHub <noreply@github.com>2024-02-09 01:40:26 +0000
commite5e2c45998d3a655c4b2d78c0a1fcb61e09c1982 (patch)
tree4a3af21378652245bdd2e58cc615458d5c163c2c /cli/tools/doc.rs
parentb07a156b1d2548c07c7e822ab69d2ef9bfaca630 (diff)
fix: upgrade to deno_ast 0.33 (#22341)
* Uses diagnostics from deno_ast * Real fix for https://github.com/denoland/deno/pull/22310 * Moves `deno lint --json` code here * Upgrades swc Closes #22117 Closes #22109 Closes #21927 Closes #20993
Diffstat (limited to 'cli/tools/doc.rs')
-rw-r--r--cli/tools/doc.rs137
1 files changed, 5 insertions, 132 deletions
diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs
index 729ee05fc..d2cd0c2a2 100644
--- a/cli/tools/doc.rs
+++ b/cli/tools/doc.rs
@@ -4,24 +4,14 @@ use crate::args::DocFlags;
use crate::args::DocHtmlFlag;
use crate::args::DocSourceFileFlag;
use crate::args::Flags;
-use crate::cache::LazyGraphSourceParser;
use crate::colors;
-use crate::diagnostics::Diagnostic;
-use crate::diagnostics::DiagnosticLevel;
-use crate::diagnostics::DiagnosticLocation;
-use crate::diagnostics::DiagnosticSnippet;
-use crate::diagnostics::DiagnosticSnippetHighlight;
-use crate::diagnostics::DiagnosticSnippetHighlightStyle;
-use crate::diagnostics::DiagnosticSnippetSource;
-use crate::diagnostics::DiagnosticSourcePos;
-use crate::diagnostics::DiagnosticSourceRange;
-use crate::diagnostics::SourceTextParsedSourceStore;
use crate::display::write_json_to_stdout;
use crate::display::write_to_stdout_ignore_sigpipe;
use crate::factory::CliFactory;
use crate::graph_util::graph_lock_or_exit;
use crate::tsc::get_types_declaration_file_text;
use crate::util::fs::collect_specifiers;
+use deno_ast::diagnostics::Diagnostic;
use deno_config::glob::FilePatterns;
use deno_config::glob::PathOrPatternSet;
use deno_core::anyhow::bail;
@@ -34,10 +24,7 @@ use deno_graph::ModuleAnalyzer;
use deno_graph::ModuleParser;
use deno_graph::ModuleSpecifier;
use doc::DocDiagnostic;
-use doc::DocDiagnosticKind;
use indexmap::IndexMap;
-use lsp_types::Url;
-use std::borrow::Cow;
use std::collections::BTreeMap;
use std::rc::Rc;
@@ -143,10 +130,7 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
if doc_flags.lint {
let diagnostics = doc_parser.take_diagnostics();
- check_diagnostics(
- LazyGraphSourceParser::new(parsed_source_cache, &graph),
- &diagnostics,
- )?;
+ check_diagnostics(&diagnostics)?;
}
doc_nodes_by_url
@@ -252,6 +236,7 @@ async fn generate_docs_directory(
hide_module_doc_title: false,
href_resolver: Rc::new(DocResolver { deno_ns }),
sidebar_flatten_namespaces: false,
+ usage_composer: None,
};
let files = deno_doc::html::generate(options, doc_nodes_by_url)
@@ -308,118 +293,7 @@ fn print_docs_to_stdout(
write_to_stdout_ignore_sigpipe(details.as_bytes()).map_err(AnyError::from)
}
-impl Diagnostic for DocDiagnostic {
- fn level(&self) -> DiagnosticLevel {
- DiagnosticLevel::Error
- }
-
- fn code(&self) -> impl std::fmt::Display + '_ {
- match self.kind {
- DocDiagnosticKind::MissingJsDoc => "missing-jsdoc",
- DocDiagnosticKind::MissingExplicitType => "missing-explicit-type",
- DocDiagnosticKind::MissingReturnType => "missing-return-type",
- DocDiagnosticKind::PrivateTypeRef { .. } => "private-type-ref",
- }
- }
-
- fn message(&self) -> impl std::fmt::Display + '_ {
- match &self.kind {
- DocDiagnosticKind::MissingJsDoc => {
- Cow::Borrowed("exported symbol is missing JSDoc documentation")
- }
- DocDiagnosticKind::MissingExplicitType => {
- Cow::Borrowed("exported symbol is missing an explicit type annotation")
- }
- DocDiagnosticKind::MissingReturnType => Cow::Borrowed(
- "exported function is missing an explicit return type annotation",
- ),
- DocDiagnosticKind::PrivateTypeRef {
- reference, name, ..
- } => Cow::Owned(format!(
- "public type '{name}' references private type '{reference}'",
- )),
- }
- }
-
- fn location(&self) -> DiagnosticLocation {
- let specifier = Url::parse(&self.location.filename).unwrap();
- DiagnosticLocation::ModulePosition {
- specifier: Cow::Owned(specifier),
- source_pos: DiagnosticSourcePos::ByteIndex(self.location.byte_index),
- }
- }
-
- fn snippet(&self) -> Option<DiagnosticSnippet<'_>> {
- let specifier = Url::parse(&self.location.filename).unwrap();
- Some(DiagnosticSnippet {
- source: DiagnosticSnippetSource::Specifier(Cow::Owned(specifier)),
- highlight: DiagnosticSnippetHighlight {
- style: DiagnosticSnippetHighlightStyle::Error,
- range: DiagnosticSourceRange {
- start: DiagnosticSourcePos::ByteIndex(self.location.byte_index),
- end: DiagnosticSourcePos::ByteIndex(self.location.byte_index + 1),
- },
- description: None,
- },
- })
- }
-
- fn hint(&self) -> Option<impl std::fmt::Display + '_> {
- match &self.kind {
- DocDiagnosticKind::PrivateTypeRef { .. } => {
- Some("make the referenced type public or remove the reference")
- }
- _ => None,
- }
- }
- fn snippet_fixed(&self) -> Option<DiagnosticSnippet<'_>> {
- match &self.kind {
- DocDiagnosticKind::PrivateTypeRef {
- reference_location, ..
- } => {
- let specifier = Url::parse(&reference_location.filename).unwrap();
- Some(DiagnosticSnippet {
- source: DiagnosticSnippetSource::Specifier(Cow::Owned(specifier)),
- highlight: DiagnosticSnippetHighlight {
- style: DiagnosticSnippetHighlightStyle::Hint,
- range: DiagnosticSourceRange {
- start: DiagnosticSourcePos::ByteIndex(
- reference_location.byte_index,
- ),
- end: DiagnosticSourcePos::ByteIndex(
- reference_location.byte_index + 1,
- ),
- },
- description: Some(Cow::Borrowed("this is the referenced type")),
- },
- })
- }
- _ => None,
- }
- }
-
- fn info(&self) -> std::borrow::Cow<'_, [std::borrow::Cow<'_, str>]> {
- match &self.kind {
- DocDiagnosticKind::MissingJsDoc => Cow::Borrowed(&[]),
- DocDiagnosticKind::MissingExplicitType => Cow::Borrowed(&[]),
- DocDiagnosticKind::MissingReturnType => Cow::Borrowed(&[]),
- DocDiagnosticKind::PrivateTypeRef { .. } => {
- Cow::Borrowed(&[Cow::Borrowed(
- "to ensure documentation is complete all types that are exposed in the public API must be public",
- )])
- }
- }
- }
-
- fn docs_url(&self) -> Option<impl std::fmt::Display + '_> {
- None::<&str>
- }
-}
-
-fn check_diagnostics(
- source_parser: LazyGraphSourceParser,
- diagnostics: &[DocDiagnostic],
-) -> Result<(), AnyError> {
+fn check_diagnostics(diagnostics: &[DocDiagnostic]) -> Result<(), AnyError> {
if diagnostics.is_empty() {
return Ok(());
}
@@ -441,8 +315,7 @@ fn check_diagnostics(
for (_, diagnostics_by_col) in diagnostics_by_lc {
for (_, diagnostics) in diagnostics_by_col {
for diagnostic in diagnostics {
- let sources = SourceTextParsedSourceStore(source_parser);
- log::error!("{}", diagnostic.display(&sources));
+ log::error!("{}", diagnostic.display());
}
}
}