Cocos2d-JS Helper
VSCode extension hỗ trợ điều hướng và tra cứu trong dự án Cocos2d-JS dùng global namespace, không phụ thuộc import/export.
Tính năng
- Go to Definition cho namespace, class, method, property và resource.
- Find All References cho symbol và resource được index.
- Chain resolution dựa trên convention phổ biến và JSDoc type hint.
- Resource jump từ key resource hoặc tên file sang file thực tế.
- Sprite frame lookup từ tên frame sang plist tương ứng.
- Persistent cache giúp lần mở workspace sau nhanh hơn.
Cách dùng
Sau khi cài extension, mở workspace Cocos2d-JS và dùng các thao tác quen thuộc của VSCode:
F12 hoặc Ctrl+Click để nhảy tới định nghĩa.
Shift+F12 để tìm references.
- Command Palette để rebuild hoặc clear index khi cần.
Cài đặt từ VSIX
Đóng gói extension:
npm run build
Cài file .vsix đã build:
code --install-extension cocosjs-helper-0.4.2.vsix
Chạy dev
- Mở folder extension trong VSCode.
- Bấm
F5 để mở Extension Development Host.
- Trong cửa sổ mới, mở workspace Cocos2d-JS cần kiểm thử.
Lệnh
| Command |
Tác dụng |
Cocos2d-JS Helper: Rebuild Index |
Build lại toàn bộ index cho workspace hiện tại. |
Cocos2d-JS Helper: Clear Index Cache |
Xóa cache, lần activate tiếp theo sẽ rebuild full. |
Cấu hình
Có thể chỉnh trong settings.json:
{
"cocosjs.srcRoots": ["src"],
"cocosjs.resRoots": ["res"],
"cocosjs.plistGlobs": ["res/**/*.plist"],
"cocosjs.maxSearchFiles": 4000,
"cocosjs.codeLens.enabled": true,
"cocosjs.debug": false
}
Các setting chính:
cocosjs.srcRoots: thư mục chứa source JavaScript cần index.
cocosjs.resRoots: thư mục resource cần resolve file.
cocosjs.plistGlobs: pattern plist dùng để tìm sprite frame.
cocosjs.maxSearchFiles: giới hạn số file quét cho mỗi query.
cocosjs.codeLens.enabled: bật/tắt CodeLens của extension.
cocosjs.debug: ghi log debug vào Output channel.
Cache
- Cache được lưu trong
globalStorage của VSCode.
- Cache tự invalidate khi setting indexer đổi hoặc file source thay đổi.
- Có thể dùng command
Clear Index Cache nếu muốn rebuild sạch.
Giới hạn đã biết
- Indexer ưu tiên tốc độ và convention, không thay thế hoàn toàn parser JavaScript.
- Một số pattern động như gán property qua key runtime có thể không resolve được.
- Engine source lớn không được index mặc định.
- Sprite frame hiện tập trung vào plist.
| |