Skip to content

Commit d89008d

Browse files
lsp: Adding test for custom include paths.
1 parent 31227e4 commit d89008d

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity >=0.8.0;
3+
4+
import "otherlib/otherlib.sol";
5+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @NotFound
6+
7+
contract MyContract
8+
{
9+
}
10+
// ----
11+
// using-custom-includes: @NotFound 6275
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity >=0.8.0;
3+
4+
library OtherLib
5+
{
6+
function f(uint n) public returns (uint) { return n + 1; }
7+
}

test/lsp.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,34 @@ def get_test_tags(self, test_name: TestName, sub_dir=None, verbose=False):
13811381
return markers
13821382

13831383

1384+
def test_custom_includes(self, solc: JsonRpcProcess) -> None:
1385+
self.setup_lsp(solc, expose_project_root=False)
1386+
solc.send_notification(
1387+
'workspace/didChangeConfiguration', {
1388+
'settings': {
1389+
'include-paths': [
1390+
f"{self.project_root_dir}/other-include-dir"
1391+
]
1392+
}
1393+
}
1394+
)
1395+
published_diagnostics = self.open_file_and_wait_for_diagnostics(solc, 'include-paths/using-custom-includes')
1396+
1397+
self.expect_equal(len(published_diagnostics), 2, "Diagnostic reports for 2 files")
1398+
1399+
# test file
1400+
report = published_diagnostics[0]
1401+
self.expect_equal(report['uri'], self.get_test_file_uri('using-custom-includes', 'include-paths'))
1402+
diagnostics = report['diagnostics']
1403+
self.expect_equal(len(diagnostics), 0, "no diagnostics")
1404+
1405+
# imported file
1406+
report = published_diagnostics[1]
1407+
self.expect_equal(report['uri'], f"{self.project_root_uri}/other-include-dir/otherlib/otherlib.sol")
1408+
diagnostics = report['diagnostics']
1409+
self.expect_equal(len(diagnostics), 1, "no diagnostics")
1410+
self.expect_diagnostic(diagnostics[0], code=2018, lineNo=5, startEndColumns=(4, 62))
1411+
13841412
def test_didChange_in_A_causing_error_in_B(self, solc: JsonRpcProcess) -> None:
13851413
# Reusing another test but now change some file that generates an error in the other.
13861414
self.test_textDocument_didOpen_with_relative_import(solc)

0 commit comments

Comments
 (0)