summaryrefslogtreecommitdiff
path: root/cli/lsp/analysis.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/lsp/analysis.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/lsp/analysis.rs')
-rw-r--r--cli/lsp/analysis.rs49
1 files changed, 13 insertions, 36 deletions
diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs
index 6c6d7cab4..96ee422c6 100644
--- a/cli/lsp/analysis.rs
+++ b/cli/lsp/analysis.rs
@@ -20,6 +20,7 @@ use deno_core::serde::Deserialize;
use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::ModuleSpecifier;
+use deno_lint::diagnostic::LintDiagnostic;
use deno_lint::rules::LintRule;
use deno_runtime::deno_node::NodeResolver;
use deno_runtime::deno_node::NpmResolver;
@@ -118,15 +119,21 @@ impl Reference {
}
}
-fn as_lsp_range(range: &deno_lint::diagnostic::Range) -> Range {
+fn as_lsp_range(diagnostic: &LintDiagnostic) -> Range {
+ let start_lc = diagnostic
+ .text_info
+ .line_and_column_index(diagnostic.range.start);
+ let end_lc = diagnostic
+ .text_info
+ .line_and_column_index(diagnostic.range.end);
Range {
start: Position {
- line: range.start.line_index as u32,
- character: range.start.column_index as u32,
+ line: start_lc.line_index as u32,
+ character: start_lc.column_index as u32,
},
end: Position {
- line: range.end.line_index as u32,
- character: range.end.column_index as u32,
+ line: end_lc.line_index as u32,
+ character: end_lc.column_index as u32,
},
}
}
@@ -142,12 +149,12 @@ pub fn get_lint_references(
lint_diagnostics
.into_iter()
.map(|d| Reference {
+ range: as_lsp_range(&d),
category: Category::Lint {
message: d.message,
code: d.code,
hint: d.hint,
},
- range: as_lsp_range(&d.range),
})
.collect(),
)
@@ -1061,36 +1068,6 @@ mod tests {
}
#[test]
- fn test_as_lsp_range() {
- let fixture = deno_lint::diagnostic::Range {
- start: deno_lint::diagnostic::Position {
- line_index: 0,
- column_index: 2,
- byte_index: 23,
- },
- end: deno_lint::diagnostic::Position {
- line_index: 1,
- column_index: 0,
- byte_index: 33,
- },
- };
- let actual = as_lsp_range(&fixture);
- assert_eq!(
- actual,
- lsp::Range {
- start: lsp::Position {
- line: 0,
- character: 2,
- },
- end: lsp::Position {
- line: 1,
- character: 0,
- },
- }
- );
- }
-
- #[test]
fn test_try_reverse_map_package_json_exports() {
let exports = json!({
".": {