1.0.2 优化打开逻辑
This commit is contained in:
32
dist/fileSystemProvider.js
vendored
32
dist/fileSystemProvider.js
vendored
@@ -39,21 +39,35 @@ class SquirrelFileSystemProvider {
|
||||
constructor(model) {
|
||||
this._onDidChangeFile = new vscode.EventEmitter();
|
||||
this.onDidChangeFile = this._onDidChangeFile.event;
|
||||
// 存储文件实例内容,支持多标签页
|
||||
this.fileContentCache = new Map();
|
||||
this.model = model;
|
||||
}
|
||||
// 读取文件
|
||||
async readFile(uri) {
|
||||
const filePath = this.getPathFromUri(uri);
|
||||
// 检查是否有缓存的内容(用于多标签页支持)
|
||||
const cacheKey = uri.toString();
|
||||
if (this.fileContentCache.has(cacheKey)) {
|
||||
const content = this.fileContentCache.get(cacheKey);
|
||||
return new TextEncoder().encode(content);
|
||||
}
|
||||
// 从模型获取内容
|
||||
const content = await this.model.getFileContent(filePath);
|
||||
if (content === undefined) {
|
||||
throw vscode.FileSystemError.FileNotFound(uri);
|
||||
}
|
||||
// 缓存内容以支持多标签页
|
||||
this.fileContentCache.set(cacheKey, content);
|
||||
return new TextEncoder().encode(content);
|
||||
}
|
||||
// 写入文件
|
||||
async writeFile(uri, content, options) {
|
||||
const filePath = this.getPathFromUri(uri);
|
||||
const textContent = new TextDecoder().decode(content);
|
||||
// 更新缓存内容
|
||||
const cacheKey = uri.toString();
|
||||
this.fileContentCache.set(cacheKey, textContent);
|
||||
const success = await this.model.saveFileContent(filePath, textContent);
|
||||
if (!success) {
|
||||
throw vscode.FileSystemError.Unavailable('保存文件失败');
|
||||
@@ -61,11 +75,17 @@ class SquirrelFileSystemProvider {
|
||||
}
|
||||
// 其他必须实现的方法(简化实现)
|
||||
stat(uri) {
|
||||
// 获取文件内容以确定大小
|
||||
const cacheKey = uri.toString();
|
||||
let content = '';
|
||||
if (this.fileContentCache.has(cacheKey)) {
|
||||
content = this.fileContentCache.get(cacheKey);
|
||||
}
|
||||
return {
|
||||
type: vscode.FileType.File,
|
||||
ctime: Date.now(),
|
||||
mtime: Date.now(),
|
||||
size: 0
|
||||
size: Buffer.byteLength(content, 'utf8')
|
||||
};
|
||||
}
|
||||
readDirectory(uri) {
|
||||
@@ -83,13 +103,23 @@ class SquirrelFileSystemProvider {
|
||||
watch(uri, options) {
|
||||
return new vscode.Disposable(() => { });
|
||||
}
|
||||
// 清理文件缓存
|
||||
clearFileCache(uri) {
|
||||
const cacheKey = uri.toString();
|
||||
this.fileContentCache.delete(cacheKey);
|
||||
}
|
||||
// 从 URI 解析文件路径
|
||||
getPathFromUri(uri) {
|
||||
if (uri.scheme !== 'squirrel') {
|
||||
throw vscode.FileSystemError.FileNotFound(uri);
|
||||
}
|
||||
// 移除查询参数,只返回路径部分
|
||||
return uri.path.substring(1); // 去掉开头的 '/'
|
||||
}
|
||||
// 获取文件实例ID
|
||||
getInstanceId(uri) {
|
||||
return uri.query ? new URLSearchParams(uri.query).get('instance') || 'default' : 'default';
|
||||
}
|
||||
}
|
||||
exports.SquirrelFileSystemProvider = SquirrelFileSystemProvider;
|
||||
//# sourceMappingURL=fileSystemProvider.js.map
|
||||
Reference in New Issue
Block a user