@@ -41,11 +41,11 @@ use crate::{
41
41
42
42
use std:: {
43
43
cmp:: Ordering ,
44
- collections:: { BTreeMap , HashSet } ,
44
+ collections:: { BTreeMap , HashMap , HashSet } ,
45
45
fmt:: Write ,
46
46
future:: Future ,
47
47
path:: PathBuf ,
48
- sync:: Arc ,
48
+ sync:: { atomic , Arc } ,
49
49
} ;
50
50
51
51
/// Gets the first language server that is attached to a document which supports a specific feature.
@@ -1498,17 +1498,13 @@ pub fn select_references_to_symbol_under_cursor(cx: &mut Context) {
1498
1498
}
1499
1499
1500
1500
pub fn pull_diagnostic_for_current_doc ( editor : & mut Editor , jobs : & mut crate :: job:: Jobs ) {
1501
- fn parse_diagnostic < P : AsRef < std:: path:: Path > > (
1502
- editor : & mut Editor ,
1503
- path : P ,
1501
+ fn parse_diagnostic (
1502
+ doc : & mut Document ,
1504
1503
offset_encoding : OffsetEncoding ,
1505
1504
server_id : usize ,
1506
1505
report : Vec < lsp:: Diagnostic > ,
1507
1506
result_id : Option < String > ,
1508
1507
) {
1509
- let Some ( doc) = editor. document_by_path_mut ( path) else {
1510
- return ;
1511
- } ;
1512
1508
let diagnostics = lsp_diagnostic_to_diagnostic (
1513
1509
& report,
1514
1510
doc. text ( ) ,
@@ -1520,14 +1516,49 @@ pub fn pull_diagnostic_for_current_doc(editor: &mut Editor, jobs: &mut crate::jo
1520
1516
doc. replace_diagnostics ( diagnostics, server_id) ;
1521
1517
}
1522
1518
1523
- let doc = doc ! ( editor) ;
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
+ }
1524
1546
1547
+ let doc = doc ! ( editor) ;
1525
1548
let Some ( language_server) = doc
1526
1549
. language_servers_with_feature ( LanguageServerFeature :: PullDiagnostics )
1527
1550
. next ( )
1528
1551
else {
1529
1552
return ;
1530
1553
} ;
1554
+ // Specialization does not say whether it is possible to have both types of diagnostics.
1555
+ // Assume we should prefer PublishDiagnostic if possible
1556
+ if language_server
1557
+ . supports_publish_diagnostic
1558
+ . load ( atomic:: Ordering :: Relaxed )
1559
+ {
1560
+ return ;
1561
+ }
1531
1562
1532
1563
let future = language_server
1533
1564
. text_document_diagnostic ( doc. identifier ( ) , doc. previous_diagnostic_id . clone ( ) ) ;
@@ -1558,32 +1589,31 @@ pub fn pull_diagnostic_for_current_doc(editor: &mut Editor, jobs: &mut crate::jo
1558
1589
lsp:: DocumentDiagnosticReport :: Full ( report) => {
1559
1590
// Original file diagnostic
1560
1591
parse_diagnostic (
1561
- editor,
1562
- & original_path,
1592
+ doc,
1563
1593
offset_encoding,
1564
1594
server_id,
1565
1595
report. full_document_diagnostic_report . items ,
1566
1596
report. full_document_diagnostic_report . result_id ,
1567
1597
) ;
1568
1598
1569
1599
// Related file diagnostic
1570
- for ( url, report) in report. related_documents . into_iter ( ) . flatten ( ) {
1571
- match report {
1572
- lsp:: DocumentDiagnosticReportKind :: Full ( report) => {
1573
- parse_diagnostic (
1574
- editor,
1575
- url. path ( ) ,
1576
- offset_encoding,
1577
- server_id,
1578
- report. items ,
1579
- report. result_id ,
1580
- ) ;
1581
- }
1582
- lsp:: DocumentDiagnosticReportKind :: Unchanged ( _) => ( ) ,
1583
- }
1584
- }
1600
+ handle_document_diagnostic_report_kind (
1601
+ editor,
1602
+ offset_encoding,
1603
+ server_id,
1604
+ report. related_documents ,
1605
+ ) ;
1606
+ }
1607
+ lsp:: DocumentDiagnosticReport :: Unchanged ( report) => {
1608
+ doc. previous_diagnostic_id =
1609
+ 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
+ ) ;
1585
1616
}
1586
- lsp:: DocumentDiagnosticReport :: Unchanged ( _) => ( ) ,
1587
1617
}
1588
1618
}
1589
1619
} ,
0 commit comments