Skip to content

Commit 5851e8d

Browse files
erha19Aaaaash
andauthored
feat: support access function for custom fs provider (#4496)
* feat: support access function for custom fs provider * fix: ensure context key initialization in file tree component --------- Co-authored-by: liuqian <[email protected]>
1 parent 68d6037 commit 5851e8d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/file-service/src/browser/file-service-client.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,15 @@ export class FileServiceClient implements IFileServiceClient, IDisposable {
511511
const provider = await this.getProvider(_uri.scheme);
512512

513513
if (!containsExtraFileMethod(provider, 'access')) {
514+
if (mode === FileAccess.Constants.F_OK) {
515+
// 当 mode 为 F_OK 时,如果 provider 不支持 access 方法,则使用 stat 方法判断文件是否存在
516+
try {
517+
const stat = await provider.stat(_uri.codeUri);
518+
return !!stat;
519+
} catch (error) {
520+
return false;
521+
}
522+
}
514523
throw this.getErrorProvideNotSupport(_uri.scheme, 'access');
515524
}
516525

packages/file-tree-next/src/browser/file-tree.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,16 @@ export const FileTree = ({ viewState }: PropsWithChildren<{ viewState: ViewState
146146
if (treeModel) {
147147
// 确保数据初始化完毕,减少初始化数据过程中多次刷新视图
148148
await treeModel.ensureReady;
149+
150+
if (wrapperRef.current) {
151+
fileTreeService.initContextKey(wrapperRef.current);
152+
}
149153
}
150154
setModel(treeModel);
151155
setIsLoading(false);
152156
});
153157
}
154-
}, [isReady]);
158+
}, [isReady, wrapperRef.current, fileTreeService]);
155159

156160
useEffect(() => {
157161
const tokenSource = new CancellationTokenSource();

0 commit comments

Comments
 (0)