diff --git a/newtests/lsp/detailed_diagnostics/test.js b/newtests/lsp/detailed_diagnostics/test.js index e76ecc81b66..3f45b68cfc0 100644 --- a/newtests/lsp/detailed_diagnostics/test.js +++ b/newtests/lsp/detailed_diagnostics/test.js @@ -4,6 +4,7 @@ */ import type {SuiteType} from '../../Tester'; +const {readFileSync} = require('fs'); const {join} = require('path'); const {suite, test} = require('../../Tester'); @@ -24,6 +25,25 @@ module.exports = (suite( initializationOptions: {detailedErrorRendering: true}, }), addFile('file_with_simple_error.js') + .waitUntilLSPMessage( + 9000, + 'textDocument/publishDiagnostics', + '{Cannot assign}', + ) + .verifyLSPMessageSnapshot( + join(__dirname, '__snapshots__', 'no-detailed-errors.json'), + ['window/showStatus', '$/cancelRequest'], + ), + lspNotification('textDocument/didOpen', { + textDocument: { + uri: '/file_with_simple_error.js', + languageId: 'javascript', + version: 1, + text: readFileSync( + join(__dirname, 'file_with_simple_error.js'), + ).toString(), + }, + }) .waitUntilLSPMessage( 9000, 'textDocument/publishDiagnostics', diff --git a/src/common/flow_lsp_conversions.ml b/src/common/flow_lsp_conversions.ml index bb295fa68d6..33c2c577757 100644 --- a/src/common/flow_lsp_conversions.ml +++ b/src/common/flow_lsp_conversions.ml @@ -234,7 +234,7 @@ let position_of_document_position { Lsp.TextDocumentPositionParams.position; _ } let diagnostics_of_flow_errors = let error_to_lsp ~unsaved_content - ~vscode_detailed_diagnostics + ~should_include_vscode_detailed_diagnostics ~(severity : Severity.severity) (printable_error : Loc.t Flow_errors_utils.printable_error) : (Lsp.DocumentUri.t * Lsp.PublishDiagnostics.diagnostic) option = @@ -253,7 +253,7 @@ let diagnostics_of_flow_errors = ~f:related_to_lsp in let data = - if vscode_detailed_diagnostics then + if should_include_vscode_detailed_diagnostics printable_error then let map_color = function | Tty.Default -> Lsp.PublishDiagnostics.ExtraDetailedDiagnosticV0.Default | Tty.Black -> Lsp.PublishDiagnostics.ExtraDetailedDiagnosticV0.Black @@ -306,9 +306,11 @@ let diagnostics_of_flow_errors = ) | Error _ -> None in - fun ~unsaved_content ~vscode_detailed_diagnostics ~errors ~warnings -> + fun ~unsaved_content ~should_include_vscode_detailed_diagnostics ~errors ~warnings -> let add severity error acc = - match error_to_lsp ~unsaved_content ~vscode_detailed_diagnostics ~severity error with + match + error_to_lsp ~unsaved_content ~should_include_vscode_detailed_diagnostics ~severity error + with | Some (uri, diagnostic) -> Lsp.UriMap.add ~combine:List.append uri [diagnostic] acc | None -> acc in diff --git a/src/server/command_handler/commandHandler.ml b/src/server/command_handler/commandHandler.ml index 0803370cbe4..d08ee86bc2e 100644 --- a/src/server/command_handler/commandHandler.ml +++ b/src/server/command_handler/commandHandler.ml @@ -3601,7 +3601,8 @@ let handle_live_errors_request = let live_diagnostics = Flow_lsp_conversions.diagnostics_of_flow_errors ~unsaved_content:(Some (File_path.make file_path, content)) - ~vscode_detailed_diagnostics:(vscode_detailed_diagnostics client) + ~should_include_vscode_detailed_diagnostics: + (Base.Fn.const (vscode_detailed_diagnostics client)) ~errors:live_errors ~warnings:live_warnings |> Lsp.UriMap.find_opt live_errors_uri diff --git a/src/server/persistent_connection/persistent_connection.ml b/src/server/persistent_connection/persistent_connection.ml index 9184dcb6f50..ccb36ea4902 100644 --- a/src/server/persistent_connection/persistent_connection.ml +++ b/src/server/persistent_connection/persistent_connection.ml @@ -108,10 +108,20 @@ let send_errors = Lsp.Initialize.(client.lsp_initialize_params.initializationOptions.detailedErrorRendering) ~default:false in + let should_include_vscode_detailed_diagnostics = + if vscode_detailed_diagnostics then + fun error -> + let open Flow_errors_utils in + match loc_of_printable_error error |> Loc.source with + | None -> false + | Some source -> SMap.mem (File_key.to_string source) client.opened_files + else + Base.Fn.const false + in let diagnostics = Flow_lsp_conversions.diagnostics_of_flow_errors ~unsaved_content:None - ~vscode_detailed_diagnostics + ~should_include_vscode_detailed_diagnostics ~errors ~warnings in