mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 17:27:54 +00:00
chore(vscode-ide-companion): update dependencies in package-lock.json
Added new dependencies including: - @cfworker/json-schema - @parcel/watcher and related platform-specific packages - autoprefixer - browserslist - chokidar - Various other utility packages These updates likely support enhanced functionality and improved compatibility.
This commit is contained in:
@@ -3,35 +3,35 @@
|
||||
* Copyright 2025 Qwen Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Diff 统计计算工具
|
||||
* Diff statistics calculation tool
|
||||
*/
|
||||
|
||||
/**
|
||||
* Diff 统计信息
|
||||
* Diff statistics
|
||||
*/
|
||||
export interface DiffStats {
|
||||
/** 新增行数 */
|
||||
/** Number of added lines */
|
||||
added: number;
|
||||
/** 删除行数 */
|
||||
/** Number of removed lines */
|
||||
removed: number;
|
||||
/** 修改行数(估算值) */
|
||||
/** Number of changed lines (estimated value) */
|
||||
changed: number;
|
||||
/** 总变更行数 */
|
||||
/** Total number of changed lines */
|
||||
total: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算两个文本之间的 diff 统计信息
|
||||
* Calculate diff statistics between two texts
|
||||
*
|
||||
* 使用简单的行对比算法(避免引入重量级 diff 库)
|
||||
* 算法说明:
|
||||
* 1. 将文本按行分割
|
||||
* 2. 比较行的集合差异
|
||||
* 3. 估算修改行数(同时出现在新增和删除中的行数)
|
||||
* Using a simple line comparison algorithm (avoiding heavy-weight diff libraries)
|
||||
* Algorithm explanation:
|
||||
* 1. Split text by lines
|
||||
* 2. Compare set differences of lines
|
||||
* 3. Estimate changed lines (lines that appear in both added and removed)
|
||||
*
|
||||
* @param oldText 旧文本内容
|
||||
* @param newText 新文本内容
|
||||
* @returns diff 统计信息
|
||||
* @param oldText Old text content
|
||||
* @param newText New text content
|
||||
* @returns Diff statistics
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
@@ -46,15 +46,15 @@ export function calculateDiffStats(
|
||||
oldText: string | null | undefined,
|
||||
newText: string | undefined,
|
||||
): DiffStats {
|
||||
// 处理空值情况
|
||||
// Handle null values
|
||||
const oldContent = oldText || '';
|
||||
const newContent = newText || '';
|
||||
|
||||
// 按行分割
|
||||
// Split by lines
|
||||
const oldLines = oldContent.split('\n').filter((line) => line.trim() !== '');
|
||||
const newLines = newContent.split('\n').filter((line) => line.trim() !== '');
|
||||
|
||||
// 如果其中一个为空,直接计算
|
||||
// If one of them is empty, calculate directly
|
||||
if (oldLines.length === 0) {
|
||||
return {
|
||||
added: newLines.length,
|
||||
@@ -73,18 +73,18 @@ export function calculateDiffStats(
|
||||
};
|
||||
}
|
||||
|
||||
// 使用 Set 进行快速查找
|
||||
// Use Set for fast lookup
|
||||
const oldSet = new Set(oldLines);
|
||||
const newSet = new Set(newLines);
|
||||
|
||||
// 计算新增:在 new 中但不在 old 中的行
|
||||
// Calculate added: lines in new but not in old
|
||||
const addedLines = newLines.filter((line) => !oldSet.has(line));
|
||||
|
||||
// 计算删除:在 old 中但不在 new 中的行
|
||||
// Calculate removed: lines in old but not in new
|
||||
const removedLines = oldLines.filter((line) => !newSet.has(line));
|
||||
|
||||
// 估算修改:取较小值(因为修改的行既被删除又被添加)
|
||||
// 这是一个简化的估算,实际的 diff 算法会更精确
|
||||
// Estimate changes: take the minimum value (because changed lines are both deleted and added)
|
||||
// This is a simplified estimation, actual diff algorithms would be more precise
|
||||
const estimatedChanged = Math.min(addedLines.length, removedLines.length);
|
||||
|
||||
const added = addedLines.length - estimatedChanged;
|
||||
@@ -100,10 +100,10 @@ export function calculateDiffStats(
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化 diff 统计信息为人类可读的文本
|
||||
* Format diff statistics as human-readable text
|
||||
*
|
||||
* @param stats diff 统计信息
|
||||
* @returns 格式化后的文本,例如 "+5 -3 ~2"
|
||||
* @param stats Diff statistics
|
||||
* @returns Formatted text, e.g. "+5 -3 ~2"
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
@@ -130,10 +130,10 @@ export function formatDiffStats(stats: DiffStats): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化详细的 diff 统计信息
|
||||
* Format detailed diff statistics
|
||||
*
|
||||
* @param stats diff 统计信息
|
||||
* @returns 详细的描述文本
|
||||
* @param stats Diff statistics
|
||||
* @returns Detailed description text
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
|
||||
@@ -33,15 +33,15 @@ function getExtensionUri(): string | undefined {
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证 URL 是否为安全的 VS Code webview 资源 URL
|
||||
* 防止 XSS 攻击
|
||||
* Validate if URL is a secure VS Code webview resource URL
|
||||
* Prevent XSS attacks
|
||||
*
|
||||
* @param url - 待验证的 URL
|
||||
* @returns 是否为安全的 URL
|
||||
* @param url - URL to validate
|
||||
* @returns Whether it is a secure URL
|
||||
*/
|
||||
function isValidWebviewUrl(url: string): boolean {
|
||||
try {
|
||||
// VS Code webview 资源 URL 的合法协议
|
||||
// Valid protocols for VS Code webview resource URLs
|
||||
const allowedProtocols = [
|
||||
'vscode-webview-resource:',
|
||||
'https-vscode-webview-resource:',
|
||||
@@ -49,7 +49,7 @@ function isValidWebviewUrl(url: string): boolean {
|
||||
'https:',
|
||||
];
|
||||
|
||||
// 检查是否以合法协议开头
|
||||
// Check if it starts with a valid protocol
|
||||
return allowedProtocols.some((protocol) => url.startsWith(protocol));
|
||||
} catch {
|
||||
return false;
|
||||
@@ -76,7 +76,7 @@ export function generateResourceUrl(relativePath: string): string {
|
||||
return '';
|
||||
}
|
||||
|
||||
// 验证 extensionUri 是否为安全的 URL
|
||||
// Validate if extensionUri is a secure URL
|
||||
if (!isValidWebviewUrl(extensionUri)) {
|
||||
console.error(
|
||||
'[resourceUrl] Invalid extension URI - possible security risk:',
|
||||
@@ -97,7 +97,7 @@ export function generateResourceUrl(relativePath: string): string {
|
||||
|
||||
const fullUrl = `${baseUri}${cleanPath}`;
|
||||
|
||||
// 验证最终生成的 URL 是否安全
|
||||
// Validate if the final generated URL is secure
|
||||
if (!isValidWebviewUrl(fullUrl)) {
|
||||
console.error('[resourceUrl] Generated URL failed validation:', fullUrl);
|
||||
return '';
|
||||
|
||||
Reference in New Issue
Block a user