Skip to content

Commit ed1cb11

Browse files
committed
Change message keys in LSP messages for action tree from snake case to camel case
1 parent ae6edaa commit ed1cb11

6 files changed

Lines changed: 58 additions & 31 deletions

File tree

docs/reference/lsp-protocol.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ Server APIs. Params are passed as the `params` array of `executeCommand`.
5151
### Action Tree and Projects
5252

5353
- `finecode.getActions`
54-
- Params: `parent_node_id` (string or `null`)
54+
- Params: `parentNodeId` (string or `null`), or positional string argument
5555
- Returns: action tree under the given node
5656

57+
Action tree node payloads use camelCase fields in the LSP protocol:
58+
`nodeId`, `nodeType`, `subnodes`, `status`, `name`.
59+
5760
- `finecode.getActionsForPosition`
5861
- Params: position object (currently ignored)
5962
- Returns: action tree (currently full tree)

docs/wm-protocol.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,15 @@ Get the hierarchical action tree for IDE sidebar display.
358358
{
359359
"nodes": [
360360
{
361-
"node_id": "ws_dir_0",
361+
"nodeId": "ws_dir_0",
362362
"name": "/path/to/workspace",
363-
"node_type": 0,
363+
"nodeType": 0,
364364
"status": "ok",
365365
"subnodes": [
366366
{
367-
"node_id": "project_0",
367+
"nodeId": "project_0",
368368
"name": "finecode",
369-
"node_type": 1,
369+
"nodeType": 1,
370370
"status": "ok",
371371
"subnodes": []
372372
}
@@ -376,7 +376,7 @@ Get the hierarchical action tree for IDE sidebar display.
376376
}
377377
```
378378

379-
`node_type` values: 0=DIRECTORY, 1=PROJECT, 2=ACTION, 3=ACTION_GROUP, 4=PRESET,
379+
`nodeType` values: 0=DIRECTORY, 1=PROJECT, 2=ACTION, 3=ACTION_GROUP, 4=PRESET,
380380
5=ENV_GROUP, 6=ENV
381381

382382
---
@@ -782,9 +782,9 @@ runner start/stop).
782782
```json
783783
{
784784
"node": {
785-
"node_id": "project_0",
785+
"nodeId": "project_0",
786786
"name": "finecode",
787-
"node_type": 1,
787+
"nodeType": 1,
788788
"status": "ok",
789789
"subnodes": []
790790
}

src/finecode/lsp_server/endpoints/action_tree.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,38 @@
55
from pygls.lsp.server import LanguageServer
66

77

8+
def _parse_parent_node_id(params) -> str | None:
9+
"""Parse getActions executeCommand params (camelCase protocol)."""
10+
if params is None:
11+
return None
12+
13+
if isinstance(params, str):
14+
return params
15+
16+
if isinstance(params, dict):
17+
return params.get("parentNodeId")
18+
19+
if isinstance(params, list):
20+
if len(params) == 0:
21+
return None
22+
first = params[0]
23+
if isinstance(first, str):
24+
return first
25+
if isinstance(first, dict):
26+
return first.get("parentNodeId")
27+
28+
return None
29+
30+
31+
async def notify_changed_action_node(ls: LanguageServer, action_node: dict) -> None:
32+
ls.protocol.notify(method="actionsNodes/changed", params=action_node)
33+
34+
835
async def list_actions(ls: LanguageServer, params):
936
logger.info(f"list_actions {params}")
1037
await global_state.server_initialized.wait()
1138

12-
# params is expected to be a list, but pygls seems to pass the first element of list
13-
# if the list contains only one element. Test after migration from pygls
14-
parent_node_id = params # params[0]
39+
parent_node_id = _parse_parent_node_id(params)
1540

1641
if global_state.wm_client is None:
1742
raise Exception()

src/finecode/lsp_server/lsp_server.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,9 @@ async def _on_initialized(ls: LanguageServer, params: types.InitializedParams):
245245

246246
# Register notification handlers for server→client push messages.
247247
async def on_tree_changed(params: dict) -> None:
248-
# TODO
249-
...
250-
# node = schemas.ActionTreeNode(**params["node"])
251-
# await action_tree_endpoints.notify_changed_action_node(ls, node)
248+
node = params.get("node")
249+
if isinstance(node, dict):
250+
await action_tree_endpoints.notify_changed_action_node(ls, node)
252251

253252
async def on_user_message(params: dict) -> None:
254253
await send_user_message_notification(ls, params["message"], params["type"])

src/finecode/wm_server/services/action_tree.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ def _project_action_tree(project: domain.Project | None, ws_context: context.Wor
3636
handler_node_id = f"{project.dir_path.as_posix()}::{action.name}::{handler.name}"
3737
handlers_nodes.append(
3838
{
39-
"node_id": handler_node_id,
39+
"nodeId": handler_node_id,
4040
"name": handler.name,
41-
"node_type": 2, # ACTION
41+
"nodeType": 2, # ACTION
4242
"subnodes": [],
4343
"status": "",
4444
}
4545
)
4646
action_nodes.append(
4747
{
48-
"node_id": node_id,
48+
"nodeId": node_id,
4949
"name": action.name,
50-
"node_type": 2, # ACTION
50+
"nodeType": 2, # ACTION
5151
"subnodes": handlers_nodes,
5252
"status": "",
5353
}
@@ -61,9 +61,9 @@ def _project_action_tree(project: domain.Project | None, ws_context: context.Wor
6161
node_id = f"{project.dir_path.as_posix()}::actions"
6262
actions_nodes.append(
6363
{
64-
"node_id": node_id,
64+
"nodeId": node_id,
6565
"name": "Actions",
66-
"node_type": 3, # ACTION_GROUP
66+
"nodeType": 3, # ACTION_GROUP
6767
"subnodes": action_nodes,
6868
"status": "",
6969
}
@@ -74,19 +74,19 @@ def _project_action_tree(project: domain.Project | None, ws_context: context.Wor
7474
env_node_id = f"{project.dir_path.as_posix()}::envs::{env}"
7575
envs_nodes.append(
7676
{
77-
"node_id": env_node_id,
77+
"nodeId": env_node_id,
7878
"name": env,
79-
"node_type": 6, # ENV
79+
"nodeType": 6, # ENV
8080
"subnodes": [],
8181
"status": "",
8282
}
8383
)
8484
node_id = f"{project.dir_path.as_posix()}::envs"
8585
actions_nodes.append(
8686
{
87-
"node_id": node_id,
87+
"nodeId": node_id,
8888
"name": "Environments",
89-
"node_type": 5, # ENV_GROUP
89+
"nodeType": 5, # ENV_GROUP
9090
"subnodes": envs_nodes,
9191
"status": "",
9292
}
@@ -135,10 +135,10 @@ def _build_tree(ws_context: context.WorkspaceContext) -> list[dict]:
135135

136136
actions_nodes = _project_action_tree(ws_context.ws_projects.get(ws_dir), ws_context)
137137
node = {
138-
"node_id": ws_dir.as_posix(),
138+
"nodeId": ws_dir.as_posix(),
139139
"name": ws_dir.name,
140140
"subnodes": actions_nodes,
141-
"node_type": dir_node_type,
141+
"nodeType": dir_node_type,
142142
"status": status,
143143
}
144144
nodes.append(node)
@@ -149,10 +149,10 @@ def _build_tree(ws_context: context.WorkspaceContext) -> list[dict]:
149149
status = project.status.name if project is not None else ""
150150
actions_nodes = _project_action_tree(project, ws_context)
151151
node = {
152-
"node_id": project_path.as_posix(),
152+
"nodeId": project_path.as_posix(),
153153
"name": project_path.name,
154154
"subnodes": actions_nodes,
155-
"node_type": 1, # PROJECT
155+
"nodeType": 1, # PROJECT
156156
"status": status,
157157
}
158158

src/finecode/wm_server/wm_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,9 @@ def _register_callbacks() -> None:
445445
async def on_project_changed(project: domain.Project) -> None:
446446
_notify_all_clients("actions/treeChanged", {
447447
"node": {
448-
"node_id": str(project.dir_path),
448+
"nodeId": str(project.dir_path),
449449
"name": project.name,
450-
"node_type": 1,
450+
"nodeType": 1,
451451
"status": project.status.name,
452452
"subnodes": [],
453453
},

0 commit comments

Comments
 (0)