Skip to content

feat: 添加 UserScript 元数据语义高亮和诊断功能#17

Merged
CodFrm merged 4 commits into
scriptscat:mainfrom
bd-dxg:feat/highlightedHead
Jan 12, 2026
Merged

feat: 添加 UserScript 元数据语义高亮和诊断功能#17
CodFrm merged 4 commits into
scriptscat:mainfrom
bd-dxg:feat/highlightedHead

Conversation

@bd-dxg
Copy link
Copy Markdown
Contributor

@bd-dxg bd-dxg commented Jan 11, 2026

#16

  • 实现语义高亮支持,高亮元数据块的键名和键值
  • 添加元数据键名验证,检测拼写错误并提供智能建议
  • 支持快速修复无效的元数据键名(如 @Nmae@name
  • 添加语义高亮启用提示,引导用户获得更好的体验
  • 新增 highlight 目录,统一管理高亮相关功能

- 实现语义高亮支持,高亮元数据块的键名和键值
- 添加元数据键名验证,检测拼写错误并提供智能建议
- 支持快速修复无效的元数据键名(如 @Nmae@name)
- 添加语义高亮启用提示,引导用户获得更好的体验
- 新增 highlight 目录,统一管理高亮相关功能
Comment thread src/highlight/userScriptDiagnostics.ts Outdated
Comment on lines +42 to +44
// ScriptCat 特有
"noframes",
"unwrap",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是scriptcat特有,unwrap是Violentmonkey的

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/highlight/userScriptDiagnostics.ts Outdated
"run-at",

// Greasemonkey 4.x
"grant",
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate entry: "grant" is already listed on line 34. This duplicate should be removed to avoid redundancy in the validation set.

Suggested change
"grant",

Copilot uses AI. Check for mistakes.
Comment thread src/highlight/userScriptDiagnostics.ts Outdated
"grant",

// ScriptCat 特有
"noframes",
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate entry: "noframes" is already listed on line 35. This duplicate should be removed to avoid redundancy in the validation set.

Suggested change
"noframes",

Copilot uses AI. Check for mistakes.
Comment thread src/highlight/userScriptDiagnostics.ts Outdated
matrix[i][j] = Math.min(
matrix[i - 1][j - 1] + 1, // 替换
matrix[i][j - 1] + 1, // 插入
matrix[i][j - 1] + 1 // 删除
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
matrix[i][j - 1] + 1 // 删除
matrix[i - 1][j] + 1 // 删除

Copilot uses AI. Check for mistakes.
Comment thread src/highlight/userScriptDiagnostics.ts Outdated

for (const validKey of VALID_META_KEYS) {
const distance = levenshteinDistance(invalidKey.toLowerCase(), validKey.toLowerCase());
// 只保留编辑距离较小的建议(最多 2 个字符差异)
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
// 只保留编辑距离较小的建议(最多 2 个字符差异)
// 只保留编辑距离较小的建议(最多 3 个字符差异)

Copilot uses AI. Check for mistakes.
冰冻大西瓜 and others added 3 commits January 12, 2026 10:31
- 修正 Levenshtein 距离计算中删除操作的索引错误(matrix[i - 1][j] + 1)
- 移除 VALID_META_KEYS 中重复的 grant 和 noframes 键名
@CodFrm CodFrm merged commit ae0e918 into scriptscat:main Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants