Skip to content

Commit

Permalink
Add LSP integration tests (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Dec 23, 2022
1 parent 3fb2531 commit b5cac85
Show file tree
Hide file tree
Showing 13 changed files with 670 additions and 32 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10" ]
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
poetry-version: [ "1.1.15" ]
os: [ ubuntu-18.04, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
Expand All @@ -27,8 +27,10 @@ jobs:
- name: Install dependencies
run: poetry install
- name: Run Ruff
run: poetry run ruff ./ruff_lsp
run: poetry run ruff ./ruff_lsp ./tests
- name: Run Black
run: poetry run black --check ./ruff_lsp
run: poetry run black --check ./ruff_lsp ./tests
- name: Run Mypy
run: poetry run mypy ./ruff_lsp
run: poetry run mypy ./ruff_lsp ./tests
- name: Run unittest
run: poetry run python -m unittest
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
fmt:
poetry run ruff --fix ./ruff_lsp
poetry run black ./ruff_lsp
poetry run ruff --fix ./ruff_lsp ./tests
poetry run black ./ruff_lsp ./tests

check:
poetry run ruff ./ruff_lsp
poetry run black --check ./ruff_lsp
poetry run mypy ./ruff_lsp
poetry run ruff ./ruff_lsp ./tests
poetry run black --check ./ruff_lsp ./tests
poetry run mypy ./ruff_lsp ./tests

.PHONY: fmt check
test:
poetry run python -m unittest tests

.PHONY: fmt check test
135 changes: 114 additions & 21 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Libraries :: Python Modules",
Expand All @@ -41,6 +42,7 @@ typing_extensions = "*"
[tool.poetry.dev-dependencies]
black = "==22.12.0"
mypy = "==0.991"
python-jsonrpc-server = "^0.4.0"

[tool.ruff]
line-length = 88
Expand All @@ -54,12 +56,15 @@ select = [
"N",
]
target-version = "py37"
extend-exclude = ["tests/data"]

[tool.black]
line-length = 88
extend-exclude = "tests/data"

[tool.mypy]
files = "ruff_lsp"
files = ["ruff_lsp", "tests"]
exclude = "tests/data"
no_implicit_optional = true
check_untyped_defs = true

Expand All @@ -68,5 +73,6 @@ module = [
"debugpy.*",
"lsprotocol.*",
"pygls.*",
"pyls_jsonrpc.*",
]
ignore_missing_imports = true
1 change: 1 addition & 0 deletions ruff_lsp/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Implementation of the LSP server for Ruff."""


from __future__ import annotations

import copy
Expand Down
Empty file added tests/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions tests/client/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
8 changes: 8 additions & 0 deletions tests/client/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""Constants for use with tests."""
from __future__ import annotations

import pathlib

TEST_ROOT = pathlib.Path(__file__).parent.parent
TEST_DATA = TEST_ROOT / "data"
PROJECT_ROOT = TEST_ROOT.parent
216 changes: 216 additions & 0 deletions tests/client/defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
"""Default initialize request params."""
from __future__ import annotations

import os

from tests.client.constants import PROJECT_ROOT
from tests.client.utils import as_uri

VSCODE_DEFAULT_INITIALIZE = {
"processId": os.getpid(),
"clientInfo": {"name": "vscode", "version": "1.45.0"},
"rootPath": str(PROJECT_ROOT),
"rootUri": as_uri(str(PROJECT_ROOT)),
"capabilities": {
"workspace": {
"applyEdit": True,
"workspaceEdit": {
"documentChanges": True,
"resourceOperations": ["create", "rename", "delete"],
"failureHandling": "textOnlyTransactional",
},
"didChangeConfiguration": {"dynamicRegistration": True},
"didChangeWatchedFiles": {"dynamicRegistration": True},
"symbol": {
"dynamicRegistration": True,
"symbolKind": {
"valueSet": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
]
},
"tagSupport": {"valueSet": [1]},
},
"executeCommand": {"dynamicRegistration": True},
"configuration": True,
"workspaceFolders": True,
},
"textDocument": {
"publishDiagnostics": {
"relatedInformation": True,
"versionSupport": False,
"tagSupport": {"valueSet": [1, 2]},
"complexDiagnosticCodeSupport": True,
},
"synchronization": {
"dynamicRegistration": True,
"willSave": True,
"willSaveWaitUntil": True,
"didSave": True,
},
"completion": {
"dynamicRegistration": True,
"contextSupport": True,
"completionItem": {
"snippetSupport": True,
"commitCharactersSupport": True,
"documentationFormat": ["markdown", "plaintext"],
"deprecatedSupport": True,
"preselectSupport": True,
"tagSupport": {"valueSet": [1]},
"insertReplaceSupport": True,
},
"completionItemKind": {
"valueSet": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
]
},
},
"hover": {
"dynamicRegistration": True,
"contentFormat": ["markdown", "plaintext"],
},
"signatureHelp": {
"dynamicRegistration": True,
"signatureInformation": {
"documentationFormat": ["markdown", "plaintext"],
"parameterInformation": {"labelOffsetSupport": True},
},
"contextSupport": True,
},
"definition": {"dynamicRegistration": True, "linkSupport": True},
"references": {"dynamicRegistration": True},
"documentHighlight": {"dynamicRegistration": True},
"documentSymbol": {
"dynamicRegistration": True,
"symbolKind": {
"valueSet": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
]
},
"hierarchicalDocumentSymbolSupport": True,
"tagSupport": {"valueSet": [1]},
},
"codeAction": {
"dynamicRegistration": True,
"isPreferredSupport": True,
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"",
"quickfix",
"refactor",
"refactor.extract",
"refactor.inline",
"refactor.rewrite",
"source",
"source.organizeImports",
]
}
},
},
"codeLens": {"dynamicRegistration": True},
"formatting": {"dynamicRegistration": True},
"rangeFormatting": {"dynamicRegistration": True},
"onTypeFormatting": {"dynamicRegistration": True},
"rename": {"dynamicRegistration": True, "prepareSupport": True},
"documentLink": {
"dynamicRegistration": True,
"tooltipSupport": True,
},
"typeDefinition": {
"dynamicRegistration": True,
"linkSupport": True,
},
"implementation": {
"dynamicRegistration": True,
"linkSupport": True,
},
"colorProvider": {"dynamicRegistration": True},
"foldingRange": {
"dynamicRegistration": True,
"rangeLimit": 5000,
"lineFoldingOnly": True,
},
"declaration": {"dynamicRegistration": True, "linkSupport": True},
"selectionRange": {"dynamicRegistration": True},
},
"window": {"workDoneProgress": True},
},
"trace": "verbose",
"workspaceFolders": [{"uri": as_uri(str(PROJECT_ROOT)), "name": "my_project"}],
"initializationOptions": {},
}
Loading

0 comments on commit b5cac85

Please sign in to comment.