Skip to content

Commit

Permalink
Merge pull request #184 from swyddfa/develop
Browse files Browse the repository at this point in the history
New Release
  • Loading branch information
alcarney authored Sep 4, 2024
2 parents b713dcb + 14e5177 commit 9cd024a
Show file tree
Hide file tree
Showing 44 changed files with 267 additions and 227 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pytest-lsp-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
os: [ubuntu-latest, windows-latest]

steps:
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.8
rev: v0.5.2
hooks:
- id: ruff
args: [--fix]
Expand All @@ -20,7 +20,7 @@ repos:
files: 'lib/.*\.py'

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.10.0'
rev: 'v1.10.1'
hooks:
- id: mypy
name: mypy (pytest-lsp)
Expand Down
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
1 change: 1 addition & 0 deletions docs/pytest-lsp/howto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ How To
:maxdepth: 2

Integrate with lsp-devtools <howto/integrate-with-lsp-devtools>
Migrate to v1 <howto/migrate-to-v1>
Test Generic JSON-RPC Servers <howto/testing-json-rpc-servers>
27 changes: 27 additions & 0 deletions docs/pytest-lsp/howto/migrate-to-v1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
How To Migrate to v1
====================

The ``v1`` release of ``pytest-lsp`` contains some breaking changes, mostly as a result of changes in the wider ecosystem.
This guide summarises the changes and provides references on where to get more details.

Python Support
--------------

This release removes support for Python 3.8 and adds support for Python 3.13.

``pytest``
----------

This release removes support for pytest ``v7``, if you have not done so already please update to pytest ``v8``.


``pytest-asyncio``
------------------

The minimum required version for ``pytest-asyncio`` is now ``0.24``, see `this guide <https://pytest-asyncio.readthedocs.io/en/latest/how-to-guides/migrate_from_0_23.html>`__ for details on upgrading

``pygls``
---------

``pygls``, the underlying language server protocol implementation used by ``pytest-lsp`` has been upgraded to ``v2``.
See `this guide <https://pygls.readthedocs.io/en/latest/howto/migrate-to-v2.html>`__ for details on the breaking changes this brings.
2 changes: 1 addition & 1 deletion lib/lsp-devtools/hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ extra-dependencies = ["pytest-asyncio"]

