diff options
Diffstat (limited to 'cli/lsp')
-rw-r--r-- | cli/lsp/diagnostics.rs | 14 | ||||
-rw-r--r-- | cli/lsp/language_server.rs | 11 | ||||
-rw-r--r-- | cli/lsp/tsc.rs | 93 |
3 files changed, 79 insertions, 39 deletions
diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index c468fb0fa..ac938d063 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -244,20 +244,10 @@ pub async fn generate_ts_diagnostics( let version = doc_data.version; let current_version = diagnostic_collection.get_version(&file_id); if version != current_version { - // TODO(@kitsonk): consider refactoring to get all diagnostics in one shot - // for a file. - let req = tsc::RequestMethod::GetSemanticDiagnostics(specifier.clone()); - let mut ts_diagnostics = ts_json_to_diagnostics( + let req = tsc::RequestMethod::GetDiagnostics(specifier.clone()); + let ts_diagnostics = ts_json_to_diagnostics( ts_server.request(state_snapshot.clone(), req).await?, )?; - let req = tsc::RequestMethod::GetSuggestionDiagnostics(specifier.clone()); - ts_diagnostics.append(&mut ts_json_to_diagnostics( - ts_server.request(state_snapshot.clone(), req).await?, - )?); - let req = tsc::RequestMethod::GetSyntacticDiagnostics(specifier.clone()); - ts_diagnostics.append(&mut ts_json_to_diagnostics( - ts_server.request(state_snapshot.clone(), req).await?, - )?); diagnostics.push((file_id, version, ts_diagnostics)); } } diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 9591f246a..e70c0198d 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -154,12 +154,19 @@ impl LanguageServer { if enabled { let diagnostics = { let diagnostic_collection = self.diagnostics.read().unwrap().clone(); - diagnostics::generate_ts_diagnostics( + match diagnostics::generate_ts_diagnostics( &self.ts_server, &diagnostic_collection, self.snapshot(), ) - .await? + .await + { + Ok(diagnostics) => diagnostics, + Err(err) => { + error!("Error processing TypeScript diagnostics:\n{}", err); + vec![] + } + } }; { let mut diagnostics_collection = self.diagnostics.write().unwrap(); diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index fde3e37b9..9de7ddcac 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -1123,12 +1123,8 @@ pub enum RequestMethod { Configure(TsConfig), /// Retrieve the text of an assets that exists in memory in the isolate. GetAsset(ModuleSpecifier), - /// Return semantic diagnostics for given file. - GetSemanticDiagnostics(ModuleSpecifier), - /// Returns suggestion diagnostics for given file. - GetSuggestionDiagnostics(ModuleSpecifier), - /// Return syntactic diagnostics for a given file. - GetSyntacticDiagnostics(ModuleSpecifier), + /// Return diagnostics for given file. + GetDiagnostics(ModuleSpecifier), /// Return quick info at position (hover information). GetQuickInfo((ModuleSpecifier, u32)), /// Return document highlights at position. @@ -1156,19 +1152,9 @@ impl RequestMethod { "method": "getAsset", "specifier": specifier, }), - RequestMethod::GetSemanticDiagnostics(specifier) => json!({ + RequestMethod::GetDiagnostics(specifier) => json!({ "id": id, - "method": "getSemanticDiagnostics", - "specifier": specifier, - }), - RequestMethod::GetSuggestionDiagnostics(specifier) => json!({ - "id": id, - "method": "getSuggestionDiagnostics", - "specifier": specifier, - }), - RequestMethod::GetSyntacticDiagnostics(specifier) => json!({ - "id": id, - "method": "getSyntacticDiagnostics", + "method": "getDiagnostics", "specifier": specifier, }), RequestMethod::GetQuickInfo((specifier, position)) => json!({ @@ -1369,7 +1355,7 @@ mod tests { } #[test] - fn test_get_semantic_diagnostics() { + fn test_get_diagnostics() { let (mut runtime, state_snapshot) = setup( false, json!({ @@ -1384,7 +1370,7 @@ mod tests { let result = request( &mut runtime, state_snapshot, - RequestMethod::GetSemanticDiagnostics(specifier), + RequestMethod::GetDiagnostics(specifier), ); assert!(result.is_ok()); let response = result.unwrap(); @@ -1437,7 +1423,7 @@ mod tests { let result = request( &mut runtime, state_snapshot, - RequestMethod::GetSemanticDiagnostics(specifier), + RequestMethod::GetDiagnostics(specifier), ); assert!(result.is_ok()); let response = result.unwrap(); @@ -1467,11 +1453,29 @@ mod tests { let result = request( &mut runtime, state_snapshot, - RequestMethod::GetSyntacticDiagnostics(specifier), + RequestMethod::GetDiagnostics(specifier), ); assert!(result.is_ok()); let response = result.unwrap(); - assert_eq!(response, json!([])); + assert_eq!( + response, + json!([{ + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 30 + }, + "fileName": "file:///a.ts", + "messageText": "\'A\' is declared but its value is never read.", + "sourceLine": " import { A } from \".\";", + "category": 2, + "code": 6133, + "reportsUnnecessary": true, + }]) + ); } #[test] @@ -1501,7 +1505,7 @@ mod tests { let result = request( &mut runtime, state_snapshot, - RequestMethod::GetSyntacticDiagnostics(specifier), + RequestMethod::GetDiagnostics(specifier), ); assert!(result.is_ok()); let response = result.unwrap(); @@ -1538,7 +1542,7 @@ mod tests { let result = request( &mut runtime, state_snapshot, - RequestMethod::GetSyntacticDiagnostics(specifier), + RequestMethod::GetDiagnostics(specifier), ); assert!(result.is_ok()); let response = result.unwrap(); @@ -1546,6 +1550,21 @@ mod tests { response, json!([{ "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 6, + "character": 55, + }, + "fileName": "file:///a.ts", + "messageText": "All imports in import declaration are unused.", + "sourceLine": " import {", + "category": 2, + "code": 6192, + "reportsUnnecessary": true + }, { + "start": { "line": 8, "character": 29 }, @@ -1563,6 +1582,30 @@ mod tests { } #[test] + fn test_no_debug_failure() { + let (mut runtime, state_snapshot) = setup( + false, + json!({ + "target": "esnext", + "module": "esnext", + "lib": ["deno.ns", "deno.window"], + "noEmit": true, + }), + vec![("file:///a.ts", r#"const url = new URL("b.js", import."#, 1)], + ); + let specifier = ModuleSpecifier::resolve_url("file:///a.ts") + .expect("could not resolve url"); + let result = request( + &mut runtime, + state_snapshot, + RequestMethod::GetDiagnostics(specifier), + ); + assert!(result.is_ok()); + let response = result.unwrap(); + assert_eq!(response, json!([])); + } + + #[test] fn test_request_asset() { let (mut runtime, state_snapshot) = setup( false, |