diff options
Diffstat (limited to 'cli/lsp')
-rw-r--r-- | cli/lsp/analysis.rs | 49 | ||||
-rw-r--r-- | cli/lsp/code_lens.rs | 2 | ||||
-rw-r--r-- | cli/lsp/documents.rs | 8 | ||||
-rw-r--r-- | cli/lsp/testing/collectors.rs | 2 |
4 files changed, 19 insertions, 42 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!({ ".": { diff --git a/cli/lsp/code_lens.rs b/cli/lsp/code_lens.rs index adf1d5c63..59787dd84 100644 --- a/cli/lsp/code_lens.rs +++ b/cli/lsp/code_lens.rs @@ -560,7 +560,7 @@ mod tests { Deno.test(`test template literal name`, () => {}); "#; let parsed_module = deno_ast::parse_module(deno_ast::ParseParams { - specifier: specifier.to_string(), + specifier: specifier.clone(), text_info: SourceTextInfo::new(source.into()), media_type: MediaType::TypeScript, capture_tokens: true, diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index c758d341b..94d0e979b 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -246,7 +246,7 @@ impl AssetOrDocument { pub fn maybe_parsed_source( &self, - ) -> Option<Result<deno_ast::ParsedSource, deno_ast::Diagnostic>> { + ) -> Option<Result<deno_ast::ParsedSource, deno_ast::ParseDiagnostic>> { self.document().and_then(|d| d.maybe_parsed_source()) } @@ -283,7 +283,7 @@ impl DocumentDependencies { } type ModuleResult = Result<deno_graph::JsModule, deno_graph::ModuleGraphError>; -type ParsedSourceResult = Result<ParsedSource, deno_ast::Diagnostic>; +type ParsedSourceResult = Result<ParsedSource, deno_ast::ParseDiagnostic>; #[derive(Debug)] struct DocumentInner { @@ -595,7 +595,7 @@ impl Document { pub fn maybe_parsed_source( &self, - ) -> Option<Result<deno_ast::ParsedSource, deno_ast::Diagnostic>> { + ) -> Option<Result<deno_ast::ParsedSource, deno_ast::ParseDiagnostic>> { self.0.maybe_parsed_source.clone() } @@ -1855,7 +1855,7 @@ fn parse_source( maybe_headers: Option<&HashMap<String, String>>, ) -> ParsedSourceResult { deno_ast::parse_module(deno_ast::ParseParams { - specifier: specifier.to_string(), + specifier: specifier.clone(), text_info, media_type: MediaType::from_specifier_and_headers(specifier, maybe_headers), capture_tokens: true, diff --git a/cli/lsp/testing/collectors.rs b/cli/lsp/testing/collectors.rs index a66e56948..8579ccc7d 100644 --- a/cli/lsp/testing/collectors.rs +++ b/cli/lsp/testing/collectors.rs @@ -644,7 +644,7 @@ pub mod tests { let specifier = resolve_url("file:///a/example.ts").unwrap(); let parsed_module = deno_ast::parse_module(deno_ast::ParseParams { - specifier: specifier.to_string(), + specifier: specifier.clone(), text_info: deno_ast::SourceTextInfo::new(source.into()), media_type: deno_ast::MediaType::TypeScript, capture_tokens: true, |