Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 16, 2025

Port demo template selection feature from CLion plugin to VSCode plugin. Users can now choose from 31 professionally-crafted examples when creating EGE projects, with intelligent file handling to prevent accidental overwrites and automatic git stash support.

Implementation

Demo Management System (src/demoOptions.ts)

  • DemoOptionsManager: Discovers and serves demo templates from filesystem
  • DemoMetadataRegistry: Bilingual metadata (zh/en) for 31 demos across 8 categories
  • Categories: Basic, Games, Graphics, Algorithms, Physics, Fractals, Image Processing, Camera

Project Setup (src/setupProject.ts)

  • Interactive QuickPick dialog with categorized demos
  • Automatic language detection from VSCode locale
  • Resource dependency handling (e.g., image files for graph_getimage.cpp)
  • Smart file overwrite protection with content comparison
  • User confirmation prompts for file and directory operations
  • Git stash integration before overwrites

File Handling (src/utils.ts)

  • copyFileWithPrompt(): Compares file content before overwriting, stashes if git-managed, prompts user if different
  • replaceDirWithPrompt(): Confirms directory replacement with user, respects "Yes to All" flag, stashes before replacing
  • copyDirRecursiveWithPrompt(): Recursive copy with per-file/directory prompts
  • isGitManaged(): Detects if directory is under git version control
  • stashFilesIfGitManaged(): Creates git stash with descriptive message before overwriting
  • Batch operation support: "Yes to All" / "No to All" with proper flag propagation
// Demo selection now precedes project setup
const demoOption = await showDemoSelectionDialog(language);
const sourceFile = demoOption.fileName 
    ? path.join(__dirname, `../cmake_template/ege_demos/${demoOption.fileName}`)
    : path.join(__dirname, `../cmake_template/main.cpp`);

// Smart copy with content comparison, git stash, and user confirmation
const result = await copyFileWithPrompt(sourceFile, `${workspaceDir}/main.cpp`, false, false, workspaceDir);

Demo Templates

31 demos organized by category:

  • Games (4): Snake, Tetris, Gomoku, Typing Practice
  • Graphics (9): Star animations, Clock, Lines effects, Fireworks
  • Algorithms (5): A* Pathfinding, Sorting visualization, K-Means, Conway's Game of Life
  • Physics (4): Ball collision, Boids simulation, Wave mesh
  • Fractals (2): Julia/Mandelbrot sets
  • Image (4): Loading, rotation, transformations
  • Camera (2): Device capture, real-time effects

Smart File Overwrite Protection

