@@ -65,7 +65,7 @@ class mock_lsp_linter final : public lsp_linter {
65
65
using lint_and_get_diagnostics_notification_type =
66
66
void (configuration&, linter_options, padded_string_view code,
67
67
string8_view uri_json, string8_view version_json,
68
- byte_buffer& notification_json );
68
+ outgoing_lsp_message_queue& outgoing_messages );
69
69
70
70
explicit mock_lsp_linter () = default;
71
71
@@ -81,9 +81,9 @@ class mock_lsp_linter final : public lsp_linter {
81
81
void lint_and_get_diagnostics_notification (
82
82
configuration& config, linter_options lint_options,
83
83
padded_string_view code, string8_view uri_json, string8_view version_json,
84
- byte_buffer& notification_json ) override {
84
+ outgoing_lsp_message_queue& outgoing_messages ) override {
85
85
this ->callback_ (config, lint_options, code, uri_json, version_json,
86
- notification_json );
86
+ outgoing_messages );
87
87
}
88
88
89
89
private:
@@ -101,11 +101,12 @@ class test_linting_lsp_server : public ::testing::Test, public filesystem_test {
101
101
this ->linter = mock_lsp_linter (
102
102
[this ](configuration& config, linter_options lint_options,
103
103
padded_string_view code, string8_view uri_json,
104
- string8_view version_json, byte_buffer& notification_json) {
104
+ string8_view version_json,
105
+ outgoing_lsp_message_queue& outgoing_messages) {
105
106
this ->lint_calls .emplace_back (code.string_view ());
106
107
if (this ->lint_callback ) {
107
108
this ->lint_callback (config, lint_options, code, uri_json,
108
- version_json, notification_json );
109
+ version_json, outgoing_messages );
109
110
}
110
111
});
111
112
this ->handler =
@@ -117,7 +118,7 @@ class test_linting_lsp_server : public ::testing::Test, public filesystem_test {
117
118
118
119
heap_function<void (configuration&, linter_options, padded_string_view code,
119
120
string8_view uri_json, string8_view version,
120
- byte_buffer& notification_json )>
121
+ outgoing_lsp_message_queue& outgoing_messages )>
121
122
lint_callback;
122
123
std::vector<string8> lint_calls;
123
124
@@ -517,11 +518,12 @@ TEST_F(test_linting_lsp_server, opening_document_lints) {
517
518
this ->lint_callback = [&](configuration&, linter_options,
518
519
padded_string_view code, string8_view uri_json,
519
520
string8_view version,
520
- byte_buffer& notification_json ) {
521
+ outgoing_lsp_message_queue& outgoing_messages ) {
521
522
EXPECT_EQ (code, u8" let x = x;" _sv);
522
523
EXPECT_EQ (uri_json, u8" \" file:///test.js\" " _sv);
523
524
EXPECT_EQ (version, u8" 10" _sv);
524
525
526
+ byte_buffer& notification_json = outgoing_messages.new_message ();
525
527
notification_json.append_copy (
526
528
u8R"--(
527
529
{
@@ -591,7 +593,7 @@ TEST_F(test_linting_lsp_server, javascript_language_ids_enable_jsx) {
591
593
592
594
this ->lint_callback = [&](configuration&, linter_options lint_options,
593
595
padded_string_view, string8_view, string8_view,
594
- byte_buffer &) {
596
+ outgoing_lsp_message_queue &) {
595
597
EXPECT_TRUE (lint_options.jsx );
596
598
EXPECT_FALSE (lint_options.typescript );
597
599
};
@@ -622,7 +624,7 @@ TEST_F(test_linting_lsp_server, typescript_language_ids_enable_typescript) {
622
624
623
625
this ->lint_callback = [&](configuration&, linter_options lint_options,
624
626
padded_string_view, string8_view, string8_view,
625
- byte_buffer &) {
627
+ outgoing_lsp_message_queue &) {
626
628
EXPECT_TRUE (lint_options.typescript );
627
629
EXPECT_FALSE (lint_options.jsx );
628
630
};
@@ -653,7 +655,7 @@ TEST_F(test_linting_lsp_server, tsx_language_ids_enable_typescript_jsx) {
653
655
654
656
this ->lint_callback = [&](configuration&, linter_options lint_options,
655
657
padded_string_view, string8_view, string8_view,
656
- byte_buffer &) {
658
+ outgoing_lsp_message_queue &) {
657
659
EXPECT_TRUE (lint_options.typescript );
658
660
EXPECT_TRUE (lint_options.jsx );
659
661
};
@@ -828,7 +830,7 @@ TEST_F(test_linting_lsp_server, linting_uses_config_from_file) {
828
830
829
831
this ->lint_callback = [&](configuration& config, linter_options,
830
832
padded_string_view, string8_view, string8_view,
831
- byte_buffer &) {
833
+ outgoing_lsp_message_queue &) {
832
834
EXPECT_TRUE (config.globals ().find (u8" testGlobalVariable" _sv));
833
835
};
834
836
@@ -915,7 +917,7 @@ TEST_F(
915
917
this ->lint_calls .clear ();
916
918
this ->lint_callback = [&](configuration& config, linter_options,
917
919
padded_string_view, string8_view, string8_view,
918
- byte_buffer &) {
920
+ outgoing_lsp_message_queue &) {
919
921
EXPECT_FALSE (config.globals ().find (u8" testGlobalVariableBefore" _sv));
920
922
EXPECT_TRUE (config.globals ().find (u8" testGlobalVariableAfter" _sv));
921
923
};
@@ -948,7 +950,7 @@ TEST_F(test_linting_lsp_server,
948
950
949
951
this ->lint_callback = [&](configuration& config, linter_options,
950
952
padded_string_view, string8_view, string8_view,
951
- byte_buffer &) {
953
+ outgoing_lsp_message_queue &) {
952
954
EXPECT_TRUE (config.globals ().find (u8" testGlobalVariable" _sv));
953
955
};
954
956
@@ -974,7 +976,7 @@ TEST_F(test_linting_lsp_server,
974
976
TEST_F (test_linting_lsp_server, linting_uses_already_opened_config_file) {
975
977
this ->lint_callback = [&](configuration& config, linter_options,
976
978
padded_string_view, string8_view, string8_view,
977
- byte_buffer &) {
979
+ outgoing_lsp_message_queue &) {
978
980
EXPECT_TRUE (config.globals ().find (u8" modified" _sv));
979
981
};
980
982
@@ -1018,7 +1020,7 @@ TEST_F(test_linting_lsp_server,
1018
1020
linting_uses_already_opened_shadowing_config_file) {
1019
1021
this ->lint_callback = [&](configuration& config, linter_options,
1020
1022
padded_string_view, string8_view, string8_view,
1021
- byte_buffer &) {
1023
+ outgoing_lsp_message_queue &) {
1022
1024
EXPECT_TRUE (config.globals ().find (u8" haveInnerConfig" _sv));
1023
1025
EXPECT_FALSE (config.globals ().find (u8" haveOuterConfig" _sv));
1024
1026
};
@@ -1064,7 +1066,8 @@ TEST_F(test_linting_lsp_server, editing_config_relints_open_js_file) {
1064
1066
1065
1067
this ->lint_callback = [&](configuration& config, linter_options,
1066
1068
padded_string_view, string8_view uri_json,
1067
- string8_view version_json, byte_buffer&) {
1069
+ string8_view version_json,
1070
+ outgoing_lsp_message_queue&) {
1068
1071
if (config.globals ().find (u8" after" _sv)) {
1069
1072
EXPECT_FALSE (config.globals ().find (u8" before" _sv));
1070
1073
EXPECT_EQ (version_json, u8" 10" );
@@ -1192,7 +1195,9 @@ TEST_F(test_linting_lsp_server,
1192
1195
1193
1196
this ->lint_callback = [&](configuration&, linter_options, padded_string_view,
1194
1197
string8_view, string8_view version_json,
1195
- byte_buffer&) { EXPECT_EQ (version_json, u8" 11" ); };
1198
+ outgoing_lsp_message_queue&) {
1199
+ EXPECT_EQ (version_json, u8" 11" );
1200
+ };
1196
1201
this ->lint_calls .clear ();
1197
1202
1198
1203
// Change 'before' to 'after'.
@@ -1225,7 +1230,8 @@ TEST_F(test_linting_lsp_server,
1225
1230
TEST_F (test_linting_lsp_server, editing_config_relints_many_open_js_files) {
1226
1231
this ->lint_callback = [&](configuration&, linter_options, padded_string_view,
1227
1232
string8_view uri_json, string8_view version_json,
1228
- byte_buffer& notification_json) {
1233
+ outgoing_lsp_message_queue& outgoing_messages) {
1234
+ byte_buffer& notification_json = outgoing_messages.new_message ();
1229
1235
notification_json.append_copy (
1230
1236
u8R"(
1231
1237
{
@@ -1337,7 +1343,8 @@ TEST_F(test_linting_lsp_server, editing_config_relints_many_open_js_files) {
1337
1343
TEST_F (test_linting_lsp_server, editing_config_relints_only_affected_js_files) {
1338
1344
this ->lint_callback = [&](configuration&, linter_options, padded_string_view,
1339
1345
string8_view uri_json, string8_view version_json,
1340
- byte_buffer& notification_json) {
1346
+ outgoing_lsp_message_queue& outgoing_messages) {
1347
+ byte_buffer& notification_json = outgoing_messages.new_message ();
1341
1348
notification_json.append_copy (
1342
1349
u8R"(
1343
1350
{
@@ -1514,7 +1521,8 @@ TEST_F(test_linting_lsp_server,
1514
1521
this ->lint_calls .clear ();
1515
1522
this ->lint_callback = [&](configuration& config, linter_options,
1516
1523
padded_string_view, string8_view,
1517
- string8_view version_json, byte_buffer&) {
1524
+ string8_view version_json,
1525
+ outgoing_lsp_message_queue&) {
1518
1526
EXPECT_EQ (version_json, u8" 11" );
1519
1527
EXPECT_FALSE (config.globals ().find (u8" before" _sv));
1520
1528
EXPECT_TRUE (config.globals ().find (u8" after" _sv));
@@ -1547,7 +1555,8 @@ TEST_F(test_linting_lsp_server, opening_config_relints_open_js_files) {
1547
1555
1548
1556
this ->lint_callback = [&](configuration& config, linter_options,
1549
1557
padded_string_view, string8_view uri_json,
1550
- string8_view version_json, byte_buffer&) {
1558
+ string8_view version_json,
1559
+ outgoing_lsp_message_queue&) {
1551
1560
if (config.globals ().find (u8" after" _sv)) {
1552
1561
EXPECT_FALSE (config.globals ().find (u8" before" _sv));
1553
1562
EXPECT_EQ (version_json, u8" 10" );
@@ -1617,13 +1626,14 @@ TEST_F(test_linting_lsp_server,
1617
1626
this ->lint_callback = [&](configuration& config, linter_options,
1618
1627
padded_string_view, string8_view uri_json,
1619
1628
string8_view version_json,
1620
- byte_buffer& notification_json ) {
1629
+ outgoing_lsp_message_queue& outgoing_messages ) {
1621
1630
EXPECT_TRUE (config.globals ().find (u8" after" _sv));
1622
1631
EXPECT_FALSE (config.globals ().find (u8" before" _sv));
1623
1632
EXPECT_EQ (version_json, u8" 10" );
1624
1633
EXPECT_EQ (uri_json, u8" \" " + this ->fs .file_uri_prefix_8 () + u8" test.js\" " );
1625
1634
after_config_was_loaded = true ;
1626
1635
1636
+ byte_buffer& notification_json = outgoing_messages.new_message ();
1627
1637
notification_json.append_copy (
1628
1638
u8R"( {
1629
1639
"method": "textDocument/publishDiagnostics",
@@ -1658,7 +1668,7 @@ TEST_F(
1658
1668
linting_uses_config_from_filesystem_if_config_is_opened_then_closed_before_opening_js_file) {
1659
1669
this ->lint_callback = [&](configuration& config, linter_options,
1660
1670
padded_string_view, string8_view, string8_view,
1661
- byte_buffer &) {
1671
+ outgoing_lsp_message_queue &) {
1662
1672
EXPECT_TRUE (config.globals ().find (u8" v1" _sv));
1663
1673
EXPECT_FALSE (config.globals ().find (u8" v2" _sv));
1664
1674
};
@@ -1749,9 +1759,10 @@ TEST_F(test_linting_lsp_server,
1749
1759
this ->lint_calls .clear ();
1750
1760
this ->lint_callback = [&](configuration& config, linter_options,
1751
1761
padded_string_view, string8_view, string8_view,
1752
- byte_buffer& notification_json ) {
1762
+ outgoing_lsp_message_queue& outgoing_messages ) {
1753
1763
EXPECT_TRUE (config.globals ().find (u8" configFromFilesystem" _sv));
1754
1764
EXPECT_FALSE (config.globals ().find (u8" configFromLSP" _sv));
1765
+ byte_buffer& notification_json = outgoing_messages.new_message ();
1755
1766
notification_json.append_copy (
1756
1767
u8R"( {
1757
1768
"method": "textDocument/publishDiagnostics",
@@ -1793,11 +1804,12 @@ TEST_F(test_linting_lsp_server, opening_js_file_with_unreadable_config_lints) {
1793
1804
this ->lint_callback = [&](configuration& config, linter_options,
1794
1805
padded_string_view, string8_view uri_json,
1795
1806
string8_view version_json,
1796
- byte_buffer& notification_json ) {
1807
+ outgoing_lsp_message_queue& outgoing_messages ) {
1797
1808
EXPECT_TRUE (config.globals ().find (u8" Array" _sv))
1798
1809
<< " config should be default" ;
1799
1810
EXPECT_FALSE (config.globals ().find (u8" undeclaredVariable" _sv))
1800
1811
<< " config should be default" ;
1812
+ byte_buffer& notification_json = outgoing_messages.new_message ();
1801
1813
notification_json.append_copy (
1802
1814
u8R"( {
1803
1815
"method": "textDocument/publishDiagnostics",
@@ -1855,11 +1867,12 @@ TEST_F(test_linting_lsp_server,
1855
1867
this ->lint_callback = [&](configuration& config, linter_options,
1856
1868
padded_string_view, string8_view uri_json,
1857
1869
string8_view version_json,
1858
- byte_buffer& notification_json ) {
1870
+ outgoing_lsp_message_queue& outgoing_messages ) {
1859
1871
EXPECT_TRUE (config.globals ().find (u8" Array" _sv))
1860
1872
<< " config should be default" ;
1861
1873
EXPECT_FALSE (config.globals ().find (u8" undeclaredVariable" _sv))
1862
1874
<< " config should be default" ;
1875
+ byte_buffer& notification_json = outgoing_messages.new_message ();
1863
1876
notification_json.append_copy (
1864
1877
u8R"( {
1865
1878
"method": "textDocument/publishDiagnostics",
@@ -1943,9 +1956,10 @@ TEST_F(test_linting_lsp_server, making_config_file_unreadable_relints) {
1943
1956
this ->lint_callback = [&](configuration& config, linter_options,
1944
1957
padded_string_view, string8_view uri_json,
1945
1958
string8_view version_json,
1946
- byte_buffer& notification_json ) {
1959
+ outgoing_lsp_message_queue& outgoing_messages ) {
1947
1960
EXPECT_FALSE (config.globals ().find (u8" configFromFilesystem" _sv))
1948
1961
<< " config should be default" ;
1962
+ byte_buffer& notification_json = outgoing_messages.new_message ();
1949
1963
notification_json.append_copy (
1950
1964
u8R"( {
1951
1965
"method": "textDocument/publishDiagnostics",
@@ -2484,21 +2498,20 @@ TEST_F(test_linting_lsp_server, invalid_notification_is_ignored) {
2484
2498
2485
2499
TEST (test_lsp_javascript_linter, linting_gives_diagnostics) {
2486
2500
padded_string code (u8" let x = x;" _sv);
2487
- byte_buffer notification_json_buffer ;
2501
+ outgoing_lsp_message_queue notifications ;
2488
2502
configuration config;
2489
2503
2490
2504
lsp_javascript_linter linter;
2491
- linter.lint_and_get_diagnostics_notification (
2492
- config, linter_options (), &code, u8" \" file:///test.js\" " _sv, u8" 10 " _sv,
2493
- notification_json_buffer );
2505
+ linter.lint_and_get_diagnostics_notification (config, linter_options (), &code,
2506
+ u8" \" file:///test.js\" " _sv,
2507
+ u8" 10 " _sv, notifications );
2494
2508
2495
- std::string notification_json ;
2496
- notification_json. resize (notification_json_buffer. size () );
2497
- notification_json_buffer. copy_to (notification_json. data () );
2509
+ spy_lsp_endpoint_remote endpoint ;
2510
+ notifications. send (endpoint );
2511
+ ::boost::json::object notification = endpoint. notifications (). at ( 0 );
2498
2512
2499
- ::boost::json::value notification = parse_boost_json (notification_json);
2500
2513
EXPECT_EQ (look_up (notification, " method" ), " textDocument/publishDiagnostics" );
2501
- EXPECT_FALSE (notification.as_object (). contains (" error" ));
2514
+ EXPECT_FALSE (notification.contains (" error" ));
2502
2515
// LSP PublishDiagnosticsParams:
2503
2516
EXPECT_EQ (look_up (notification, " params" , " uri" ), " file:///test.js" );
2504
2517
EXPECT_EQ (look_up (notification, " params" , " version" ), 10 );
0 commit comments