Skip to content

Commit

Permalink
Merge pull request #168 from swyddfa/develop
Browse files Browse the repository at this point in the history
New Release
  • Loading branch information
alcarney authored May 22, 2024
2 parents 084f934 + ccb8b36 commit 439c6b7
Show file tree
Hide file tree
Showing 81 changed files with 2,394 additions and 620 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
target-branch: "develop"
schedule:
interval: "weekly"
4 changes: 2 additions & 2 deletions .github/workflows/capabilities-nvim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
capture:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.11"

Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/lsp-devtools-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: pip
Expand All @@ -31,7 +31,7 @@ jobs:
./scripts/make_release.py lsp-devtools
name: Set Version
- uses: hynek/build-and-inspect-python-package@v1
- uses: hynek/build-and-inspect-python-package@v2
with:
path: lib/lsp-devtools

Expand All @@ -45,10 +45,10 @@ jobs:
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
allow-prereleases: true
python-version: ${{ matrix.python-version }}
Expand All @@ -58,13 +58,11 @@ jobs:
- run: |
python --version
python -m pip install --upgrade pip
python -m pip install --upgrade tox
python -m pip install --upgrade hatch
name: Setup Environment
- run: |
cd lib/lsp-devtools
version=$(echo ${{ matrix.python-version }} | tr -d .)
python -m tox run -f "py${version}"
hatch test -i py=${{ matrix.python-version }}
shell: bash
name: Run Tests
4 changes: 2 additions & 2 deletions .github/workflows/lsp-devtools-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"

Expand All @@ -44,7 +44,7 @@ jobs:
hatch build
- name: 'Upload Artifact'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: 'dist'
path: lib/lsp-devtools/dist
Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/pytest-lsp-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: pip
Expand All @@ -31,7 +31,7 @@ jobs:
./scripts/make_release.py pytest-lsp
name: Set Version
- uses: hynek/build-and-inspect-python-package@v1
- uses: hynek/build-and-inspect-python-package@v2
with:
path: lib/pytest-lsp

Expand All @@ -45,10 +45,10 @@ jobs:
os: [ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
allow-prereleases: true
python-version: ${{ matrix.python-version }}
Expand All @@ -58,13 +58,11 @@ jobs:
- run: |
python --version
python -m pip install --upgrade pip
python -m pip install --upgrade tox
python -m pip install --upgrade hatch
name: Setup Environment
- run: |
cd lib/pytest-lsp
version=$(echo ${{ matrix.python-version }} | tr -d .)
python -m tox run -f "py${version}"
hatch test -i py=${{ matrix.python-version }}
shell: bash
name: Run Tests
4 changes: 2 additions & 2 deletions .github/workflows/pytest-lsp-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"

Expand All @@ -44,7 +44,7 @@ jobs:
hatch build
- name: 'Upload Artifact'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: 'dist'
path: lib/pytest-lsp/dist
Expand Down
39 changes: 9 additions & 30 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,25 @@ exclude: '.bumpversion.cfg$'
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
exclude: 'lib/pytest-lsp/pytest_lsp/clients/.*\.json'
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 24.1.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: black
- id: ruff
args: [--fix]
files: 'lib/.*\.py'

- repo: https://github.com/PyCQA/flake8
rev: 7.0.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.13.2
hooks:
- id: isort
name: isort (lsp-devtools)
args: [--settings-file, lib/lsp-devtools/pyproject.toml]
files: 'lib/lsp-devtools/lsp_devtools/.*\.py'

- id: isort
name: isort (pytest-lsp)
args: [--settings-file, lib/pytest-lsp/pyproject.toml]
files: 'lib/pytest-lsp/pytest_lsp/.*\.py'
- id: ruff-format
files: 'lib/.*\.py'

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.8.0'
rev: 'v1.10.0'
hooks:
- id: mypy
name: mypy (pytest-lsp)
Expand Down
3 changes: 3 additions & 0 deletions docs/ext/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ def get_client_support_for(self, capability: str):

supported_values = set(supported_values)
for value in clients[name]:
if value not in supported_values:
continue

if (existing := clients[name][value]) is None:
clients[name][value] = version
else:
Expand Down
260 changes: 233 additions & 27 deletions docs/lsp-devtools/guide/example-to-file-output.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/lsp-devtools/changes/157.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All `lsp-devtools` commands should no longer crash when encountering messages containing unicode characters
1 change: 1 addition & 0 deletions lib/lsp-devtools/changes/158.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Commands like `lsp-devtools record` should now continue to function after encountering an error
1 change: 1 addition & 0 deletions lib/lsp-devtools/changes/165.enhancement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The `lsp-devtools agent` now forwards the server's `stderr` channel
7 changes: 7 additions & 0 deletions lib/lsp-devtools/hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ include = ["lsp_devtools", "tests", "CHANGES.md"]

[build.targets.wheel]
packages = ["lsp_devtools"]

[envs.hatch-test]
extra-dependencies = ["pytest-asyncio"]

[envs.hatch-static-analysis]
config-path = "ruff_defaults.toml"
dependencies = ["ruff==0.4.4"]
53 changes: 12 additions & 41 deletions lib/lsp-devtools/lsp_devtools/agent/__init__.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,34 @@
import argparse
import asyncio
import logging
import subprocess
import sys
from typing import List
from uuid import uuid4

from .agent import Agent
from .agent import RPCMessage
from .agent import logger
from .agent import parse_rpc_message
from .client import AgentClient
from .protocol import MESSAGE_TEXT_NOTIFICATION
from .protocol import MessageText
from .server import AgentServer
from .server import parse_rpc_message

__all__ = [
"Agent",
"AgentClient",
"AgentServer",
"RPCMessage",
"logger",
"MESSAGE_TEXT_NOTIFICATION",
"MessageText",
"parse_rpc_message",
]


class MessageHandler(logging.Handler):
"""Logging handler that forwards captured JSON-RPC messages through to the
``AgentServer`` instance."""
async def forward_stderr(server: asyncio.subprocess.Process):
"""Forward the server's stderr to the agent's stderr."""
if server.stderr is None:
return

def __init__(self, client: AgentClient, *args, **kwargs):
super().__init__(*args, **kwargs)
self.client = client
self.session = str(uuid4())
self._buffer: List[MessageText] = []

def emit(self, record: logging.LogRecord):
message = MessageText(
text=record.args[0], # type: ignore
session=self.session,
timestamp=record.created,
source=record.__dict__["source"],
)

if not self.client.connected:
self._buffer.append(message)
return

# Send any buffered messages
while len(self._buffer) > 0:
self.client.protocol.message_text_notification(self._buffer.pop(0))

self.client.protocol.message_text_notification(message)
# EOF is signalled with an empty bytestring
while (line := await server.stderr.readline()) != b"":
sys.stderr.buffer.write(line)


async def main(args, extra: List[str]):
Expand All @@ -60,26 +37,20 @@ async def main(args, extra: List[str]):
return 1

command, *arguments = extra

server = await asyncio.create_subprocess_exec(
command,
*arguments,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
agent = Agent(server, sys.stdin.buffer, sys.stdout.buffer)

client = AgentClient()
handler = MessageHandler(client)
handler.setLevel(logging.INFO)

logger.setLevel(logging.INFO)
logger.addHandler(handler)
agent = Agent(server, sys.stdin.buffer, sys.stdout.buffer, client.forward_message)

await asyncio.gather(
client.start_tcp(args.host, args.port),
agent.start(),
forward_stderr(server),
)


Expand Down
Loading

0 comments on commit 439c6b7

Please sign in to comment.