autosnippet 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/injection.js +33 -9
- package/bin/watch.js +13 -4
- package/package.json +1 -1
package/bin/injection.js
CHANGED
|
@@ -17,18 +17,42 @@ const headerMark = '// ahead ';
|
|
|
17
17
|
const importReg = /^\#import\s*<\w+\/\w+.h>$/;
|
|
18
18
|
|
|
19
19
|
function createHeader(headerLine) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
// 格式:// ahead <Module/Header.h> [relative/path/to/Header.h]
|
|
21
|
+
// 或:// ahead <Module/Header.h> [relative/path/to/Header.h] (转义格式)
|
|
22
|
+
const content = headerLine.split(headerMark)[1].trim();
|
|
23
|
+
|
|
24
|
+
// 匹配 <Module/Header.h> 或 <Module/Header.h> 以及可选的相对路径
|
|
25
|
+
const match = content.match(/^(?:<|<)(\w+)\/(\w+\.h)(?:>|>)(?:\s+(.+))?$/);
|
|
26
|
+
|
|
27
|
+
if (!match) {
|
|
28
|
+
// 兼容旧格式:直接解析
|
|
29
|
+
const headerArray = content.split('/');
|
|
30
|
+
const moduleName = headerArray[0].substr(1);
|
|
31
|
+
const headerName = headerArray[1].substr(0, headerArray[1].length - 1);
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
name: content,
|
|
35
|
+
specName: headerArray[0] + '/' + headerArray[0].substr(1) + '.h>',
|
|
36
|
+
moduleName: moduleName,
|
|
37
|
+
headerName: headerName,
|
|
38
|
+
moduleStrName: '"' + moduleName + '.h"',
|
|
39
|
+
headerStrName: '"' + headerName + '"',
|
|
40
|
+
headRelativePathFromMark: null,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const moduleName = match[1];
|
|
45
|
+
const headerName = match[2];
|
|
46
|
+
const headRelativePathFromMark = match[3] || null; // 相对路径(如果有)
|
|
47
|
+
|
|
25
48
|
return {
|
|
26
|
-
name:
|
|
27
|
-
specName:
|
|
49
|
+
name: `<${moduleName}/${headerName}>`,
|
|
50
|
+
specName: `<${moduleName}/${headerName}>`,
|
|
28
51
|
moduleName: moduleName,
|
|
29
52
|
headerName: headerName,
|
|
30
|
-
moduleStrName:
|
|
31
|
-
headerStrName:
|
|
53
|
+
moduleStrName: `"${moduleName}.h"`,
|
|
54
|
+
headerStrName: `"${headerName}"`,
|
|
55
|
+
headRelativePathFromMark: headRelativePathFromMark, // 从标记中提取的相对路径
|
|
32
56
|
};
|
|
33
57
|
}
|
|
34
58
|
|
package/bin/watch.js
CHANGED
|
@@ -13,7 +13,8 @@ const alinkMark = 'alink';
|
|
|
13
13
|
const wellMark = '#';
|
|
14
14
|
const atMark = '@';
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
// 匹配原始格式和转义格式:// ahead <Module/Header.h> 或 // ahead <Module/Header.h>
|
|
17
|
+
const headerReg = /^\/\/ ahead\s+(?:<|<)(\w+)\/(\w+\.h)(?:>|>)(\s+.+)?$/;
|
|
17
18
|
const headerSwiftReg = /^\/\/ ahead \w+$/;
|
|
18
19
|
const importReg = /^\#import\s*<\w+\/\w+.h>$/;
|
|
19
20
|
const importSwiftReg = /^import\s*\w+$/;
|
|
@@ -148,14 +149,22 @@ function processFileChange(specFile, updateFile, relativePath) {
|
|
|
148
149
|
}
|
|
149
150
|
|
|
150
151
|
if (headerLine) {
|
|
151
|
-
|
|
152
|
-
|
|
152
|
+
// 先解码 HTML 实体(< -> <, > -> >, & -> &)
|
|
153
|
+
let decodedHeaderLine = headerLine
|
|
154
|
+
.replace(/</g, '<')
|
|
155
|
+
.replace(/>/g, '>')
|
|
156
|
+
.replace(/&/g, '&');
|
|
157
|
+
|
|
158
|
+
const isMatch = currHeaderReg.test(decodedHeaderLine);
|
|
159
|
+
console.log(`📋 检查 // ahead 标记: ${headerLine}`);
|
|
160
|
+
console.log(`📋 解码后: ${decodedHeaderLine}, 匹配: ${isMatch}`);
|
|
153
161
|
|
|
154
162
|
if (isMatch) {
|
|
155
163
|
console.log(`✅ 触发头文件注入: ${updateFile}`);
|
|
156
164
|
clearTimeout(timeoutHead);
|
|
157
165
|
timeoutHead = setTimeout(() => {
|
|
158
|
-
|
|
166
|
+
// 传递解码后的 headerLine
|
|
167
|
+
checkAnotherFile(specFile, updateFile, decodedHeaderLine, importArray, isSwift);
|
|
159
168
|
}, DEBOUNCE_DELAY);
|
|
160
169
|
} else {
|
|
161
170
|
console.log(`⚠️ // ahead 标记格式不匹配,期望格式: // ahead <Module/Header.h> [相对路径]`);
|