feat(fs): add stat API for markdown file validation (#774)
Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Bohdan Triapitsyn
parent
0e70422835
commit
14fc741cc9
@@ -1022,14 +1022,14 @@ const getContextDirectory = (effectiveDirectory: string, resolvedPath: string):
|
||||
const useFileReferenceInteractions = ({
|
||||
containerRef,
|
||||
effectiveDirectory,
|
||||
readFile,
|
||||
statFile,
|
||||
editor,
|
||||
preferRuntimeEditor,
|
||||
deferValidationUntilIdle = false,
|
||||
}: {
|
||||
containerRef: React.RefObject<HTMLDivElement | null>;
|
||||
effectiveDirectory: string;
|
||||
readFile?: (path: string) => Promise<{ content: string; path: string }>;
|
||||
statFile?: (path: string) => Promise<{ path: string; isFile: boolean; size: number }>;
|
||||
editor?: EditorAPI;
|
||||
preferRuntimeEditor?: boolean;
|
||||
deferValidationUntilIdle?: boolean;
|
||||
@@ -1061,10 +1061,14 @@ const useFileReferenceInteractions = ({
|
||||
|
||||
const checkPromise = (async () => {
|
||||
try {
|
||||
if (!readFile) {
|
||||
if (!statFile) {
|
||||
return false;
|
||||
}
|
||||
const stat = await statFile(resolvedPath);
|
||||
if (!stat.isFile) {
|
||||
cache.set(resolvedPath, false);
|
||||
return false;
|
||||
}
|
||||
await readFile(resolvedPath);
|
||||
cache.set(resolvedPath, true);
|
||||
return true;
|
||||
} catch {
|
||||
@@ -1289,7 +1293,7 @@ const useFileReferenceInteractions = ({
|
||||
container.removeEventListener('click', handleClick);
|
||||
container.removeEventListener('keydown', handleKeyDown);
|
||||
};
|
||||
}, [containerRef, deferValidationUntilIdle, editor, effectiveDirectory, preferRuntimeEditor, readFile]);
|
||||
}, [containerRef, deferValidationUntilIdle, editor, effectiveDirectory, preferRuntimeEditor, statFile]);
|
||||
};
|
||||
|
||||
const useMermaidInlineInteractions = ({
|
||||
@@ -1405,7 +1409,7 @@ export const MarkdownRenderer: React.FC<MarkdownRendererProps> = ({
|
||||
useFileReferenceInteractions({
|
||||
containerRef: streamdownContainerRef,
|
||||
effectiveDirectory,
|
||||
readFile: files.readFile,
|
||||
statFile: files.statFile,
|
||||
editor,
|
||||
preferRuntimeEditor: runtime.isVSCode,
|
||||
deferValidationUntilIdle: isStreaming,
|
||||
@@ -1491,7 +1495,7 @@ export const SimpleMarkdownRenderer: React.FC<{
|
||||
useFileReferenceInteractions({
|
||||
containerRef: streamdownContainerRef,
|
||||
effectiveDirectory,
|
||||
readFile: files.readFile,
|
||||
statFile: files.statFile,
|
||||
editor,
|
||||
preferRuntimeEditor: runtime.isVSCode,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user