[envs.hatch-static-analysis]
config-path = "ruff_defaults.toml"
dependencies = ["ruff==0.4.8"]
dependencies = ["ruff==0.5.2"]
13 changes: 5 additions & 8 deletions lib/lsp-devtools/ruff_defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ select = [
"ARG003",
"ARG004",
"ARG005",
"ASYNC100",
"ASYNC101",
"ASYNC102",
"ASYNC210",
"ASYNC220",
"ASYNC221",
"ASYNC230",
"ASYNC251",
"B002",
"B003",
"B004",
Expand Down Expand Up @@ -463,11 +465,6 @@ select = [
"TID251",
"TID252",
"TID253",
"TRIO100",
"TRIO105",
"TRIO109",
"TRIO110",
"TRIO115",
"TRY002",
"TRY003",
"TRY004",
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
1 change: 1 addition & 0 deletions lib/pytest-lsp/changes/177.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Migrate to pygls v2
1 change: 1 addition & 0 deletions lib/pytest-lsp/changes/178.breaking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drop Python 3.8 support
1 change: 1 addition & 0 deletions lib/pytest-lsp/changes/180.breaking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drop support for pytest v7
1 change: 1 addition & 0 deletions lib/pytest-lsp/changes/180.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for Python 3.13
1 change: 1 addition & 0 deletions lib/pytest-lsp/changes/182.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bump minimum `pytest-asyncio` verision to `v0.24`
10 changes: 6 additions & 4 deletions lib/pytest-lsp/hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ packages = ["pytest_lsp"]
[envs.hatch-test]
dependencies = ["pytest-asyncio"]

[envs.hatch-test.env-vars]
UV_PRERELEASE="allow"

[[envs.hatch-test.matrix]]
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]
pytest = ["7", "8"]
python = ["3.9", "3.10", "3.11", "3.12", "3.13"]
pytest = ["8"]

[envs.hatch-test.overrides]
matrix.pytest.dependencies = [
{ value = "pytest>=7,<8", if = ["7"] },
{ value = "pytest>=8,<9", if = ["8"] },
]

[envs.hatch-static-analysis]
config-path = "ruff_defaults.toml"
dependencies = ["ruff==0.4.8"]
dependencies = ["ruff==0.5.2"]
12 changes: 6 additions & 6 deletions lib/pytest-lsp/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,27 @@ name = "pytest-lsp"
dynamic = ["version"]
description = "A pytest plugin for end-to-end testing of language servers"
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.9"
license = { text = "MIT" }
authors = [{ name = "Alex Carney", email = "alcarneyme@gmail.com" }]
classifiers = [
"Development Status :: 3 - Alpha",
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
"Framework :: Pytest",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
dependencies = [
"importlib-resources; python_version<\"3.9\"",
"packaging",
"pygls>=1.1.0",
"pygls>=2.0.0a1",
"pytest",
"pytest-asyncio>=0.23",
"pytest-asyncio>=0.24",
]

[project.urls]
Expand All @@ -49,6 +48,7 @@ sort = "Cover"

[tool.pytest.ini_options]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"

[tool.towncrier]
filename = "CHANGES.md"
Expand Down
3 changes: 0 additions & 3 deletions lib/pytest-lsp/pyrightconfig.json

This file was deleted.

17 changes: 8 additions & 9 deletions lib/pytest-lsp/pytest_lsp/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
"""

from __future__ import annotations

# ruff: noqa: S101
import logging
import warnings
from typing import Any
from typing import Callable
from typing import Dict
from typing import List
from typing import Optional
from typing import Set
from typing import Union

from lsprotocol import types
Expand All @@ -27,8 +26,8 @@
ParamsChecker = Callable[[types.ClientCapabilities, Any], None]
ResultChecker = Callable[[types.ClientCapabilities, Any], None]

PARAMS_CHECKS: Dict[str, ParamsChecker] = {}
RESULT_CHECKS: Dict[str, ResultChecker] = {}
PARAMS_CHECKS: dict[str, ParamsChecker] = {}
RESULT_CHECKS: dict[str, ResultChecker] = {}


class LspSpecificationWarning(UserWarning):
Expand Down Expand Up @@ -135,7 +134,7 @@ def check_params_against_client_capabilities(
def check_completion_item(
item: types.CompletionItem,
commit_characters_support: bool,
documentation_formats: Set[str],
documentation_formats: set[str],
snippet_support: bool,
):
"""Ensure that the given ``CompletionItem`` complies with the given capabilities."""
Expand All @@ -155,7 +154,7 @@ def check_completion_item(
@check_result_for(method=types.TEXT_DOCUMENT_COMPLETION)
def completion_items(
capabilities: types.ClientCapabilities,
result: Union[types.CompletionList, List[types.CompletionItem], None],
result: Union[types.CompletionList, list[types.CompletionItem], None],
):
"""Ensure that the completion items returned from the server are compliant with the
spec and the client's declared capabilities."""
Expand Down Expand Up @@ -230,7 +229,7 @@ def completion_item_resolve(

@check_result_for(method=types.TEXT_DOCUMENT_DOCUMENT_LINK)
def document_links(
capabilities: types.ClientCapabilities, result: Optional[List[types.DocumentLink]]
capabilities: types.ClientCapabilities, result: Optional[list[types.DocumentLink]]
):
"""Ensure that the document links returned from the server are compliant with the
Spec and the client's declared capabilities."""
Expand Down Expand Up @@ -261,7 +260,7 @@ def work_done_progress_create(
@check_params_of(method=types.WORKSPACE_CONFIGURATION)
def workspace_configuration(
capabilities: types.ClientCapabilities,
params: types.WorkspaceConfigurationParams,
params: types.ConfigurationParams,
):
"""Ensure that the client has support for ``workspace/configuration`` requests."""
is_supported = get_capability(capabilities, "workspace.configuration", False)
Expand Down
Loading

0 comments on commit 9cd024a

Please sign in to comment.