diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 95e0e84..8764100 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,13 +13,19 @@ repos: rev: 23.11.0 hooks: - id: black - exclude: 'lib/pytest-lsp/pytest_lsp/gen.py' - repo: https://github.com/PyCQA/flake8 rev: 6.1.0 hooks: - id: flake8 + name: flake8 (lsp-devtools) args: [--config=lib/lsp-devtools/setup.cfg] + files: 'lib/lsp-devtools/lsp_devtools/.*\.py' + + - id: flake8 + name: flake8 (pytest-lsp) + args: [--config=lib/pytest-lsp/setup.cfg] + files: 'lib/pytest-lsp/pytest_lsp/.*\.py' - repo: https://github.com/pycqa/isort rev: 5.12.0 @@ -33,7 +39,6 @@ repos: name: isort (pytest-lsp) args: [--settings-file, lib/pytest-lsp/pyproject.toml] files: 'lib/pytest-lsp/pytest_lsp/.*\.py' - exclude: 'lib/pytest-lsp/pytest_lsp/gen.py' - repo: https://github.com/pre-commit/mirrors-mypy rev: 'v1.7.0' diff --git a/lib/pytest-lsp/setup.cfg b/lib/pytest-lsp/setup.cfg index 2bcd70e..6fd2a01 100644 --- a/lib/pytest-lsp/setup.cfg +++ b/lib/pytest-lsp/setup.cfg @@ -1,2 +1,3 @@ [flake8] max-line-length = 88 +ignore = E501 diff --git a/lib/pytest-lsp/tests/test_checks.py b/lib/pytest-lsp/tests/test_checks.py index b5f2db7..a815c90 100644 --- a/lib/pytest-lsp/tests/test_checks.py +++ b/lib/pytest-lsp/tests/test_checks.py @@ -39,6 +39,14 @@ types.WorkspaceConfigurationParams(items=[]), "does not support 'workspace/configuration'", ), + ( + types.ClientCapabilities( + workspace=types.WorkspaceClientCapabilities(configuration=True) + ), + types.WORKSPACE_CONFIGURATION, + types.WorkspaceConfigurationParams(items=[]), + None, + ), ], ) def test_params_check_warning( @@ -92,6 +100,20 @@ def test_params_check_warning( [types.CompletionItem(label="item", commit_characters=["."])], "does not support commit characters", ), + ( + types.ClientCapabilities( + text_document=types.TextDocumentClientCapabilities( + completion=types.CompletionClientCapabilities( + completion_item=types.CompletionClientCapabilitiesCompletionItemType( + commit_characters_support=True + ) + ) + ) + ), + types.TEXT_DOCUMENT_COMPLETION, + [types.CompletionItem(label="item", commit_characters=["."])], + None, + ), ( types.ClientCapabilities( text_document=types.TextDocumentClientCapabilities( @@ -109,6 +131,27 @@ def test_params_check_warning( ], "does not support documentation format 'markdown'", ), + ( + types.ClientCapabilities( + text_document=types.TextDocumentClientCapabilities( + completion=types.CompletionClientCapabilities( + completion_item=types.CompletionClientCapabilitiesCompletionItemType( + documentation_format=[types.MarkupKind.Markdown] + ) + ) + ) + ), + types.TEXT_DOCUMENT_COMPLETION, + [ + types.CompletionItem( + label="item", + documentation=types.MarkupContent( + value="", kind=types.MarkupKind.Markdown + ), + ) + ], + None, + ), ( types.ClientCapabilities( text_document=types.TextDocumentClientCapabilities( @@ -127,19 +170,52 @@ def test_params_check_warning( ( types.ClientCapabilities( text_document=types.TextDocumentClientCapabilities( - document_link=types.DocumentLinkClientCapabilities( - tooltip_support=False + completion=types.CompletionClientCapabilities( + completion_item=types.CompletionClientCapabilitiesCompletionItemType( + snippet_support=True + ) ) ) ), + types.TEXT_DOCUMENT_COMPLETION, + [ + types.CompletionItem( + label="item", + insert_text_format=types.InsertTextFormat.Snippet, + ) + ], + None, + ), + ( + types.ClientCapabilities( + text_document=types.TextDocumentClientCapabilities( + document_link=types.DocumentLinkClientCapabilities() + ) + ), types.TEXT_DOCUMENT_DOCUMENT_LINK, [types.DocumentLink(range=a_range, tooltip="a tooltip")], "does not support tooltips", ), + ( + types.ClientCapabilities( + text_document=types.TextDocumentClientCapabilities( + document_link=types.DocumentLinkClientCapabilities( + tooltip_support=True + ) + ) + ), + types.TEXT_DOCUMENT_DOCUMENT_LINK, + [types.DocumentLink(range=a_range, tooltip="a tooltip")], + None, + ), ], ) def test_result_check_warning( - capabilities: types.ClientCapabilities, method: str, result: Any, expected: str + capabilities: types.ClientCapabilities, + method: str, + result: Any, + expected: Optional[str], + recwarn, ): """Ensure that parameter checks work as expected. @@ -156,7 +232,19 @@ def test_result_check_warning( expected The expected warning message + + recwarn + Builtin fixture from pytest for recording warnings """ - with pytest.warns(checks.LspSpecificationWarning, match=expected): + if expected is None: + checks.check_result_against_client_capabilities(capabilities, method, result) + assert len(recwarn) == 0 + + else: + with pytest.warns(checks.LspSpecificationWarning, match=expected): + checks.check_result_against_client_capabilities( + capabilities, method, result + ) + checks.check_result_against_client_capabilities(capabilities, method, result)