Skip to content

Commit 3f6ebe1

Browse files
committed
fix: std i18n translator
1 parent f8ac776 commit 3f6ebe1

File tree

11 files changed

+329
-137
lines changed

11 files changed

+329
-137
lines changed

crates/emmylua_ls/src/handlers/initialized/std_i18n.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn check_need_dump_std(resources_dir: &Path, locale: &str) -> bool {
118118
/// Params:
119119
/// - `locale` - 语言
120120
/// - `out_parent_dir` - 输出目录的父目录
121-
fn generate(locale: &str, out_parent_dir: &Path) -> (PathBuf, Vec<LuaFileInfo>) {
121+
fn generate(locale: &str, out_parent_dir: &Path) -> Vec<LuaFileInfo> {
122122
let origin_std_files = emmylua_code_analysis::load_resource_from_include_dir();
123123
let translate_std_root = out_parent_dir.join(format!("std-{locale}"));
124124
log::info!("Creating std-{locale} dir: {:?}", translate_std_root);
@@ -145,11 +145,7 @@ fn generate(locale: &str, out_parent_dir: &Path) -> (PathBuf, Vec<LuaFileInfo>)
145145
});
146146
}
147147

148-
// 写入版本文件,用于下次启动时判断是否需要重新生成
149-
let version_path = translate_std_root.join("version");
150-
let _ = std::fs::write(&version_path, VERSION);
151-
152-
(translate_std_root, out_files)
148+
out_files
153149
}
154150

