@lvce-editor/editor-worker 19.72.4 → 19.72.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/editorWorkerMain.js +72 -4
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -5627,7 +5627,7 @@ const FocusFindWidgetToggleReplace = 42;
|
|
|
5627
5627
|
const SourceActions = 38;
|
|
5628
5628
|
const FocusCodeGenerator = 52;
|
|
5629
5629
|
|
|
5630
|
-
const createEditor2 = (id, uri, x, y, width, height, platform, assetDir, _languageId, _tokenizePath, _useCache, applicationId) => {
|
|
5630
|
+
const createEditor2 = (id, uri, x, y, width, height, platform, assetDir, _languageId, _tokenizePath, _useCache, applicationId, editorFileCacheEnabled = false) => {
|
|
5631
5631
|
number(id);
|
|
5632
5632
|
const editor = {
|
|
5633
5633
|
...(applicationId !== undefined && {
|
|
@@ -5654,6 +5654,7 @@ const createEditor2 = (id, uri, x, y, width, height, platform, assetDir, _langua
|
|
|
5654
5654
|
differences: [],
|
|
5655
5655
|
documentSymbols: [],
|
|
5656
5656
|
dragAndDropEnabled: true,
|
|
5657
|
+
editorFileCacheEnabled,
|
|
5657
5658
|
embeds: [],
|
|
5658
5659
|
endOfLine: 'lf',
|
|
5659
5660
|
endOfLineDecorations: [],
|
|
@@ -16742,11 +16743,78 @@ const intialize = async (syntaxHighlightingEnabled, syncIncremental) => {
|
|
|
16742
16743
|
};
|
|
16743
16744
|
|
|
16744
16745
|
const largeFileContentLength = 10 * 1024 * 1024;
|
|
16746
|
+
const editorFileCacheMaxBytes = 500_000;
|
|
16745
16747
|
const pendingFileReads = new Map();
|
|
16746
|
-
const
|
|
16748
|
+
const getFileStatFingerprint = stat => {
|
|
16749
|
+
if (!stat || typeof stat !== 'object' || !Number.isFinite(stat.size)) {
|
|
16750
|
+
return '';
|
|
16751
|
+
}
|
|
16752
|
+
const modifiedTime = stat.mtimeMs ?? stat.mtime;
|
|
16753
|
+
if (typeof modifiedTime !== 'number' && typeof modifiedTime !== 'string') {
|
|
16754
|
+
return '';
|
|
16755
|
+
}
|
|
16756
|
+
const fingerprint = [stat.type, stat.size, modifiedTime];
|
|
16757
|
+
const changedTime = stat.ctimeMs ?? stat.ctime;
|
|
16758
|
+
if (typeof changedTime === 'number' || typeof changedTime === 'string') {
|
|
16759
|
+
fingerprint.push(changedTime);
|
|
16760
|
+
}
|
|
16761
|
+
if (typeof stat.etag === 'string') {
|
|
16762
|
+
fingerprint.push(stat.etag);
|
|
16763
|
+
}
|
|
16764
|
+
return JSON.stringify(fingerprint);
|
|
16765
|
+
};
|
|
16766
|
+
const isExcludedFromFileCache = uri => {
|
|
16767
|
+
const path = uri.split(/[?#]/, 1)[0];
|
|
16768
|
+
const fileName = path.slice(path.lastIndexOf('/') + 1);
|
|
16769
|
+
return fileName === '.env' || fileName.startsWith('.env.');
|
|
16770
|
+
};
|
|
16771
|
+
const removeCachedEditorFile = (applicationId, uri) => {
|
|
16772
|
+
void invoke$9(undefined, 'CacheStorage.removeEditorFileCache', applicationId || '', uri).catch(() => {});
|
|
16773
|
+
};
|
|
16774
|
+
const readFileWithCache = async (applicationId, uri, forceReload, useCache) => {
|
|
16775
|
+
if (!useCache) {
|
|
16776
|
+
return readFile$1(applicationId, uri);
|
|
16777
|
+
}
|
|
16747
16778
|
if (forceReload) {
|
|
16779
|
+
removeCachedEditorFile(applicationId, uri);
|
|
16748
16780
|
return readFile$1(applicationId, uri);
|
|
16749
16781
|
}
|
|
16782
|
+
if (isExcludedFromFileCache(uri)) {
|
|
16783
|
+
removeCachedEditorFile(applicationId, uri);
|
|
16784
|
+
return readFile$1(applicationId, uri);
|
|
16785
|
+
}
|
|
16786
|
+
let fingerprint = '';
|
|
16787
|
+
try {
|
|
16788
|
+
const stat = await invoke$9(applicationId, 'FileSystem.statWithMetadata', uri);
|
|
16789
|
+
if (stat?.size <= editorFileCacheMaxBytes) {
|
|
16790
|
+
fingerprint = getFileStatFingerprint(stat);
|
|
16791
|
+
}
|
|
16792
|
+
} catch {
|
|
16793
|
+
// Filesystems without stat metadata continue to use normal reads.
|
|
16794
|
+
}
|
|
16795
|
+
if (!fingerprint) {
|
|
16796
|
+
removeCachedEditorFile(applicationId, uri);
|
|
16797
|
+
}
|
|
16798
|
+
if (fingerprint) {
|
|
16799
|
+
try {
|
|
16800
|
+
const cached = await invoke$9(undefined, 'CacheStorage.getEditorFileCache', applicationId || '', uri, fingerprint);
|
|
16801
|
+
if (typeof cached === 'string') {
|
|
16802
|
+
return cached;
|
|
16803
|
+
}
|
|
16804
|
+
} catch {
|
|
16805
|
+
// Cache Storage failures must not prevent opening a file.
|
|
16806
|
+
}
|
|
16807
|
+
}
|
|
16808
|
+
const content = await readFile$1(applicationId, uri);
|
|
16809
|
+
if (fingerprint && new TextEncoder().encode(content).byteLength <= editorFileCacheMaxBytes) {
|
|
16810
|
+
void invoke$9(undefined, 'CacheStorage.setEditorFileCache', applicationId || '', uri, fingerprint, content).catch(() => {});
|
|
16811
|
+
}
|
|
16812
|
+
return content;
|
|
16813
|
+
};
|
|
16814
|
+
const readFile = (applicationId, uri, forceReload, useCache) => {
|
|
16815
|
+
if (forceReload) {
|
|
16816
|
+
return readFileWithCache(applicationId, uri, forceReload, useCache);
|
|
16817
|
+
}
|
|
16750
16818
|
let applicationReads = pendingFileReads.get(applicationId);
|
|
16751
16819
|
if (!applicationReads) {
|
|
16752
16820
|
applicationReads = new Map();
|
|
@@ -16768,7 +16836,7 @@ const readFile = (applicationId, uri, forceReload) => {
|
|
|
16768
16836
|
};
|
|
16769
16837
|
fileRead = (async () => {
|
|
16770
16838
|
try {
|
|
16771
|
-
return await
|
|
16839
|
+
return await readFileWithCache(applicationId, uri, forceReload, useCache);
|
|
16772
16840
|
} finally {
|
|
16773
16841
|
removePendingRead();
|
|
16774
16842
|
}
|
|
@@ -16927,7 +16995,7 @@ const loadContent = async (state, savedState, largeFile = false, focus = true, f
|
|
|
16927
16995
|
let endOfLine = existingEditor?.endOfLine || 'lf';
|
|
16928
16996
|
try {
|
|
16929
16997
|
if (!existingEditor) {
|
|
16930
|
-
content = await readFile(state.applicationId, uri, forceReload);
|
|
16998
|
+
content = await readFile(state.applicationId, uri, forceReload, state.editorFileCacheEnabled === true);
|
|
16931
16999
|
endOfLine = getEndOfLine(content);
|
|
16932
17000
|
content = normalizeLineEndings(content);
|
|
16933
17001
|
}
|