Skip to content

Commit c2d4e28

Browse files
committed
Create a test to check for early project loading
1 parent 18357f1 commit c2d4e28

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
project Prj is
2+
package Gnattest is
3+
for Harness_Dir use "myharness";
4+
end Gnattest;
5+
end Prj;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
The goal of this test is to check that the ALS loads the project early in the session,
3+
such that immediately after the initialization sequence, it is possible to inspect
4+
project attributes without opening any Ada sources or sending a configuration change to
5+
force a project load.
6+
"""
7+
8+
from drivers.pylsp import ALSLanguageClient, test
9+
10+
11+
@test(
12+
# Sending initializationOptions should cause the ALS to load a project early,
13+
# when handling the `initialized` notification. So we give an empty settings
14+
# dictionary to force the sending of initializationOptions.
15+
als_settings={}
16+
)
17+
async def t1(lsp: ALSLanguageClient):
18+
# Query a project attribute
19+
result = await lsp.getProjectAttributeValue("harness_dir", "gnattest")
20+
21+
lsp.assertEqual(result, "myharness")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
driver: pylsp

testsuite/drivers/pylsp.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,27 @@ async def sleep(self, seconds: float) -> None:
485485
wait_factor: int = int(os.environ.get("ALS_WAIT_FACTOR", "1"))
486486
await asyncio.sleep(seconds * wait_factor)
487487

488+
async def getProjectAttributeValue(
489+
self, attribute: str, pkg: str = "", index: str = ""
490+
) -> str | list[str]:
491+
"""Send a workspace/executeCommand request with command
492+
'als-get-project-attribute-value' to retrieve an attribute of the loaded
493+
project.
494+
"""
495+
result = await self.workspace_execute_command_async(
496+
ExecuteCommandParams(
497+
command="als-get-project-attribute-value",
498+
arguments=[{"attribute": attribute, "pkg": pkg, "index": index}],
499+
)
500+
)
501+
502+
assert isinstance(result, str) or (
503+
isinstance(result, list)
504+
and all(lambda x: isinstance(x, str) for x in result)
505+
), f"Unexpected type of result: {result}"
506+
507+
return result
508+
488509

489510
def als_client_factory() -> ALSLanguageClient:
490511
"""This function is an ugly copy-paste of pytest_lsp.make_test_lsp_client. It is
@@ -634,7 +655,7 @@ def test(
634655
"""
635656

636657
async def async_wrapper(
637-
func: Callable[[ALSLanguageClient], Awaitable[object]]
658+
func: Callable[[ALSLanguageClient], Awaitable[object]],
638659
) -> None:
639660
als = os.environ.get("ALS", "ada_language_server")
640661
command = [als]

0 commit comments

Comments
 (0)