155151
fn translate_one_std_file(locale: &str, rel_lua_path: &Path, content: &str) -> Option<String> {
@@ -385,14 +381,14 @@ mod tests {
385381
use super::generate;
386382

387383
#[test]
384+
#[ignore]
388385
fn test_generate_translated() {
389386
let test_output_dir = Path::new(env!("CARGO_MANIFEST_DIR"))
390387
.parent()
391388
.unwrap()
392389
.join("emmylua_code_analysis")
393390
.join("resources");
394-
let (root, files) = generate("zh_CN", &test_output_dir);
395-
assert!(root.exists());
391+
let files = generate("zh_CN", &test_output_dir);
396392
assert!(!files.is_empty());
397393
}
398394
}

crates/emmylua_ls/std_i18n/debug/meta.yaml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ entries:
510510
col: 29
511511
hash: fnv1a64:cbf29ce484222325
512512
context_hash: fnv1a64:fda1a39e0913db3f
513-
- key: debuglib.getlocal
513+
- key: debuglib.getlocal@>5.2,JIT
514514
kind:
515515
type: doc_block
516516
indent: ''
@@ -519,11 +519,11 @@ entries:
519519
line: 105
520520
col: 0
521521
end:
522-
line: 133
523-
col: 14
524-
hash: fnv1a64:e89d131112b5cf0c
522+
line: 125
523+
col: 0
524+
hash: fnv1a64:4b73d2bc58010347
525525
context_hash: fnv1a64:de7cc417de1b3246
526-
- key: debuglib.getlocal.param.thread
526+
- key: debuglib.getlocal@>5.2,JIT.param.thread
527527
kind:
528528
type: line_tail
529529
prefix: ' '
@@ -536,7 +536,7 @@ entries:
536536
col: 24
537537
hash: fnv1a64:cbf29ce484222325
538538
context_hash: fnv1a64:1ee979508970775b
539-
- key: debuglib.getlocal.param.f
539+
- key: debuglib.getlocal@>5.2,JIT.param.f
540540
kind:
541541
type: line_tail
542542
prefix: ' '
@@ -549,7 +549,7 @@ entries:
549549
col: 20
550550
hash: fnv1a64:cbf29ce484222325
551551
context_hash: fnv1a64:41f139265960290b
552-
- key: debuglib.getlocal.param.index
552+
- key: debuglib.getlocal@>5.2,JIT.param.index
553553
kind:
554554
type: line_tail
555555
prefix: ' '
@@ -562,7 +562,7 @@ entries:
562562
col: 24
563563
hash: fnv1a64:cbf29ce484222325
564564
context_hash: fnv1a64:ac1cec9bf544fdf1
565-
- key: debuglib.getlocal.return.1
565+
- key: debuglib.getlocal@>5.2,JIT.return.1
566566
kind:
567567
type: line_tail
568568
prefix: ' '
@@ -575,7 +575,7 @@ entries:
575575
col: 24
576576
hash: fnv1a64:cbf29ce484222325
577577
context_hash: fnv1a64:aa7d58a98ea93c05
578-
- key: debuglib.getlocal.return.2
578+
- key: debuglib.getlocal@>5.2,JIT.return.2
579579
kind:
580580
type: line_tail
581581
prefix: ' '
@@ -588,7 +588,7 @@ entries:
588588
col: 22
589589
hash: fnv1a64:cbf29ce484222325
590590
context_hash: fnv1a64:2d3fc065d614b7f2
591-
- key: debuglib.getlocal
591+
- key: debuglib.getlocal@5.1
592592
kind:
593593
type: doc_block
594594
indent: ''
@@ -597,11 +597,11 @@ entries:
597597
line: 137
598598
col: 0
599599
end:
600-
line: 153
601-
col: 14
602-
hash: fnv1a64:6e78bee4ce7ab0e2
600+
line: 147
601+
col: 0
602+
hash: fnv1a64:2c536048630738b5
603603
context_hash: fnv1a64:de7cc417de1b3246
604-
- key: debuglib.getlocal.param.thread
604+
- key: debuglib.getlocal@5.1.param.thread
605605
kind:
606606
type: line_tail
607607
prefix: ' '
@@ -614,7 +614,7 @@ entries:
614614
col: 24
615615
hash: fnv1a64:cbf29ce484222325
616616
context_hash: fnv1a64:1ee979508970775b
617-
- key: debuglib.getlocal.param.lvl
617+
- key: debuglib.getlocal@5.1.param.lvl
618618
kind:
619619
type: line_tail
620620
prefix: ' '
@@ -627,7 +627,7 @@ entries:
627627
col: 22
628628
hash: fnv1a64:cbf29ce484222325
629629
context_hash: fnv1a64:9799ce0a2eaca463
630-
- key: debuglib.getlocal.param.index
630+
- key: debuglib.getlocal@5.1.param.index
631631
kind:
632632
type: line_tail
633633
prefix: ' '
@@ -640,7 +640,7 @@ entries:
640640
col: 24
641641
hash: fnv1a64:cbf29ce484222325
642642
context_hash: fnv1a64:ac1cec9bf544fdf1
643-
- key: debuglib.getlocal.return.1
643+
- key: debuglib.getlocal@5.1.return.1
644644
kind:
645645
type: line_tail
646646
prefix: ' '
@@ -653,7 +653,7 @@ entries:
653653
col: 24
654654
hash: fnv1a64:cbf29ce484222325
655655
context_hash: fnv1a64:aa7d58a98ea93c05
656-
- key: debuglib.getlocal.return.2
656+
- key: debuglib.getlocal@5.1.return.2
657657
kind:
658658
type: line_tail
659659
prefix: ' '

crates/emmylua_ls/std_i18n/debug/zh_CN.yaml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ debuglib.getinfo.param.what: ""
107107

108108
debuglib.getinfo.return.1: ""
109109

110-
debuglib.getlocal: |
110+
debuglib.getlocal@>5.2,JIT: |
111111
此函数返回栈中第 `level` 层函数的索引为 `local` 的局部变量的名称和值。
112112
此函数不仅访问显式的局部变量,还包括参数、临时变量等。
113113
@@ -121,17 +121,36 @@ debuglib.getlocal: |
121121
122122
参数 `f` 也可以是一个函数。在这种情况下,`getlocal` 仅返回函数参数的名称。
123123
124-
debuglib.getlocal.param.thread: ""
124+
debuglib.getlocal@>5.2,JIT.param.thread: ""
125125

126-
debuglib.getlocal.param.f: ""
126+
debuglib.getlocal@>5.2,JIT.param.f: ""
127127

128-
debuglib.getlocal.param.index: ""
128+
debuglib.getlocal@>5.2,JIT.param.index: ""
129129

130-
debuglib.getlocal.return.1: ""
130+
debuglib.getlocal@>5.2,JIT.return.1: ""
131131

132-
debuglib.getlocal.return.2: ""
132+
debuglib.getlocal@>5.2,JIT.return.2: ""
133133

134-
debuglib.getlocal.param.lvl: ""
134+
# This function returns the name and the value of the local variable with
135+
# index `index` of the function at level `level` of the stack. (The first
136+
# parameter or local variable has index 1, and so on, until the last active
137+
# local variable). The function returns **nil** if there is no local variable
138+
# with the given index, and raises an error when called with a level out of
139+
# range. (You can call `debug.getinfo` to check whether the level is valid.)
140+
#
141+
# Variable names starting with `'('` (open parentheses) represent internal
142+
# variables (loop control variables, temporaries, and C function locals).
143+
144+
145+
146+
147+
148+
149+
150+
151+
152+
153+
135154

136155
debuglib.getmetatable: |
137156
返回给定 `value` 的元表,如果它没有元表则返回 **nil**。

crates/emmylua_ls/std_i18n/io/meta.yaml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ entries:
468468
col: 0
469469
end:
470470
line: 120
471-
col: 16
472-
hash: fnv1a64:827344117e46f1db
471+
col: 0
472+
hash: fnv1a64:c32f01b42c8a68a4
473473
context_hash: fnv1a64:de7cc417de1b3246
474474
- key: iolib.tmpfile.return.1
475475
kind:
@@ -532,9 +532,9 @@ entries:
532532
line: 131
533533
col: 0
534534
end:
535-
line: 135
536-
col: 23
537-
hash: fnv1a64:0629a9747818290d
535+
line: 133
536+
col: 0
537+
hash: fnv1a64:cddfb7fad90f9885
538538
context_hash: fnv1a64:de7cc417de1b3246
539539
- key: iolib.write.return.1
540540
kind:
@@ -575,7 +575,7 @@ entries:
575575
col: 0
576576
hash: fnv1a64:045bdb188ddcd0b3
577577
context_hash: fnv1a64:6b5eb10d9792750b
578-
- key: file.close
578+
- key: file.close@>5.2
579579
kind:
580580
type: doc_block
581581
indent: ''
@@ -584,11 +584,11 @@ entries:
584584
line: 143
585585
col: 0
586586
end:
587-
line: 152
588-
col: 19
589-
hash: fnv1a64:9154cc24d038abbc
587+
line: 150
588+
col: 0
589+
hash: fnv1a64:925e9a7d74c51050
590590
context_hash: fnv1a64:de7cc417de1b3246
591-
- key: file.close.return.1
591+
- key: file.close@>5.2.return.1
592592
kind:
593593
type: line_tail
594594
prefix: ' '
@@ -601,7 +601,7 @@ entries:
601601
col: 20
602602
hash: fnv1a64:cbf29ce484222325
603603
context_hash: fnv1a64:cfb38283db200bc3
604-
- key: file.close.return.2
604+
- key: file.close@>5.2.return.2
605605
kind:
606606
type: line_tail
607607
prefix: ' '
@@ -614,7 +614,7 @@ entries:
614614
col: 27
615615
hash: fnv1a64:cbf29ce484222325
616616
context_hash: fnv1a64:4825f8f81da91b94
617-
- key: file.close.return.3
617+
- key: file.close@>5.2.return.3
618618
kind:
619619
type: line_tail
620620
prefix: ' '
@@ -627,7 +627,7 @@ entries:
627627
col: 19
628628
hash: fnv1a64:cbf29ce484222325
629629
context_hash: fnv1a64:743c11d628d947ba
630-
- key: file.close
630+
- key: file.close@5.1,JIT
631631
kind:
632632
type: doc_block
633633
indent: ''
@@ -636,11 +636,11 @@ entries:
636636
line: 156
637637
col: 0
638638
end:
639-
line: 161
640-
col: 23
641-
hash: fnv1a64:338ed03603732be6
639+
line: 160
640+
col: 0
641+
hash: fnv1a64:0564fc98d5b21d64
642642
context_hash: fnv1a64:de7cc417de1b3246
643-
- key: file.close.return.1
643+
- key: file.close@5.1,JIT.return.1
644644
kind:
645645
type: line_tail
646646
prefix: ' '
@@ -653,7 +653,7 @@ entries:
653653
col: 20
654654
hash: fnv1a64:cbf29ce484222325
655655
context_hash: fnv1a64:cfb38283db200bc3
656-
- key: file.close.return.2
656+
- key: file.close@5.1,JIT.return.2
657657
kind:
658658
type: line_tail
659659
prefix: ' '
@@ -675,9 +675,9 @@ entries:
675675
line: 164
676676
col: 0
677677
end:
678-
line: 167
679-
col: 23
680-
hash: fnv1a64:a5298a94416c2ee9
678+
line: 166
679+
col: 0
680+
hash: fnv1a64:f7013005b20a614b
681681
context_hash: fnv1a64:de7cc417de1b3246
682682
- key: file.flush.return.1
683683
kind:
@@ -883,9 +883,9 @@ entries:
883883
line: 256
884884
col: 0
885885
end:
886-
line: 264
887-
col: 23
888-
hash: fnv1a64:eedd45da049efc00
886+
line: 262
887+
col: 0
888+
hash: fnv1a64:4ce76ceb7010e8d4
889889
context_hash: fnv1a64:de7cc417de1b3246
890890
- key: file.write.return.1
891891
kind:

crates/emmylua_ls/std_i18n/io/zh_CN.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,27 @@ iolib.write.return.2: ""
135135
file: |
136136
文件对象
137137
138-
file.close: |
138+
file.close@>5.2: |
139139
关闭 `file`。请注意,当文件句柄被垃圾收集时,文件会自动关闭,
140140
但这需要的时间是不可预测的。
141141
142142
当关闭由 `io.popen` 创建的文件句柄时,`file:close` 返回
143143
与 `os.execute` 相同的返回值。
144144
145-
file.close.return.1: ""
145+
file.close@>5.2.return.1: ""
146146

147-
file.close.return.2: ""
147+
file.close@>5.2.return.2: ""
148148

149-
file.close.return.3: ""
149+
file.close@>5.2.return.3: ""
150+
151+
# Closes `file`. Note that files are automatically closed when their
152+
# handles are garbage collected, but that takes an unpredictable amount of
153+
# time to happen.
154+
155+
156+
[email protected],JIT.return.1: ""
157+
158+
[email protected],JIT.return.2: ""
150159

151160
file.flush: |
152161
将任何写入的数据保存到 `file`。

0 commit comments

Comments
 (0)