Skip to content

Commit

Permalink
pytest-lsp: Update README code
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Sep 4, 2024
1 parent bb832ba commit 9e7ed84
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ This also means `pytest-lsp` can be used to test language servers written in any
```python
import sys

import pytest
import pytest_lsp
from lsprotocol.types import (
CompletionParams,
InitializeParams,
Position,
TextDocumentIdentifier,
)
from lsprotocol import types
from pytest_lsp import (
ClientServerConfig,
LanguageClient,
Expand All @@ -48,16 +44,21 @@ from pytest_lsp import (


@pytest_lsp.fixture(
scope="module",
config=ClientServerConfig(
server_command=[sys.executable, "-m", "esbonio"],
),
)
async def client(lsp_client: LanguageClient):
# Setup
response = await lsp_client.initialize_session(
InitializeParams(
types.InitializeParams(
capabilities=client_capabilities("visual-studio-code"),
root_uri="file:///path/to/test/project/root/",
workspace_folders=[
types.WorkspaceFolder(
uri="file:///path/to/test/project/root/", name="project"
),
],
)
)

Expand All @@ -67,11 +68,12 @@ async def client(lsp_client: LanguageClient):
await lsp_client.shutdown_session()


@pytest.mark.asyncio(loop_scope="module")
async def test_completion(client: LanguageClient):
result = await client.text_document_completion_async(
params=CompletionParams(
position=Position(line=5, character=23),
text_document=TextDocumentIdentifier(
params=types.CompletionParams(
position=types.Position(line=5, character=23),
text_document=types.TextDocumentIdentifier(
uri="file:///path/to/test/project/root/test_file.rst"
),
)
Expand Down
24 changes: 13 additions & 11 deletions lib/pytest-lsp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ See the [documentation](https://lsp-devtools.readthedocs.io/en/latest/) for deta
```python
import sys

import pytest
import pytest_lsp
from lsprotocol.types import (
CompletionParams,
InitializeParams,
Position,
TextDocumentIdentifier,
)
from lsprotocol import types
from pytest_lsp import (
ClientServerConfig,
LanguageClient,
Expand All @@ -27,16 +23,21 @@ from pytest_lsp import (


@pytest_lsp.fixture(
scope="module",
config=ClientServerConfig(
server_command=[sys.executable, "-m", "esbonio"],
),
)
async def client(lsp_client: LanguageClient):
# Setup
response = await lsp_client.initialize_session(
InitializeParams(
types.InitializeParams(
capabilities=client_capabilities("visual-studio-code"),
root_uri="file:///path/to/test/project/root/",
workspace_folders=[
types.WorkspaceFolder(
uri="file:///path/to/test/project/root/", name="project"
),
],
)
)

Expand All @@ -46,11 +47,12 @@ async def client(lsp_client: LanguageClient):
await lsp_client.shutdown_session()


@pytest.mark.asyncio(loop_scope="module")
async def test_completion(client: LanguageClient):
result = await client.text_document_completion_async(
params=CompletionParams(
position=Position(line=5, character=23),
text_document=TextDocumentIdentifier(
params=types.CompletionParams(
position=types.Position(line=5, character=23),
text_document=types.TextDocumentIdentifier(
uri="file:///path/to/test/project/root/test_file.rst"
),
)
Expand Down

0 comments on commit 9e7ed84

Please sign in to comment.