Skip to content

Commit f5fd7be

Browse files
committed
backup
1 parent d555a9a commit f5fd7be

File tree

13 files changed

+126
-45
lines changed

13 files changed

+126
-45
lines changed

src/lsp_client/clients/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import override
55

66
from lsp_client.client.abc import Client
7-
from lsp_client.client.lang import LanguageConfig
7+
from lsp_client.protocol.lang import LanguageConfig
88
from lsp_client.utils.types import lsp_type
99

1010

src/lsp_client/protocol/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
"""LSP protocol abstractions and type definitions.
2+
3+
This module defines the protocol interfaces for LSP client capabilities,
4+
server request/notification hooks, and client operations.
5+
"""
6+
17
from __future__ import annotations
28

39
from .capability import (

src/lsp_client/protocol/capability.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""LSP capability protocols defining client-side capability registration.
2+
3+
Provides protocol interfaces for different LSP capability categories:
4+
workspace, text document, notebook, window, general, and experimental capabilities.
5+
Each protocol defines methods for registering client capabilities with the server.
6+
"""
7+
18
from __future__ import annotations
29

310
from abc import abstractmethod

src/lsp_client/protocol/client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
"""LSP client protocol defining the minimal interface for LSP operations.
2+
3+
Provides the CapabilityClientProtocol that defines required methods for
4+
workspace management, configuration access, file operations, and LSP message handling.
5+
"""
6+
17
from __future__ import annotations
28

39
from abc import abstractmethod
410
from collections.abc import AsyncGenerator
511
from contextlib import asynccontextmanager
612
from pathlib import Path
7-
from typing import TYPE_CHECKING, Protocol, runtime_checkable
13+
from typing import Protocol, runtime_checkable
814

915
import anyio
1016

@@ -13,8 +19,7 @@
1319
from lsp_client.utils.uri import from_local_uri
1420
from lsp_client.utils.workspace import DEFAULT_WORKSPACE_DIR, Workspace
1521

16-
if TYPE_CHECKING:
17-
from lsp_client.client.lang import LanguageConfig
22+
from .lang import LanguageConfig
1823

1924

2025
@runtime_checkable

src/lsp_client/protocol/hook.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
"""Server request and notification hook system for LSP client.
2+
3+
Defines hooks for handling server-initiated requests and notifications,
4+
with a registry for managing and dispatching these hooks.
5+
"""
6+
17
from __future__ import annotations
28

39
from typing import Protocol, runtime_checkable
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
"""Language-specific configuration for LSP clients.
2+
3+
Provides LanguageConfig for defining language properties including file suffixes,
4+
project markers, and project root detection logic.
5+
"""
6+
17
from __future__ import annotations
28

39
from pathlib import Path

src/lsp_client/server/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .error import ServerError, ServerInstallationError, ServerRuntimeError
77
from .local import LocalServer
88
from .socket import SocketServer
9+
from .types import ServerType
910

1011
__all__ = [
1112
"ContainerServer",
@@ -15,5 +16,6 @@
1516
"ServerError",
1617
"ServerInstallationError",
1718
"ServerRuntimeError",
19+
"ServerType",
1820
"SocketServer",
1921
]

src/lsp_client/server/abc.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from __future__ import annotations
22

33
from abc import ABC, abstractmethod
4-
from collections.abc import AsyncGenerator, Sequence
4+
from collections.abc import AsyncGenerator
55
from contextlib import asynccontextmanager
66
from typing import Self
77

88
import asyncer
9-
from attrs import Factory, define, field
9+
from attrs import define, field
1010
from loguru import logger
1111

1212
from lsp_client.jsonrpc.channel import ResponseTable, response_channel
@@ -23,7 +23,7 @@
2323

2424
@define(kw_only=True)
2525
class Server(ABC):
26-
args: Sequence[str] = Factory(list)
26+
"""Base server implementation with JSON-RPC protocol handling."""
2727

2828
_resp_table: ResponseTable = field(factory=ResponseTable, init=False)
2929

@@ -43,11 +43,6 @@ async def receive(self) -> RawPackage | None:
4343
async def kill(self) -> None:
4444
"""Kill the runtime process."""
4545

46-
@abstractmethod
47-
@asynccontextmanager
48-
def run_process(self, workspace: Workspace) -> AsyncGenerator[None]:
49-
"""Run the server process."""
50-
5146
async def _dispatch(self, sender: Sender[ServerRequest] | None) -> None:
5247
if not sender:
5348
logger.warning(
@@ -85,16 +80,12 @@ async def request(self, request: RawRequest) -> RawResponsePackage:
8580
async def notify(self, notification: RawNotification) -> None:
8681
await self.send(notification)
8782

83+
@abstractmethod
8884
@asynccontextmanager
89-
async def run(
85+
def run(
9086
self,
9187
workspace: Workspace,
9288
*,
9389
sender: Sender[ServerRequest] | None = None,
9490
) -> AsyncGenerator[Self]:
95-
async with (
96-
self.run_process(workspace),
97-
asyncer.create_task_group() as tg,
98-
):
99-
tg.soonify(self._dispatch)(sender)
100-
yield self
91+
"""Run the server."""

src/lsp_client/server/container.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
from collections.abc import AsyncGenerator
55
from contextlib import asynccontextmanager
66
from pathlib import Path
7-
from typing import Literal, final, override
7+
from typing import Literal, Self, final, override
88

99
import anyio
1010
from attrs import Factory, define, field
1111
from loguru import logger
1212

1313
from lsp_client.jsonrpc.parse import RawPackage
14+
from lsp_client.server.types import ServerRequest
15+
from lsp_client.utils.channel import Sender
1416
from lsp_client.utils.workspace import Workspace
1517

1618
from .abc import Server
@@ -207,12 +209,17 @@ async def check_availability(self) -> None:
207209
"could not be pulled."
208210
) from e
209211

210-
@override
211212
@asynccontextmanager
212-
async def run_process(self, workspace: Workspace) -> AsyncGenerator[None]:
213+
async def run(
214+
self,
215+
workspace: Workspace,
216+
*,
217+
sender: Sender[ServerRequest] | None = None,
218+
) -> AsyncGenerator[Self]:
213219
args = self.format_args(workspace)
214220
logger.debug("Running docker runtime with command: {}", args)
215221

216222
self._local = LocalServer(program=self.backend, args=args)
217-
async with self._local.run_process(workspace):
218-
yield
223+
224+
async with self._local.run(workspace, sender=sender):
225+
yield self

src/lsp_client/server/default.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,46 @@
11
from __future__ import annotations
22

3+
from collections.abc import AsyncIterator
4+
from contextlib import suppress
5+
36
from attrs import frozen
47

8+
from .abc import Server
59
from .container import ContainerServer
10+
from .error import ServerRuntimeError
611
from .local import LocalServer
12+
from .types import ServerType
713

814

915
@frozen
1016
class DefaultServers:
1117
local: LocalServer
1218
container: ContainerServer
19+
20+
async def iter_candidate(
21+
self,
22+
*,
23+
server: Server | ServerType = "local",
24+
) -> AsyncIterator[Server]:
25+
"""
26+
Server candidates in order of priority:
27+
1. User-provided server
28+
2. Local server (if available)
29+
3. Containerized server
30+
4. Local server with auto-install (if enabled)
31+
"""
32+
33+
match server:
34+
case "container":
35+
yield self.container
36+
case "local":
37+
yield self.local
38+
case Server() as server:
39+
yield server
40+
41+
with suppress(ServerRuntimeError):
42+
await self.local.check_availability()
43+
yield self.local
44+
45+
yield self.container
46+
yield self.local

0 commit comments

Comments
 (0)