-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Document
workspace/configuration
support
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
lib/pytest-lsp/tests/examples/workspace-configuration/server.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from lsprotocol import types | ||
from pygls.server import LanguageServer | ||
|
||
server = LanguageServer("workspace-configuration", "v1") | ||
|
||
|
||
@server.command("server.configuration") | ||
async def configuration(ls: LanguageServer, *args): | ||
results = await ls.get_configuration_async( | ||
types.WorkspaceConfigurationParams( | ||
items=[ | ||
types.ConfigurationItem(scope_uri="file://workspace/file.txt"), | ||
types.ConfigurationItem(section="not.found"), | ||
types.ConfigurationItem(section="values.c"), | ||
] | ||
) | ||
) | ||
|
||
a = results[0]["values"]["a"] | ||
assert results[1] is None | ||
c = results[2] | ||
|
||
return a + c | ||
|
||
|
||
if __name__ == "__main__": | ||
server.start_io() |
44 changes: 44 additions & 0 deletions
44
lib/pytest-lsp/tests/examples/workspace-configuration/t_server.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import sys | ||
|
||
import pytest | ||
from lsprotocol import types | ||
|
||
import pytest_lsp | ||
from pytest_lsp import ClientServerConfig | ||
from pytest_lsp import LanguageClient | ||
|
||
|
||
@pytest_lsp.fixture( | ||
config=ClientServerConfig(server_command=[sys.executable, "server.py"]), | ||
) | ||
async def client(lsp_client: LanguageClient): | ||
# Setup | ||
params = types.InitializeParams( | ||
capabilities=types.ClientCapabilities( | ||
workspace=types.WorkspaceClientCapabilities(configuration=False) | ||
) | ||
) | ||
await lsp_client.initialize_session(params) | ||
|
||
yield | ||
|
||
# Teardown | ||
await lsp_client.shutdown_session() | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_configuration(client: LanguageClient): | ||
global_config = {"values": {"a": 42, "c": 4}} | ||
|
||
workspace_uri = "file://workspace/file.txt" | ||
workspace_config = {"a": 1, "c": 1} | ||
|
||
client.set_configuration(global_config) | ||
client.set_configuration( | ||
workspace_config, section="values", scope_uri=workspace_uri | ||
) | ||
|
||
result = await client.workspace_execute_command_async( | ||
params=types.ExecuteCommandParams(command="server.configuration") | ||
) | ||
assert result == 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters