@@ -539,16 +539,9 @@ def at_end(self):
539
539
return self .current_line_tuple is None
540
540
541
541
class FileLoadStrategy (Enum ):
542
- Undefined = auto ()
543
- ProjectDirectory = auto ()
544
- DirectlyOpenedAndOnImport = auto ()
545
-
546
- def lsp_name (self ):
547
- if self == FileLoadStrategy .ProjectDirectory :
548
- return 'project-directory'
549
- elif self == FileLoadStrategy .DirectlyOpenedAndOnImport :
550
- return 'directly-opened-and-on-import'
551
- return None
542
+ Undefined = None
543
+ ProjectDirectory = 'project-directory'
544
+ DirectlyOpenedAndOnImport = 'directly-opened-and-on-import'
552
545
553
546
class FileTestRunner :
554
547
"""
@@ -932,7 +925,6 @@ def setup_lsp(
932
925
# Enable traces to receive the amount of expected diagnostics before
933
926
# actually receiving them.
934
927
'trace' : 'messages' ,
935
- # 'initializationOptions': {},
936
928
'capabilities' : {
937
929
'textDocument' : {
938
930
'publishDiagnostics' : {'relatedInformation' : True }
@@ -949,7 +941,7 @@ def setup_lsp(
949
941
950
942
if file_load_strategy != FileLoadStrategy .Undefined :
951
943
params ['initializationOptions' ] = {}
952
- params ['initializationOptions' ]['file-load-strategy' ] = file_load_strategy .lsp_name ()
944
+ params ['initializationOptions' ]['file-load-strategy' ] = file_load_strategy .value
953
945
954
946
if custom_include_paths is not None and len (custom_include_paths ) != 0 :
955
947
if params ['initializationOptions' ] is None :
@@ -1337,7 +1329,7 @@ def user_interaction_failed_autoupdate(self, test, sub_dir):
1337
1329
# }}}
1338
1330
1339
1331
# {{{ actual tests
1340
- def test_analyze_all_project_files1 (self , solc : JsonRpcProcess ) -> None :
1332
+ def test_analyze_all_project_files_flat (self , solc : JsonRpcProcess ) -> None :
1341
1333
"""
1342
1334
Tests the option (default) to analyze all .sol project files even when they have not been actively
1343
1335
opened yet. This is how other LSPs (at least for C++) work too and it makes cross-unit tasks
@@ -1370,42 +1362,41 @@ def test_analyze_all_project_files1(self, solc: JsonRpcProcess) -> None:
1370
1362
self .expect_equal (report ['uri' ], self .get_test_file_uri ('E' , SUBDIR ), "Correct file URI" )
1371
1363
self .expect_equal (len (report ['diagnostics' ]), 0 , "no diagnostics" )
1372
1364
1373
- def test_analyze_all_project_files2 (self , solc : JsonRpcProcess ) -> None :
1365
+ def test_analyze_all_project_files_nested (self , solc : JsonRpcProcess ) -> None :
1374
1366
"""
1375
1367
Same as first test on that matter but with deeper nesting levels.
1376
1368
"""
1377
1369
SUBDIR = 'include-paths-nested'
1378
- EXPECTED_FILES = [
1370
+ EXPECTED_FILES = {
1379
1371
"A/B/C/foo" ,
1380
1372
"A/B/foo" ,
1381
1373
"A/foo" ,
1382
1374
"foo" ,
1383
- ]
1384
- EXPECTED_URIS = [ self .get_test_file_uri (x , SUBDIR ) for x in EXPECTED_FILES ]
1375
+ }
1376
+ EXPECTED_URIS = { self .get_test_file_uri (x , SUBDIR ) for x in EXPECTED_FILES }
1385
1377
self .setup_lsp (
1386
1378
solc ,
1387
1379
file_load_strategy = FileLoadStrategy .ProjectDirectory ,
1388
1380
project_root_subdir = SUBDIR
1389
1381
)
1390
1382
published_diagnostics = self .wait_for_diagnostics (solc )
1391
1383
self .expect_equal (len (published_diagnostics ), len (EXPECTED_FILES ), "Test number of files analyzed." )
1392
- for report in published_diagnostics :
1393
- self .expect_true (report ['uri' ] in EXPECTED_URIS , "Correct file URI" )
1394
- self .expect_equal (len (report ['diagnostics' ]), 0 , "no diagnostics" )
1384
+ self .expect_equal ({report ['uri' ] for report in published_diagnostics }, EXPECTED_URIS )
1385
+ self .expect_equal ([len (report ['diagnostics' ]) for report in published_diagnostics ], [0 ] * len (EXPECTED_URIS ))
1395
1386
1396
- def test_analyze_all_project_files3 (self , solc : JsonRpcProcess ) -> None :
1387
+ def test_analyze_all_project_files_nested_with_include_paths (self , solc : JsonRpcProcess ) -> None :
1397
1388
"""
1398
1389
Same as first test on that matter but with deeper nesting levels.
1399
1390
"""
1400
1391
SUBDIR = 'include-paths-nested-2'
1401
- EXPECTED_FILES = [
1392
+ EXPECTED_FILES = {
1402
1393
"A/B/C/foo" ,
1403
1394
"A/B/foo" ,
1404
1395
"A/foo" ,
1405
1396
"foo" ,
1406
- ]
1397
+ }
1407
1398
IMPLICITLY_LOADED_FILE_COUNT = 1
1408
- EXPECTED_URIS = [ self .get_test_file_uri (x , SUBDIR ) for x in EXPECTED_FILES ]
1399
+ EXPECTED_URIS = { self .get_test_file_uri (x , SUBDIR ) for x in EXPECTED_FILES }
1409
1400
self .setup_lsp (
1410
1401
solc ,
1411
1402
file_load_strategy = FileLoadStrategy .ProjectDirectory ,
@@ -1426,9 +1417,9 @@ def test_analyze_all_project_files3(self, solc: JsonRpcProcess) -> None:
1426
1417
1427
1418
# Check last report (should be the custom imported lib).
1428
1419
# This file is analyzed because it was imported via "A/B/C/foo.sol".
1429
- report = published_diagnostics [len (EXPECTED_URIS )]
1430
- self .expect_equal (report ['uri' ], f" { self .project_root_uri } / other-include-dir/otherlib/second.sol" , "Correct file URI" )
1431
- self .expect_equal (len (report ['diagnostics' ]), 0 , "no diagnostics" )
1420
+ last_report = published_diagnostics [len (EXPECTED_URIS )]
1421
+ self .expect_equal (last_report ['uri' ], self .get_test_file_uri ( 'second' , ' other-include-dir/otherlib' ) , "Correct file URI" )
1422
+ self .expect_equal (len (last_report ['diagnostics' ]), 0 , "no diagnostics" )
1432
1423
1433
1424
1434
1425
def test_publish_diagnostics_errors_multiline (self , solc : JsonRpcProcess ) -> None :
@@ -1545,7 +1536,7 @@ def test_custom_includes(self, solc: JsonRpcProcess) -> None:
1545
1536
1546
1537
def test_custom_includes_with_full_project (self , solc : JsonRpcProcess ) -> None :
1547
1538
"""
1548
- Tests loading all all project files while having custom include directories configured.
1539
+ Tests loading all project files while having custom include directories configured.
1549
1540
In such a scenario, all project files should be analyzed and those being included via search path
1550
1541
but not those include files that are not directly nor indirectly included.
1551
1542
"""
@@ -1577,7 +1568,7 @@ def test_custom_includes_with_full_project(self, solc: JsonRpcProcess) -> None:
1577
1568
report = published_diagnostics [1 ]
1578
1569
self .expect_equal (report ['uri' ], f"{ self .project_root_uri } /other-include-dir/otherlib/otherlib.sol" )
1579
1570
diagnostics = report ['diagnostics' ]
1580
- self .expect_equal (len (diagnostics ), 1 , "no diagnostics" )
1571
+ self .expect_equal (len (diagnostics ), 1 )
1581
1572
self .expect_diagnostic (diagnostics [0 ], code = 2018 , lineNo = 5 , startEndColumns = (4 , 62 ))
1582
1573
1583
1574
def test_didChange_in_A_causing_error_in_B (self , solc : JsonRpcProcess ) -> None :
0 commit comments