When creating a new project with existing files:

  1. File Content Comparison

    • Automatically compares existing file content with template
    • If identical → Skip without prompting
    • If different → Prompt user for confirmation
  2. Individual File Confirmation

    • User can choose: Yes, No, Yes to All, or No to All
    • Cancel operation at any point
  3. Directory Replacement

    • For ege and .vscode folders, user confirms before replacing entire directory
    • "Yes to All" flag applies to directory operations (no additional prompts)
    • Options: Yes (replace), No (keep existing), or Cancel
  4. Batch Operations

    • "Yes to All" → Overwrites remaining files and directories without individual prompts
    • "No to All" → Skips remaining files without individual prompts
    • Flags properly propagate through recursive operations
  5. Git Stash Integration

    • Automatically detects if workspace is git-managed
    • Creates git stash before overwriting files/directories when user confirms
    • Stash messages include timestamps: EGE Plugin: Auto-stash before overwrite (2025-12-16T10-05-19-123Z)
    • Silent failure if git is unavailable or stash fails (doesn't block operation)
    • Protects user work by preserving changes in git history
  6. Full Internationalization

    • All prompts and messages in Chinese and English
    • Automatic language detection from VSCode settings

Source files copied directly from x-ege/ege-clion-plugin repository under same organization.

Original prompt

任务: 创建项目的时候, 支持更多的 Demo 模板。
描述:请先审查本项目, 了解本项目时做什么的。 然后参考一下 https://github.com/x-ege/ege-clion-plugin 这个项目。 这两个项目功能类似, 都是为 xege 这个图形库服务,但是功能现在有差异了。
clion 版本插件在「新建项目」模板功能里面支持了选择不同的 demo 的功能。 我希望你把这个功能移植到本项目里面。
这两个项目在同一个组织下面, 所以无需担心版权问题, 你觉得应该照搬的地方就照搬。


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@coderabbitai
Copy link

coderabbitai bot commented Dec 16, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Note

Free review on us!

CodeRabbit is offering free reviews until Wed Dec 17 2025 to showcase some of the refinements we've made.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI and others added 4 commits December 16, 2025 03:04
Co-authored-by: wysaid <1430725+wysaid@users.noreply.github.com>
Co-authored-by: wysaid <1430725+wysaid@users.noreply.github.com>
Co-authored-by: wysaid <1430725+wysaid@users.noreply.github.com>
Co-authored-by: wysaid <1430725+wysaid@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for more demo templates in project creation Add demo template selection with 31 categorized examples Dec 16, 2025
Copilot AI requested a review from wysaid December 16, 2025 03:11
@wysaid
Copy link
Collaborator

wysaid commented Dec 16, 2025

@copilot 继续改进一下, 当创建新的模板 CMake 项目时, 如果遇到文件已存在,先检查文件内容是否一致, 如果一致, 那么跳过, 否则给用户逐个弹窗确认是否覆盖。
对于 ege 和 .vscode 文件夹, 弹窗确认是否替换整个文件夹

Copilot AI and others added 2 commits December 16, 2025 07:57
Co-authored-by: wysaid <1430725+wysaid@users.noreply.github.com>
Co-authored-by: wysaid <1430725+wysaid@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 16, 2025

@copilot 继续改进一下, 当创建新的模板 CMake 项目时, 如果遇到文件已存在,先检查文件内容是否一致, 如果一致, 那么跳过, 否则给用户逐个弹窗��...

已完成改进!实现的功能:

文件处理:

  • 创建项目时检查文件是否存在
  • 如果内容相同,自动跳过(无提示)
  • 如果内容不同,弹窗让用户确认是否覆盖
  • 支持"全部是"/"全部否"批量操作

文件夹处理:

  • 对于 ege.vscode 文件夹,如果已存在会弹窗询问是否替换整个文件夹
  • 用户可选择保留现有或替换

技术改进:

  • 所有提示信息支持中英文双语
  • 批量操作的标志正确传递到子目录
  • 用户可随时取消操作

提交记录:15f2da1

Copilot AI changed the title Add demo template selection with 31 categorized examples Add demo template selection with 31 categorized examples and smart file overwrite protection Dec 16, 2025
@wysaid
Copy link
Collaborator

wysaid commented Dec 16, 2025

@copilot 继续改进, 几个问题:

  1. 你提交了不该提交的文件, 请去掉, 并忽略掉。
  2. 创建基于 ege 源码的 CMake 模板时, 选择了「全部是」, 似乎只对文件生效, 对文件夹不生效, 还是弹出了文件夹重复,是否覆盖的提示, 这种情况下, 如果选择了全部是, 那么直接全覆盖。
  3. 创建模板的情况下, 如果需要覆盖, 且用户选择了覆盖, 那么判断一下用户这个目录是否有 git 管理, 如果有 git 管理, 并且用户本地也安装了 git,那么帮用户 stash 一下要被覆盖的 文件/文件夹

Copilot AI and others added 2 commits December 16, 2025 10:09
…s, add git stash support

Co-authored-by: wysaid <1430725+wysaid@users.noreply.github.com>
Co-authored-by: wysaid <1430725+wysaid@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 16, 2025

@copilot 继续改进, 几个问题:

  1. 你提交了不该提交的文件, 请去掉, 并忽略掉。
  2. 创建基于 ege 源码的 CMake 模板时, 选择了「全部是」, 似乎只对文...

已完成所有改进!

解决的问题:

  1. 删除不该提交的文件

    • 删除了 _codeql_detected_source_root 文件
    • 添加到 .gitignore 防止再次提交
  2. "全部是"对文件夹生效

    • 修改了 replaceDirWithPrompt 函数,现在接受 overwriteAll 参数
    • 当选择"全部是"后,后续的文件夹也会直接覆盖,不再弹窗
  3. Git Stash 支持

    • 添加了 isGitManaged() 检查目录是否被 git 管理
    • 添加了 stashFilesIfGitManaged() 在覆盖前自动 stash
    • 覆盖文件/文件夹前,如果目录被 git 管理且本地安装了 git,会自动 stash
    • Stash 消息带时间戳,便于识别
    • 如果 stash 失败不会中断操作

技术细节:

  • 所有函数都传递 workspaceDir 参数以支持 git stash
  • replaceDirWithPrompt 现在尊重 overwriteAll 标志
  • 类型安全处理 git 命令输出(支持 string 和 Buffer)

提交记录:dc496c5

Copilot AI changed the title Add demo template selection with 31 categorized examples and smart file overwrite protection Add demo template selection with 31 categorized examples, smart file overwrite protection, and git stash integration Dec 16, 2025
@wysaid wysaid marked this pull request as ready for review December 16, 2025 13:02
Copilot AI review requested due to automatic review settings December 16, 2025 13:02
Copy link

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 pull request ports the demo template selection feature from the CLion plugin, enabling users to choose from 31 professionally-crafted EGE examples organized into 8 categories when creating new projects. The implementation includes intelligent file handling with content comparison, user confirmation prompts, and git stash integration to prevent accidental data loss.

Key Changes:

  • Demo management system with bilingual (Chinese/English) metadata for 31 templates across 8 categories
  • Interactive QuickPick dialog with automatic language detection
  • Smart file overwrite protection comparing content before prompting users
  • Git stash integration that automatically preserves changes before overwrites
  • Batch operation support with "Yes to All" / "No to All" flags

Reviewed changes

Copilot reviewed 38 out of 41 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/demoOptions.ts New file implementing demo discovery, metadata registry, and categorization system for 31 templates
src/setupProject.ts Enhanced project setup with demo selection dialog, smart file handling, and resource dependency management
src/utils.ts Added file/directory copy with prompts, content comparison, git stash support, and batch operation flags
src/i18n.ts Extended with new localized strings for file operation prompts and messages
src/extension.ts Updated command handlers to properly await async setupProject function
cmake_template/ege_demos/*.cpp 31 new demo template files covering games, graphics, algorithms, physics, fractals, and image processing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

});

// Show QuickPick
const selected = await vscode.window.showQuickPick(items.filter(item => item.kind !== vscode.QuickPickItemKind.Separator), {
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The QuickPick is filtering out separator items, but this creates a UI inconsistency. Users won't see the category headers that provide visual organization. Consider using showQuickPick with all items including separators, or restructure to use labels without separators.

Copilot uses AI. Check for mistakes.
Comment on lines +625 to +628
// Stage the files first
for (const p of paths) {
runShellCommand('git', ['add', p], { cwd: workspaceDir, noErrorMsg: true });
}
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The git add operation stages files before creating the stash. This is problematic because it modifies the git state even if the stash fails. Additionally, staging untracked or modified files may include unwanted changes. Consider using git stash push --include-untracked without pre-staging, or handle the staging rollback on failure.

Copilot uses AI. Check for mistakes.
items.push({
label: '',
kind: vscode.QuickPickItemKind.Separator
} as any);
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The type assertion as any is used to bypass type checking for separator items. This suppresses TypeScript's safety checks. Consider defining a proper union type or interface that accommodates both regular items and separators.

Copilot uses AI. Check for mistakes.
* Demo options management for EGE VSCode Extension
*/

import * as path from 'path';
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

Unused import path.

Copilot uses AI. Check for mistakes.
import { ege } from './ege';
import { copyDirRecursiveIfNotExist, copyIfNotExist } from './utils';
import { t } from './i18n';
import { copyDirRecursiveIfNotExist, copyIfNotExist, copyFileWithPrompt, copyDirRecursiveWithPrompt, replaceDirWithPrompt } from './utils';
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

Unused imports copyDirRecursiveIfNotExist, copyDirRecursiveWithPrompt, copyIfNotExist.

Copilot uses AI. Check for mistakes.
* Show demo selection dialog
*/
async function showDemoSelectionDialog(language: string): Promise<DemoOption | undefined> {
const demoOptions = DemoOptionsManager.getDemoOptions(language);
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

Unused variable demoOptions.

Copilot uses AI. Check for mistakes.
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.

2 participants