feat: 添加 UserScript 元数据语义高亮和诊断功能#17
Conversation
| // ScriptCat 特有 | ||
| "noframes", | ||
| "unwrap", |
There was a problem hiding this comment.
不是scriptcat特有,unwrap是Violentmonkey的
There was a problem hiding this comment.
Pull request overview
This PR adds UserScript metadata semantic highlighting and diagnostic features to the ScriptCat VS Code extension. It introduces a new highlight directory containing modules for semantic token highlighting, diagnostic validation, and user prompts for enabling semantic highlighting features.
Changes:
- Implemented semantic token provider for highlighting UserScript metadata keys and values
- Added diagnostic provider to validate metadata key names with Levenshtein distance-based suggestions
- Added user prompt system to encourage enabling semantic highlighting in VS Code settings
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/highlight/userScriptHighlighter.ts | Implements semantic token provider for UserScript metadata syntax highlighting |
| src/highlight/userScriptDiagnostics.ts | Provides diagnostic validation and quick-fix actions for invalid metadata keys |
| src/highlight/semanticHighlighting.ts | Implements user prompt to enable semantic highlighting feature |
| src/extension.ts | Integrates new highlighting and diagnostic features into extension activation |
| package.json | Adds semantic token scope configuration for JavaScript files |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "run-at", | ||
|
|
||
| // Greasemonkey 4.x | ||
| "grant", |
There was a problem hiding this comment.
Duplicate entry: "grant" is already listed on line 34. This duplicate should be removed to avoid redundancy in the validation set.
| "grant", |
| "grant", | ||
|
|
||
| // ScriptCat 特有 | ||
| "noframes", |
There was a problem hiding this comment.
Duplicate entry: "noframes" is already listed on line 35. This duplicate should be removed to avoid redundancy in the validation set.
| "noframes", |
| matrix[i][j] = Math.min( | ||
| matrix[i - 1][j - 1] + 1, // 替换 | ||
| matrix[i][j - 1] + 1, // 插入 | ||
| matrix[i][j - 1] + 1 // 删除 |
There was a problem hiding this comment.
The third parameter in this Math.min call should be matrix[i - 1][j] + 1 for deletion, not matrix[i][j - 1] + 1 which represents insertion. This is a copy-paste error that causes incorrect Levenshtein distance calculations, which will affect the quality of spelling suggestions.
| matrix[i][j - 1] + 1 // 删除 | |
| matrix[i - 1][j] + 1 // 删除 |
|
|
||
| for (const validKey of VALID_META_KEYS) { | ||
| const distance = levenshteinDistance(invalidKey.toLowerCase(), validKey.toLowerCase()); | ||
| // 只保留编辑距离较小的建议(最多 2 个字符差异) |
There was a problem hiding this comment.
The distance threshold check has a logic issue. The condition "distance > 0" prevents exact matches (distance = 0) from being included, which is correct. However, the outer condition "distance <= 3" allows up to 3 character differences, while the comment states "最多 2 个字符差异" (maximum 2 character differences). Either the threshold should be changed to 2 or the comment should be updated to match the implementation.
| // 只保留编辑距离较小的建议(最多 2 个字符差异) | |
| // 只保留编辑距离较小的建议(最多 3 个字符差异) |
- 修正 Levenshtein 距离计算中删除操作的索引错误(matrix[i - 1][j] + 1) - 移除 VALID_META_KEYS 中重复的 grant 和 noframes 键名
#16