Skip to content

Commit ef02ab8

Browse files
authored
docs(contracts): Core 作为应用契约唯一真源,补回命令表与 AI 配置章节 (#24)
- rust-core-api.md 补回 #19 误删的命令总表(375 条,每个 CoreCommand::parse 接受的命令一行) 和 AI configuration 章节;Build systems 表补上 build.resolveStoredOptions、build.editStoredOption。 - protocol::command 新增测试:命令表与解析器逐条比对,增删改命令必须同一次提交更新表格。 - 删除 rust/fixtures/i18n(归 Lithe-IDEA i18n 生成器所有,迁到 shared/i18n/fixtures) 和无人读取的 rust/fixtures/phpunit-project。 Refs 1lck/Lithe-IDEA#1853
1 parent 5a8e67d commit ef02ab8

10 files changed

Lines changed: 479 additions & 63 deletions

File tree

‎rust/contracts/application-boundary.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ no runtime JSON loading, package download or write to installed resources occurs
2727
The locale registry preserves each platform's persisted identifiers and default
2828
language. Explicit fallback chains resolve shared entries during generation;
2929
all existing platform catalogs and presentation-owned bilingual copy use this source. Translation coverage is not a
30-
capability claim. [Format fixtures](../fixtures/i18n/format-v1.json) bind generation
30+
capability claim. [Format fixtures](https://github.com/1lck/Lithe-IDEA/blob/preview/shared/i18n/fixtures/format-v1.json) bind generation
3131
to native positional formatting, literal percent signs and unmodified argument data.
3232

3333
## Feature Contracts

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

Lines changed: 406 additions & 1 deletion
Large diffs are not rendered by default.

‎rust/fixtures/i18n/format-v1.json‎

Lines changed: 0 additions & 23 deletions
This file was deleted.

‎rust/fixtures/i18n/native-abi-v1.json‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎rust/fixtures/phpunit-project/.gitignore‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎rust/fixtures/phpunit-project/composer.json‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎rust/fixtures/phpunit-project/phpunit.xml‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎rust/fixtures/phpunit-project/src/Store.php‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎rust/fixtures/phpunit-project/tests/StoreTest.php‎

Lines changed: 0 additions & 12 deletions
This file was deleted.

‎rust/lithe-core/src/protocol/command.rs‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,78 @@ impl CoreCommand {
12231223
#[cfg(test)]
12241224
mod tests {
12251225
use super::CoreCommand;
1226+
use std::collections::BTreeSet;
1227+
use std::path::Path;
1228+
1229+
/// Returns the command names that `CoreCommand::parse` matches, read from
1230+
/// this file so the test cannot drift from the parser it checks.
1231+
fn parsed_command_names(source: &str) -> Vec<String> {
1232+
let body = source
1233+
.split_once("pub fn parse(value: &str) -> Option<Self> {")
1234+
.and_then(|(_, rest)| rest.split_once("_ => None,"))
1235+
.map(|(body, _)| body)
1236+
.expect("CoreCommand::parse body");
1237+
body.lines()
1238+
.filter_map(|line| line.trim().strip_prefix('"'))
1239+
.filter_map(|line| line.split_once("\" =>"))
1240+
.map(|(name, _)| name.to_owned())
1241+
.collect()
1242+
}
1243+
1244+
/// Returns the first-column names of the `| Command | Purpose |` table.
1245+
fn documented_command_names(document: &str) -> Vec<String> {
1246+
document
1247+
.lines()
1248+
.skip_while(|line| !line.starts_with("| Command | Purpose |"))
1249+
.skip(2)
1250+
.take_while(|line| line.starts_with("| `"))
1251+
.map(|line| {
1252+
line["| `".len()..]
1253+
.split_once('`')
1254+
.expect("backticked command name")
1255+
.0
1256+
.to_owned()
1257+
})
1258+
.collect()
1259+
}
1260+
1261+
#[test]
1262+
fn api_command_table_lists_exactly_the_parsed_commands() {
1263+
let crate_root = Path::new(env!("CARGO_MANIFEST_DIR"));
1264+
let source = std::fs::read_to_string(crate_root.join("src/protocol/command.rs"))
1265+
.expect("read command.rs");
1266+
let document = std::fs::read_to_string(crate_root.join("../contracts/rust-core-api.md"))
1267+
.expect("read rust-core-api.md");
1268+
let parsed = parsed_command_names(&source);
1269+
let documented = documented_command_names(&document);
1270+
1271+
assert!(
1272+
parsed.len() > 300,
1273+
"parser scan found {} names",
1274+
parsed.len()
1275+
);
1276+
for name in &parsed {
1277+
assert!(
1278+
CoreCommand::parse(name).is_some(),
1279+
"scanned {name} does not parse"
1280+
);
1281+
}
1282+
let unique: BTreeSet<_> = documented.iter().collect();
1283+
assert_eq!(
1284+
unique.len(),
1285+
documented.len(),
1286+
"duplicate rows in the command table"
1287+
);
1288+
1289+
let parsed: BTreeSet<_> = parsed.iter().collect();
1290+
let undocumented: Vec<_> = parsed.difference(&unique).collect();
1291+
let unknown: Vec<_> = unique.difference(&parsed).collect();
1292+
assert!(
1293+
undocumented.is_empty() && unknown.is_empty(),
1294+
"rust-core-api.md command table is out of date: missing {undocumented:?}, \
1295+
not parsed {unknown:?}"
1296+
);
1297+
}
12261298

12271299
#[test]
12281300
fn parses_semantic_lsp_runtime_commands() {

0 commit comments

Comments
 (0)