@@ -915,6 +915,7 @@ def setup_lsp(
915
915
lsp : JsonRpcProcess ,
916
916
expose_project_root = True ,
917
917
file_load_strategy : FileLoadStrategy = FileLoadStrategy .DirectlyOpenedAndOnImport ,
918
+ custom_include_paths : list [str ] = [],
918
919
project_root_subdir = None
919
920
):
920
921
"""
@@ -944,11 +945,19 @@ def setup_lsp(
944
945
}
945
946
}
946
947
}
948
+
947
949
if file_load_strategy != FileLoadStrategy .Undefined :
948
950
params ['initializationOptions' ] = {}
949
951
params ['initializationOptions' ]['file-load-strategy' ] = file_load_strategy .lsp_name ()
952
+
953
+ if len (custom_include_paths ) != 0 :
954
+ if params ['initializationOptions' ] is None :
955
+ params ['initializationOptions' ] = {}
956
+ params ['initializationOptions' ]['include-paths' ] = custom_include_paths
957
+
950
958
if not expose_project_root :
951
959
params ['rootUri' ] = None
960
+
952
961
lsp .call_method ('initialize' , params )
953
962
lsp .send_notification ('initialized' )
954
963
@@ -1383,6 +1392,40 @@ def test_analyze_all_project_files2(self, solc: JsonRpcProcess) -> None:
1383
1392
self .expect_true (report ['uri' ] in EXPECTED_URIS , "Correct file URI" )
1384
1393
self .expect_equal (len (report ['diagnostics' ]), 0 , "no diagnostics" )
1385
1394
1395
+ def test_analyze_all_project_files3 (self , solc : JsonRpcProcess ) -> None :
1396
+ """
1397
+ Same as first test on that matter but with deeper nesting levels.
1398
+ """
1399
+ SUBDIR = 'include-paths-nested-2'
1400
+ EXPECTED_FILES = [
1401
+ "A/B/C/foo" ,
1402
+ "A/B/foo" ,
1403
+ "A/foo" ,
1404
+ "foo" ,
1405
+ ]
1406
+ IMPLICITLY_LOADED_FILE_COUNT = 1
1407
+ EXPECTED_URIS = [self .get_test_file_uri (x , SUBDIR ) for x in EXPECTED_FILES ]
1408
+ self .setup_lsp (
1409
+ solc ,
1410
+ file_load_strategy = FileLoadStrategy .ProjectDirectory ,
1411
+ project_root_subdir = SUBDIR ,
1412
+ custom_include_paths = [f"{ self .project_root_dir } /other-include-dir" ]
1413
+ )
1414
+ published_diagnostics = self .wait_for_diagnostics (solc )
1415
+ self .expect_equal (len (published_diagnostics ), len (EXPECTED_FILES ) + IMPLICITLY_LOADED_FILE_COUNT , "Test number of files analyzed." )
1416
+
1417
+ # All but the last report should be from expected files
1418
+ for report in published_diagnostics [:- IMPLICITLY_LOADED_FILE_COUNT ]:
1419
+ self .expect_true (report ['uri' ] in EXPECTED_URIS , "Correct file URI" )
1420
+ self .expect_equal (len (report ['diagnostics' ]), 0 , "no diagnostics" )
1421
+
1422
+ # Check last report (should be the custom imported lib).
1423
+ # This file is analyzed because it was imported via "A/B/C/foo.sol".
1424
+ report = published_diagnostics [len (EXPECTED_URIS )]
1425
+ self .expect_equal (report ['uri' ], f"{ self .project_root_uri } /other-include-dir/otherlib/second.sol" , "Correct file URI" )
1426
+ self .expect_equal (len (report ['diagnostics' ]), 0 , "no diagnostics" )
1427
+
1428
+
1386
1429
def test_publish_diagnostics_errors_multiline (self , solc : JsonRpcProcess ) -> None :
1387
1430
self .setup_lsp (solc )
1388
1431
TEST_NAME = 'publish_diagnostics_3'
@@ -1495,6 +1538,43 @@ def test_custom_includes(self, solc: JsonRpcProcess) -> None:
1495
1538
self .expect_equal (len (diagnostics ), 1 , "no diagnostics" )
1496
1539
self .expect_diagnostic (diagnostics [0 ], code = 2018 , lineNo = 5 , startEndColumns = (4 , 62 ))
1497
1540
1541
+ def test_custom_includes_with_full_project (self , solc : JsonRpcProcess ) -> None :
1542
+ """
1543
+ Tests loading all all project files while having custom include directories configured.
1544
+ In such a scenario, all project files should be analyzed and those being included via search path
1545
+ but not those include files that are not directly nor indirectly included.
1546
+ """
1547
+ self .setup_lsp (
1548
+ solc ,
1549
+ expose_project_root = True ,
1550
+ project_root_subdir = ''
1551
+ )
1552
+ solc .send_notification (
1553
+ 'workspace/didChangeConfiguration' , {
1554
+ 'settings' : {
1555
+ 'include-paths' : [
1556
+ f"{ self .project_root_dir } /other-include-dir"
1557
+ ]
1558
+ }
1559
+ }
1560
+ )
1561
+ published_diagnostics = self .open_file_and_wait_for_diagnostics (solc , 'include-paths/using-custom-includes' )
1562
+
1563
+ self .expect_equal (len (published_diagnostics ), 2 , "Diagnostic reports for 2 files" )
1564
+
1565
+ # test file
1566
+ report = published_diagnostics [0 ]
1567
+ self .expect_equal (report ['uri' ], self .get_test_file_uri ('using-custom-includes' , 'include-paths' ))
1568
+ diagnostics = report ['diagnostics' ]
1569
+ self .expect_equal (len (diagnostics ), 0 , "no diagnostics" )
1570
+
1571
+ # imported file
1572
+ report = published_diagnostics [1 ]
1573
+ self .expect_equal (report ['uri' ], f"{ self .project_root_uri } /other-include-dir/otherlib/otherlib.sol" )
1574
+ diagnostics = report ['diagnostics' ]
1575
+ self .expect_equal (len (diagnostics ), 1 , "no diagnostics" )
1576
+ self .expect_diagnostic (diagnostics [0 ], code = 2018 , lineNo = 5 , startEndColumns = (4 , 62 ))
1577
+
1498
1578
def test_didChange_in_A_causing_error_in_B (self , solc : JsonRpcProcess ) -> None :
1499
1579
# Reusing another test but now change some file that generates an error in the other.
1500
1580
self .test_textDocument_didOpen_with_relative_import (solc )
0 commit comments