Skip to content

Commit 2ed5b5b

Browse files
committed
Raise an error in WM addDir if starting ERs fails. If project is provided in CLI run options, start ERs only in it. More migration from apischema to cattrs in WM.
1 parent 3e03ec5 commit 2ed5b5b

5 files changed

Lines changed: 23 additions & 10 deletions

File tree

src/finecode/cli_app/commands/run_cmd.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,15 @@ async def _ignore_tree_changed(params: dict) -> None:
129129

130130
client.on_notification("actions/treeChanged", _ignore_tree_changed)
131131

132-
await client.add_dir(workdir_path)
132+
# When a project filter is given and we own the server, discover
133+
# projects first (no runners), resolve names to paths, then start
134+
# runners only for the requested projects. In shared-server mode
135+
# runners are already running, so always use the normal path.
136+
deferred_runner_start = own_server and projects_names is not None
137+
try:
138+
await client.add_dir(workdir_path, start_runners=not deferred_runner_start)
139+
except ApiError as exc:
140+
raise RunFailed(str(exc)) from exc
133141

134142
# Resolve project names (CLI option) to paths (canonical API identifier).
135143
project_paths: list[str] | None = None
@@ -145,6 +153,12 @@ async def _ignore_tree_changed(params: dict) -> None:
145153
p["path"] for p in all_projects if p["name"] in projects_names
146154
]
147155

156+
if deferred_runner_start:
157+
try:
158+
await client.start_runners(projects=project_paths)
159+
except ApiError as exc:
160+
raise RunFailed(str(exc)) from exc
161+
148162
# Resolve action names to sources (ADR-0019).
149163
all_actions = await client.list_actions()
150164
name_to_source: dict[str, str] = {a["name"]: a["source"] for a in all_actions}

src/finecode/lsp_server/endpoints/code_actions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from pathlib import Path
44
from typing import TYPE_CHECKING, Any
55

6-
import apischema
76
from loguru import logger
87
from lsprotocol import types
98

9+
from finecode._converter import converter as _converter
1010
from finecode.lsp_server import global_state, pygls_types_utils
1111
from finecode_extension_api.actions.code_quality.code_action_types import (
1212
CodeAction,
@@ -168,7 +168,7 @@ async def document_code_action(
168168
if json_result is None:
169169
return []
170170

171-
result = apischema.deserialize(GetCodeActionsRunResult, json_result)
171+
result = _converter.structure(json_result, GetCodeActionsRunResult)
172172

173173
return [_code_action_to_lsp(action) for action in result.actions]
174174

src/finecode/lsp_server/endpoints/diagnostics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
from pathlib import Path
55
from typing import TYPE_CHECKING, cast
66

7-
import apischema
87
from loguru import logger
98
from lsprotocol import types
109

10+
from finecode._converter import converter as _converter
1111
from finecode.lsp_server import global_state, pygls_types_utils
1212
from finecode_extension_api.actions.code_quality import lint_action
1313
from finecode_extension_api.resource_uri import ResourceUri
@@ -100,7 +100,7 @@ async def document_diagnostic_with_full_result(
100100
json_result = (response.get("resultByFormat") or {}).get("json")
101101
if json_result is None:
102102
return None
103-
lint_result = apischema.deserialize(lint_action.LintRunResult, json_result)
103+
lint_result = _converter.structure(json_result, lint_action.LintRunResult)
104104

105105
try:
106106
requested_file_messages = lint_result.messages.pop(
@@ -261,7 +261,7 @@ async def workspace_diagnostic_with_full_result() -> types.WorkspaceDiagnosticRe
261261
json_result = (response.get("resultByFormat") or {}).get("json")
262262
if not json_result:
263263
return types.WorkspaceDiagnosticReport(items=[])
264-
lint_result = apischema.deserialize(lint_action.LintRunResult, json_result)
264+
lint_result = _converter.structure(json_result, lint_action.LintRunResult)
265265

266266
items: list[types.WorkspaceDocumentDiagnosticReport] = []
267267
for file_uri, lint_messages in lint_result.messages.items():

src/finecode/lsp_server/endpoints/formatting.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
from typing import TYPE_CHECKING, cast
44

5-
import apischema
65
from loguru import logger
76
from lsprotocol import types
87

8+
from finecode._converter import converter as _converter
99
from finecode.lsp_server import global_state, pygls_types_utils
1010
from finecode_extension_api.actions.code_quality import format_files_action
1111
from finecode_extension_api.resource_uri import ResourceUri
@@ -49,9 +49,7 @@ async def format_document(_ls: LspServer, params: types.DocumentFormattingParams
4949
if json_result is None:
5050
return []
5151

52-
format_result = apischema.deserialize(
53-
format_files_action.FormatFilesRunResult, json_result
54-
)
52+
format_result = _converter.structure(json_result, format_files_action.FormatFilesRunResult)
5553

5654
response_for_file = format_result.result_by_file_path.get(
5755
cast(ResourceUri, file_uri)

src/finecode/wm_server/_api_handlers/_workspace.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ async def _handle_add_dir(
219219
f"Did you run `finecode prepare-envs`?",
220220
"type": "ERROR",
221221
})
222+
raise
222223

223224
# If config overrides were set before this addDir call (e.g. standalone CLI mode),
224225
# apply them to the newly discovered projects and push to their running runners.

0 commit comments

Comments
 (0)