Skip to content

Commit

Permalink
lsp-devtools: Update tox definition
Browse files Browse the repository at this point in the history
Also
- Comment out websocket code for now
- Fix tests
- Enable coverage
  • Loading branch information
alcarney committed Aug 19, 2023
1 parent a56dac7 commit 5a18119
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.coverage
.env
.tox
*.pyc
Expand Down
27 changes: 14 additions & 13 deletions lib/lsp-devtools/lsp_devtools/agent/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@
from pygls.client import Client
from pygls.client import aio_readline
from pygls.protocol import default_converter
from websockets.client import WebSocketClientProtocol

from lsp_devtools.agent.protocol import AgentProtocol

# from websockets.client import WebSocketClientProtocol

class WebSocketClientTransportAdapter:
"""Protocol adapter for the WebSocket client interface."""

def __init__(self, ws: WebSocketClientProtocol, loop: asyncio.AbstractEventLoop):
self._ws = ws
self._loop = loop
# class WebSocketClientTransportAdapter:
# """Protocol adapter for the WebSocket client interface."""

def close(self) -> None:
"""Stop the WebSocket server."""
print("-- CLOSING --")
self._loop.create_task(self._ws.close())
# def __init__(self, ws: WebSocketClientProtocol, loop: asyncio.AbstractEventLoop):
# self._ws = ws
# self._loop = loop

def write(self, data: Any) -> None:
"""Create a task to write specified data into a WebSocket."""
asyncio.ensure_future(self._ws.send(data))
# def close(self) -> None:
# """Stop the WebSocket server."""
# print("-- CLOSING --")
# self._loop.create_task(self._ws.close())

# def write(self, data: Any) -> None:
# """Create a task to write specified data into a WebSocket."""
# asyncio.ensure_future(self._ws.send(data))


class AgentClient(Client):
Expand Down
2 changes: 1 addition & 1 deletion lib/lsp-devtools/lsp_devtools/record/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class FormatString:
VARIABLE = re.compile(r"{\.([^}]+)}")

def __init__(self, pattern: str):
self.pattern = pattern.replace("\\n", "\n").replace("\\t", "\t")
self.pattern = pattern # .replace("\\n", "\n").replace("\\t", "\t")
self._parse()

def _parse(self):
Expand Down
25 changes: 8 additions & 17 deletions lib/lsp-devtools/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ dev = [
"pre-commit",
"tox",
]
test=[
"pytest-cov",
"pytest-timeout",
]
typecheck=[
"mypy",
"importlib_resources",
Expand All @@ -60,6 +56,14 @@ lsp-devtools = "lsp_devtools.cli:main"
[tool.setuptools.packages.find]
include = ["lsp_devtools*"]

[tool.coverage.run]
source_pkgs = ["lsp_devtools"]

[tool.coverage.report]
show_missing = true
skip_covered = true
sort = "Cover"

[tool.isort]
force_single_line = true
profile = "black"
Expand Down Expand Up @@ -100,16 +104,3 @@ showcontent = true
directory = "misc"
name = "Misc"
showcontent = true

[tool.tox]
legacy_tox_ini = """
[tox]
isolated_build = True
skip_missing_interpreters = true
envlist = py{37,38,39,310,311}
[testenv]
extras=test
commands =
pytest {posargs}
"""
8 changes: 4 additions & 4 deletions lib/lsp-devtools/tests/record/test_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"textDocument": {"uri": "file:///path/to/file.txt"},
},
},
"textDocument/completion file:///path/to/file.txt:{'line': 1, 'character': 2}", # noqa: E501
'textDocument/completion file:///path/to/file.txt:{\n "line": 1,\n "character": 2\n}', # noqa: E501
),
(
"{.method} {.params.textDocument.uri}:{.params.position|Position}",
Expand Down Expand Up @@ -61,7 +61,7 @@
"items": [{"label": "one"}, {"label": "two"}, {"label": "three"}]
}
},
"{'label': 'one'}\n{'label': 'two'}\n{'label': 'three'}",
'{\n "label": "one"\n}\n{\n "label": "two"\n}\n{\n "label": "three"\n}',
),
(
"{.result.items[].label}",
Expand All @@ -88,7 +88,7 @@
"items": [{"label": "one"}, {"label": "two"}, {"label": "three"}]
}
},
"{'label': 'one'}",
'{\n "label": "one"\n}',
),
(
"{.result.items[-1]}",
Expand All @@ -97,7 +97,7 @@
"items": [{"label": "one"}, {"label": "two"}, {"label": "three"}]
}
},
"{'label': 'three'}",
'{\n "label": "three"\n}',
),
(
"- {.result.items[0].label}",
Expand Down
21 changes: 21 additions & 0 deletions lib/lsp-devtools/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tox]
isolated_build = True
skip_missing_interpreters = true
min_version = 4.0
envlist = py{38,39,310,311}

[testenv]
description = "Run lsp-devtools' test suite"
package = wheel
wheel_build_env = .pkg
deps =
coverage[toml]
pytest

git+https://github.com/openlawlibrary/pygls
commands_pre =
coverage erase
commands =
coverage run -m pytest {posargs}
commands_post =
coverage report

0 comments on commit 5a18119

Please sign in to comment.