@@ -1497,53 +1497,7 @@ pub fn select_references_to_symbol_under_cursor(cx: &mut Context) {
1497
1497
) ;
1498
1498
}
1499
1499
1500
- pub fn pull_diagnostic_for_current_doc ( editor : & mut Editor , jobs : & mut crate :: job:: Jobs ) {
1501
- fn parse_diagnostic (
1502
- doc : & mut Document ,
1503
- offset_encoding : OffsetEncoding ,
1504
- server_id : usize ,
1505
- report : Vec < lsp:: Diagnostic > ,
1506
- result_id : Option < String > ,
1507
- ) {
1508
- let diagnostics = lsp_diagnostic_to_diagnostic (
1509
- & report,
1510
- doc. text ( ) ,
1511
- offset_encoding,
1512
- doc. language_config ( ) ,
1513
- server_id,
1514
- ) ;
1515
- doc. previous_diagnostic_id = result_id;
1516
- doc. replace_diagnostics ( diagnostics, server_id) ;
1517
- }
1518
-
1519
- fn handle_document_diagnostic_report_kind (
1520
- editor : & mut Editor ,
1521
- offset_encoding : OffsetEncoding ,
1522
- server_id : usize ,
1523
- report : Option < HashMap < lsp:: Url , lsp:: DocumentDiagnosticReportKind > > ,
1524
- ) {
1525
- for ( url, report) in report. into_iter ( ) . flatten ( ) {
1526
- let Some ( doc) = editor. document_by_path_mut ( url. path ( ) )
1527
- else {
1528
- continue ;
1529
- } ;
1530
- match report {
1531
- lsp:: DocumentDiagnosticReportKind :: Full ( report) => {
1532
- parse_diagnostic (
1533
- doc,
1534
- offset_encoding,
1535
- server_id,
1536
- report. items ,
1537
- report. result_id ,
1538
- ) ;
1539
- }
1540
- lsp:: DocumentDiagnosticReportKind :: Unchanged ( report) => {
1541
- doc. previous_diagnostic_id = Some ( report. result_id ) ;
1542
- }
1543
- }
1544
- }
1545
- }
1546
-
1500
+ pub fn pull_diagnostic_for_current_doc ( editor : & Editor , jobs : & mut crate :: job:: Jobs ) {
1547
1501
let doc = doc ! ( editor) ;
1548
1502
let Some ( language_server) = doc
1549
1503
. language_servers_with_feature ( LanguageServerFeature :: PullDiagnostics )
@@ -1584,35 +1538,63 @@ pub fn pull_diagnostic_for_current_doc(editor: &mut Editor, jobs: &mut crate::jo
1584
1538
let offset_encoding = language_server. offset_encoding ( ) ;
1585
1539
let server_id = language_server. id ( ) ;
1586
1540
1541
+ let parse_diagnostic = |editor : & mut Editor ,
1542
+ path,
1543
+ report : Vec < lsp:: Diagnostic > ,
1544
+ result_id : Option < String > | {
1545
+ if let Some ( doc) = editor. document_by_path_mut ( & path) {
1546
+ let diagnostics = lsp_diagnostic_to_diagnostic (
1547
+ & report,
1548
+ doc. text ( ) ,
1549
+ offset_encoding,
1550
+ doc. language_config ( ) ,
1551
+ server_id,
1552
+ ) ;
1553
+ doc. previous_diagnostic_id = result_id;
1554
+ doc. replace_diagnostics ( diagnostics, server_id) ;
1555
+ }
1556
+ let url = lsp:: Url :: from_file_path ( & path) . unwrap ( ) ;
1557
+ editor. add_diagnostics ( report, url, server_id) ;
1558
+ } ;
1559
+
1560
+ let handle_document_diagnostic_report_kind = |editor : & mut Editor ,
1561
+ report : Option <
1562
+ HashMap < lsp:: Url , lsp:: DocumentDiagnosticReportKind > ,
1563
+ > | {
1564
+ for ( url, report) in report. into_iter ( ) . flatten ( ) {
1565
+ match report {
1566
+ lsp:: DocumentDiagnosticReportKind :: Full ( report) => {
1567
+ let path = url. to_file_path ( ) . unwrap ( ) ;
1568
+ parse_diagnostic ( editor, path, report. items , report. result_id ) ;
1569
+ }
1570
+ lsp:: DocumentDiagnosticReportKind :: Unchanged ( report) => {
1571
+ let Some ( doc) = editor. document_by_path_mut ( url. path ( ) ) else {
1572
+ return ;
1573
+ } ;
1574
+ doc. previous_diagnostic_id = Some ( report. result_id ) ;
1575
+ }
1576
+ }
1577
+ }
1578
+ } ;
1579
+
1587
1580
if let Some ( response) = response {
1588
1581
match response {
1589
1582
lsp:: DocumentDiagnosticReport :: Full ( report) => {
1590
1583
// Original file diagnostic
1591
1584
parse_diagnostic (
1592
- doc,
1593
- offset_encoding,
1594
- server_id,
1585
+ editor,
1586
+ original_path,
1595
1587
report. full_document_diagnostic_report . items ,
1596
1588
report. full_document_diagnostic_report . result_id ,
1597
1589
) ;
1598
1590
1599
- // Related file diagnostic
1600
- handle_document_diagnostic_report_kind (
1601
- editor,
1602
- offset_encoding,
1603
- server_id,
1604
- report. related_documents ,
1605
- ) ;
1591
+ // Related files diagnostic
1592
+ handle_document_diagnostic_report_kind ( editor, report. related_documents ) ;
1606
1593
}
1607
1594
lsp:: DocumentDiagnosticReport :: Unchanged ( report) => {
1608
1595
doc. previous_diagnostic_id =
1609
1596
Some ( report. unchanged_document_diagnostic_report . result_id ) ;
1610
- handle_document_diagnostic_report_kind (
1611
- editor,
1612
- offset_encoding,
1613
- server_id,
1614
- report. related_documents ,
1615
- ) ;
1597
+ handle_document_diagnostic_report_kind ( editor, report. related_documents ) ;
1616
1598
}
1617
1599
}
1618
1600
}
0 commit comments