Skip to content

Commit 62b8a08

Browse files
authored
feat(core): 八组 Viva 宿主规则移进 Core(项目树、编辑分组、插件生命周期、工作树、Git 分组、代理排除、停止等待) (#30) (#31)
* feat(process): processLifecycle.resolve 返回停止等待时间的默认值与上下限 gracefulStopRule 设置页读取 gracefulStopRule { defaultSeconds, minSeconds, maxSeconds },不再用三个越界值探测推导(Lithe-IDEA #1830)。规则与 resolve 共用同一组常量。 * feat(network): read proxy exclusion entries in Core network.proxyPolicy now returns exclusionRules, the exclusion entries as host, suffix, ip, cidr and local rules, and invalidExclusions, the entries with none of the forms. The contract states the exact comparison a network stack applies, addresses compared within their family and an IPv6 zone ignored, and rust/fixtures/network/proxy-bypass-v1.json pins which hosts go direct, so hosts no longer parse the entries themselves. * feat(git): git.changedFileGroups groups changed files by folder in natural order The changed-file lists of a commit, a stash and a shelf grouped their files in the desktop client with path.Dir and a byte comparison. Core now owns the grouping: a file belongs to the folder before its last slash, the top being "", folders sort segment by segment and files by name in the project tree's natural order (lithe_core_rules::file_names), a folder right before its subfolders. The response carries indices into the request's paths so hosts keep their own file records. Shared fixture rust/fixtures/git/changed-file-groups-v1.json. Refs Lithe-IDEA/Lithe-IDEA#1814 * feat(git): worktree states, allowed writes and creation preview in Core git.worktrees now gives each worktree its state (missing, locked, modified, current, available) and the writes it allows with the reason a write is blocked; countChanges counts the local changes of every checkout in the same listing. git.worktreeCreationPreview derives the dialog's choices, held reference, cleaned branch name, suggested destination and readiness, so the desktop no longer keeps its own copy of these rules (Lithe-IDEA#1817). * feat(core): 新增 plugins.installed.lifecycle,插件启用与卸载规则由 Core 持有 新 crate lithe-plugin-lifecycle:输入已安装版本、用户的启用选择和动作(确认安装、启用、 禁用、卸载),返回每个已安装插件的启用状态和宿主按顺序执行的步骤(记录/清除选择、停止 程序、逐个删除版本并清除其批准记录、删除状态目录)。没有选择即禁用;确认安装只在没有 选择时启用;禁用先记录再停止;卸载先停止,再删除全部版本、清除选择和状态。对未安装插件 的动作返回 plugin.lifecycle.notInstalled。契约写入 rust-core-api.md,共享用例在 rust/fixtures/plugins/installed-lifecycle.json。 Refs 1lck/Lithe-IDEA#1842 * feat(editor-layout): 编辑分组与分栏树的状态转换下沉到 Core 新增纯规则 crate lithe-editor-layout,公开两条命令: - editor.groupLayout.reduce:在分组状态和分栏树上一起执行一次转换。 支持 editor.workbenchState.reduce 的全部动作,以及 openTab、dropTab、 removeEmptyGroups;分组离开状态时,叶子自动从树中移除。 拖放落点过期返回 stale,规则拒绝返回 refused,两种情况都按原样返回状态和树。 - editor.groupLayout.dropTargets:拖动开始时给出每个分组可接受的落点 (标签条、主体边缘分栏、主体中间追加),以及空编辑区是否可接受。 分栏比例、像素和拖动过程留在宿主;Core 只接收树的形状。新分栏使用宿主 提供的编号,新分组使用宿主提供的 ID。契约、fixture 和测试同步补齐。 Refs 1lck/Lithe-IDEA#1806 * feat(project-tree): 项目树可见行与多选规则下沉到 Core 新增两个纯规则 crate,公开两条命令: - workspace.rowSelection.reduce(lithe-row-selection):路径行的多选。 普通点击选中并清掉标记和锚点;Cmd/Ctrl 点击切换标记并设为锚点;Shift 点击从锚点(没有锚点时从选中行)标记到点击行,保留其他标记;clear 结束 批量操作。根节点永远不会被标记。点击已经消失的行返回 stale。targets 给出 批量操作的对象:去掉已标记文件夹里面的路径。项目树和变更列表共用。 - workspace.projectTree.rows(lithe-project-tree):宿主按先序发送已加载 节点(深度、是否展开)、选择和视口顶行路径;Core 返回可见行、修复后的选择 (节点消失或被折叠时移到最近的可见上级)、顶行的新行号和 targets。不读 磁盘,只在树形变化时调用,不在每帧调用。 契约、fixture 和测试同步补齐。 Refs 1lck/Lithe-IDEA#1800
1 parent 7ae0c16 commit 62b8a08

47 files changed

Lines changed: 7638 additions & 25 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎rust/Cargo.lock‎

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rust/contracts/rust-core-api.md‎

Lines changed: 221 additions & 10 deletions
Large diffs are not rendered by default.

‎rust/crates/core/Cargo.toml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ lithe-diagnostics = { path = "../diagnostics" }
2222
lithe-diff = { path = "../diff" }
2323
lithe-document-uri = { path = "../document-uri" }
2424
lithe-editor = { path = "../editor" }
25+
lithe-editor-layout = { path = "../editor-layout" }
2526
lithe-execution = { path = "../execution" }
2627
lithe-git = { path = "../git" }
2728
lithe-git-host = { path = "../git-host" }
@@ -36,6 +37,7 @@ lithe-plugin-function-relay = { path = "../plugin-function-relay" }
3637
lithe-plugin-keymap-import = { path = "../plugin-keymap-import" }
3738
lithe-plugin-language-servers = { path = "../plugin-language-servers" }
3839
lithe-plugin-manifest = { path = "../plugin-manifest" }
40+
lithe-plugin-lifecycle = { path = "../plugin-lifecycle" }
3941
lithe-plugin-marketplace = { path = "../plugin-marketplace" }
4042
lithe-plugin-model = { path = "../plugin-model" }
4143
lithe-plugin-native-ui = { path = "../plugin-native-ui" }
@@ -45,7 +47,9 @@ lithe-plugin-web-content = { path = "../plugin-web-content" }
4547
lithe-process = { path = "../process" }
4648
lithe-project = { path = "../project" }
4749
lithe-project-generators = { path = "../project-generators" }
50+
lithe-project-tree = { path = "../project-tree" }
4851
lithe-protocol = { path = "../protocol" }
52+
lithe-row-selection = { path = "../row-selection" }
4953
lithe-request-context = { path = "../request-context" }
5054
lithe-terminal = { path = "../terminal" }
5155
lithe-text = { path = "../text" }

‎rust/crates/core/src/protocol/command.rs‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ pub enum PluginsCommand {
235235
DeclarativeSettingsActionPlan,
236236
/// Selects numeric installed versions and reports malformed native facts.
237237
InstalledSelect,
238+
/// Reports installed plugins' enablement and plans a lifecycle action
239+
/// (`plugins.installed.lifecycle`).
240+
InstalledLifecycle,
238241
/// Validates an atomic plugin settings edit and preserves unrelated values.
239242
DeclarativeEditSettings,
240243
/// Expands a language server's `workspaceConfiguration` (`plugins.declarative.workspaceConfiguration`).
@@ -460,6 +463,12 @@ pub enum WorkspaceCommand {
460463
ReleaseIndexing,
461464
/// Lists the visible children of project directories (`workspace.listDirectories`).
462465
ListDirectories,
466+
/// Says which loaded project tree nodes show as rows and keeps the selection on one
467+
/// (`workspace.projectTree.rows`).
468+
ProjectTreeRows,
469+
/// Applies one click to the multi-selection of rows of workspace paths
470+
/// (`workspace.rowSelection.reduce`).
471+
RowSelectionReduce,
463472
/// Orders natively enumerated directory siblings (`workspace.orderEntries`).
464473
OrderEntries,
465474
/// Ranks host-supplied candidate names with the shared matcher (`workspace.rankNames`).
@@ -533,6 +542,13 @@ pub enum EditorCommand {
533542
/// (`editor.workbenchState.reduce`). The rule lives in `lithe-core-rules` so the Windows frontend
534543
/// can run it synchronously inside store updates.
535544
WorkbenchStateReduce,
545+
/// Applies one transition to the editor groups and the tree that divides the editor area
546+
/// among them: a workbench state action, opening a tab, dropping a dragged one or removing
547+
/// empty groups (`editor.groupLayout.reduce`).
548+
GroupLayoutReduce,
549+
/// Says which places of each editor group accept a dragged tab
550+
/// (`editor.groupLayout.dropTargets`).
551+
GroupLayoutDropTargets,
536552
/// Applies a deterministic line-level editing transform
537553
/// (`editor.lineEdit`).
538554
LineEdit,
@@ -803,6 +819,11 @@ pub enum GitCommand {
803819
RebasePlanPreview,
804820
/// Groups one kind of loaded references into an ordered tree (`git.referenceTree`).
805821
ReferenceTree,
822+
/// Groups changed files by folder in natural order (`git.changedFileGroups`).
823+
ChangedFileGroups,
824+
/// Derives the worktree creation dialog's choices, branch, destination and readiness
825+
/// (`git.worktreeCreationPreview`).
826+
WorktreeCreationPreview,
806827
/// Resolves the destination and commits for a branch push (`git.pushPreview`).
807828
PushPreview,
808829
/// Resolves metadata for one commit (`git.commit`).
@@ -982,6 +1003,9 @@ impl CoreCommand {
9821003
Some(Self::Plugins(PluginsCommand::DeclarativeSettingsActionPlan))
9831004
}
9841005
"plugins.installed.select" => Some(Self::Plugins(PluginsCommand::InstalledSelect)),
1006+
"plugins.installed.lifecycle" => {
1007+
Some(Self::Plugins(PluginsCommand::InstalledLifecycle))
1008+
}
9851009
"plugins.declarative.editSettings" => {
9861010
Some(Self::Plugins(PluginsCommand::DeclarativeEditSettings))
9871011
}
@@ -1094,6 +1118,12 @@ impl CoreCommand {
10941118
"workspace.refreshIndexing" => Some(Self::Workspace(WorkspaceCommand::RefreshIndexing)),
10951119
"workspace.filterChanges" => Some(Self::Workspace(WorkspaceCommand::FilterChanges)),
10961120
"workspace.listDirectories" => Some(Self::Workspace(WorkspaceCommand::ListDirectories)),
1121+
"workspace.projectTree.rows" => {
1122+
Some(Self::Workspace(WorkspaceCommand::ProjectTreeRows))
1123+
}
1124+
"workspace.rowSelection.reduce" => {
1125+
Some(Self::Workspace(WorkspaceCommand::RowSelectionReduce))
1126+
}
10971127
"workspace.orderEntries" => Some(Self::Workspace(WorkspaceCommand::OrderEntries)),
10981128
"workspace.rankNames" => Some(Self::Workspace(WorkspaceCommand::RankNames)),
10991129
"workspace.planDuplicate" => Some(Self::Workspace(WorkspaceCommand::PlanDuplicate)),
@@ -1157,6 +1187,10 @@ impl CoreCommand {
11571187
"editor.workbenchState.reduce" => {
11581188
Some(Self::Editor(EditorCommand::WorkbenchStateReduce))
11591189
}
1190+
"editor.groupLayout.reduce" => Some(Self::Editor(EditorCommand::GroupLayoutReduce)),
1191+
"editor.groupLayout.dropTargets" => {
1192+
Some(Self::Editor(EditorCommand::GroupLayoutDropTargets))
1193+
}
11601194
"workspace.classifyVisibility" => {
11611195
Some(Self::Workspace(WorkspaceCommand::ClassifyVisibility))
11621196
}
@@ -1367,6 +1401,8 @@ impl CoreCommand {
13671401
"git.normalizeChangeTargets" => Some(Self::Git(GitCommand::NormalizeChangeTargets)),
13681402
"git.rebasePlanPreview" => Some(Self::Git(GitCommand::RebasePlanPreview)),
13691403
"git.referenceTree" => Some(Self::Git(GitCommand::ReferenceTree)),
1404+
"git.changedFileGroups" => Some(Self::Git(GitCommand::ChangedFileGroups)),
1405+
"git.worktreeCreationPreview" => Some(Self::Git(GitCommand::WorktreeCreationPreview)),
13701406
"git.pushPreview" => Some(Self::Git(GitCommand::PushPreview)),
13711407
"git.commit" => Some(Self::Git(GitCommand::Commit)),
13721408
"git.commitFiles" => Some(Self::Git(GitCommand::CommitFiles)),

‎rust/crates/core/src/runtime/dispatcher/editor.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! `editor.*` commands: workbench state, text edits, find, navigation and preferences.
1+
//! `editor.*` commands: workbench state, group layout, text edits, find, navigation and preferences.
22
33
use super::{plugin_response, rules_response};
44
use crate::protocol::{CoreError, CoreResponse, EditorCommand, ErrorCode};
@@ -15,6 +15,12 @@ pub(super) fn dispatch(
1515
EditorCommand::WorkbenchStateReduce => {
1616
rules_response(id, "editor.workbenchState.reduce", payload)
1717
}
18+
EditorCommand::GroupLayoutReduce => {
19+
plugin_response(id, payload, lithe_editor_layout::reduce_command)
20+
}
21+
EditorCommand::GroupLayoutDropTargets => {
22+
plugin_response(id, payload, lithe_editor_layout::drop_targets_command)
23+
}
1824
EditorCommand::Find => match lithe_editor::find::command(payload, document) {
1925
Ok(data) => CoreResponse::success(id, data),
2026
Err(error) => CoreResponse::failure(id, error),

‎rust/crates/core/src/runtime/dispatcher/git.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,12 @@ pub(super) fn dispatch(command: GitCommand, id: Option<String>, payload: Value)
435435
GitCommand::ReferenceTree => {
436436
plugin_response(id, payload, lithe_git::reference_tree_command)
437437
}
438+
GitCommand::ChangedFileGroups => {
439+
plugin_response(id, payload, lithe_git::changed_file_groups_command)
440+
}
441+
GitCommand::WorktreeCreationPreview => {
442+
plugin_response(id, payload, lithe_git::worktree_creation_preview_command)
443+
}
438444
GitCommand::PrepareCommitSelection => {
439445
plugin_response(id, payload, lithe_git::prepare_commit_selection_command)
440446
}

‎rust/crates/core/src/runtime/dispatcher/plugins.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ pub(super) fn dispatch(
7474
PluginsCommand::InstalledSelect => {
7575
plugin_response(id, payload, lithe_plugin_model::installed::select_command)
7676
}
77+
PluginsCommand::InstalledLifecycle => {
78+
plugin_response(id, payload, lithe_plugin_lifecycle::command)
79+
}
7780
PluginsCommand::SettingsCatalog => {
7881
plugin_response(id, payload, lithe_plugin_manifest::settings_catalog_command)
7982
}

‎rust/crates/core/src/runtime/dispatcher/workspace.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//! `workspace.*` commands: snapshots, indexing, directory actions, repositories and search.
1+
//! `workspace.*` commands: snapshots, indexing, project tree rows, row selection, directory
2+
//! actions, repositories and search.
23
34
use super::{plugin_response, rules_response};
45
use crate::project::{
@@ -93,6 +94,12 @@ pub(super) fn dispatch(
9394
),
9495
}
9596
}
97+
WorkspaceCommand::ProjectTreeRows => {
98+
plugin_response(id, payload, lithe_project_tree::command)
99+
}
100+
WorkspaceCommand::RowSelectionReduce => {
101+
plugin_response(id, payload, lithe_row_selection::command)
102+
}
96103
WorkspaceCommand::ListDirectories => {
97104
match serde_json::from_value::<DirectoryListingRequest>(payload)
98105
.map_err(|error| {

‎rust/crates/core/src/tests/git.rs‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,37 @@ fn git_worktrees_lists_primary_linked_and_locked_metadata() {
18461846
assert_eq!(worktrees[1]["branch"], "refs/heads/feature/linked");
18471847
assert_eq!(worktrees[1]["isLocked"], true);
18481848
assert_eq!(worktrees[1]["lockReason"], "Codex task");
1849+
assert_eq!(worktrees[0]["status"], "current");
1850+
assert_eq!(worktrees[0]["changes"], Value::Null);
1851+
assert_eq!(
1852+
worktrees[0]["actions"]["remove"]["reason"],
1853+
"git_worktree_primary"
1854+
);
1855+
assert_eq!(worktrees[1]["status"], "locked");
1856+
assert_eq!(
1857+
worktrees[1]["actions"]["remove"]["reason"],
1858+
"git_worktree_locked"
1859+
);
1860+
assert_eq!(worktrees[1]["actions"]["lock"]["allowed"], true);
1861+
1862+
fs::write(root.join("draft.txt"), "draft\n").expect("untracked file should be written");
1863+
let counted: Value = serde_json::from_str(&execute_json(
1864+
&serde_json::to_string(&serde_json::json!({
1865+
"id": "git-worktrees-count",
1866+
"command": "git.worktrees",
1867+
"payload": { "root": root, "countChanges": true }
1868+
}))
1869+
.expect("worktrees request should encode"),
1870+
))
1871+
.expect("worktrees response should be JSON");
1872+
assert_eq!(counted["ok"], true, "{counted:?}");
1873+
let counted = counted["data"]["worktrees"]
1874+
.as_array()
1875+
.expect("worktrees should be an array");
1876+
assert_eq!(counted[0]["changes"], 1, "{counted:?}");
1877+
assert_eq!(counted[0]["status"], "modified");
1878+
assert_eq!(counted[1]["changes"], 0, "{counted:?}");
1879+
assert_eq!(counted[1]["status"], "locked");
18491880
}
18501881

18511882
#[test]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//! `git.changedFileGroups` against the shared fixture.
2+
3+
use serde_json::{json, Value};
4+
5+
fn call(payload: Value) -> Value {
6+
serde_json::from_str(&crate::execute_json(
7+
&json!({"id":"groups", "command":"git.changedFileGroups", "payload":payload}).to_string(),
8+
))
9+
.unwrap()
10+
}
11+
12+
#[test]
13+
fn shared_fixture_paths_have_one_grouping_and_order() {
14+
let fixture: Value = serde_json::from_str(include_str!(
15+
"../../../../fixtures/git/changed-file-groups-v1.json"
16+
))
17+
.unwrap();
18+
for case in fixture["cases"].as_array().unwrap() {
19+
let response = call(case["request"].clone());
20+
assert_eq!(response["ok"], true, "{}: {response}", case["name"]);
21+
assert_eq!(
22+
response["data"]["folders"], case["folders"],
23+
"{}",
24+
case["name"]
25+
);
26+
}
27+
}
28+
29+
#[test]
30+
fn rejects_unknown_fields() {
31+
let response = call(json!({"paths":["a"],"status":["M"]}));
32+
assert_eq!(response["ok"], false);
33+
assert_eq!(response["error"]["code"], "invalid_request");
34+
}

0 commit comments

Comments
 (0)