This commit is contained in:
Andras Schmelczer 2026-04-26 12:46:12 +01:00
parent 8eae770621
commit 8b7be48522
13 changed files with 37 additions and 28 deletions

View file

@ -192,6 +192,10 @@ export class DeterministicAgent extends debugging.InMemoryFileSystem {
const isNew = !this.files.has(path);
await super.write(path, content);
if (!this.isSyncEnabled) {
return;
}
if (isNew) {
this.enqueueSync(async () => {
this.client.syncLocallyCreatedFile(path);
@ -208,9 +212,11 @@ export class DeterministicAgent extends debugging.InMemoryFileSystem {
updater: (current: TextWithCursors) => TextWithCursors
): Promise<string> {
const result = await super.atomicUpdateText(path, updater);
this.enqueueSync(async () => {
this.client.syncLocallyUpdatedFile({ relativePath: path });
});
if (this.isSyncEnabled) {
this.enqueueSync(async () => {
this.client.syncLocallyUpdatedFile({ relativePath: path });
});
}
return result;
}
@ -228,12 +234,14 @@ export class DeterministicAgent extends debugging.InMemoryFileSystem {
newPath: RelativePath
): Promise<void> {
await super.rename(oldPath, newPath);
this.enqueueSync(async () => {
this.client.syncLocallyUpdatedFile({
oldPath,
relativePath: newPath
if (this.isSyncEnabled) {
this.enqueueSync(async () => {
this.client.syncLocallyUpdatedFile({
oldPath,
relativePath: newPath
});
});
});
}
}
private async waitForWebSocket(): Promise<void> {

View file

@ -8,7 +8,7 @@ export function parseConcurrency(): number {
i + 1 < args.length
) {
const n = parseInt(args[i + 1], 10);
if (!isNaN(n) && n > 0) return n;
if (!isNaN(n) && n > 0) {return n;}
}
}
return os.cpus().length;

View file

@ -19,7 +19,7 @@ export class ServerManager {
}
public async stopAll(): Promise<void> {
if (this.isShuttingDown) return;
if (this.isShuttingDown) {return;}
this.isShuttingDown = true;
const servers = Array.from(this.activeServers);

View file

@ -19,6 +19,7 @@ export default [
rules: {
"no-console": "error",
"no-unused-vars": "off",
"curly": ["error", "all"],
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-floating-promises": [

View file

@ -14,7 +14,7 @@ export function renderCursorsInFileExplorer(
app: App
): void {
const fileExplorers = app.workspace.getLeavesOfType("file-explorer");
if (fileExplorers.length == 0) return;
if (fileExplorers.length == 0) {return;}
const [fileExplorer] = fileExplorers;

View file

@ -70,7 +70,7 @@ export class SyncService {
response: Response,
operation: string
): Promise<void> {
if (response.ok) return;
if (response.ok) {return;}
const message = `Failed to ${operation}: ${await SyncService.errorFromResponse(response)}`;
// 429 is the only 4xx the server uses for *transient* contention
// (`WriteBusyError` → HTTP 429). Every other 4xx means the request

View file

@ -17,7 +17,7 @@ function truncateFileNameToByteLimit(
maxBytes: number
): string {
const encoder = new TextEncoder();
if (encoder.encode(fileName).byteLength <= maxBytes) return fileName;
if (encoder.encode(fileName).byteLength <= maxBytes) {return fileName;}
const dotIndex = fileName.lastIndexOf(".");
// Dotfile (starts with "." and nothing else) → no extension to preserve.
@ -35,7 +35,7 @@ function truncateFileNameToByteLimit(
let usedBytes = 0;
for (const { segment } of segmenter.segment(stem)) {
const segmentBytes = encoder.encode(segment).byteLength;
if (usedBytes + segmentBytes > stemBudget) break;
if (usedBytes + segmentBytes > stemBudget) {break;}
truncatedStem += segment;
usedBytes += segmentBytes;
}

View file

@ -90,9 +90,9 @@ export class ExpectedFsEvents {
key: RelativePath
): boolean {
const count = map.get(key) ?? 0;
if (count === 0) return false;
if (count === 1) map.delete(key);
else map.set(key, count - 1);
if (count === 0) {return false;}
if (count === 1) {map.delete(key);}
else {map.set(key, count - 1);}
return true;
}
}

View file

@ -72,7 +72,7 @@ export async function scheduleOfflineChanges(
}
for (const path of locallyPossibleCreatedFiles) {
if (renamedPaths.has(path)) continue;
if (renamedPaths.has(path)) {continue;}
logger.info(
`File ${path} was created while offline, scheduling sync to create it`

View file

@ -17,7 +17,7 @@ import {
import { MinCovered } from "../utils/data-structures/min-covered";
export class SyncEventQueue {
private _lastSeenUpdateId: MinCovered;
private readonly _lastSeenUpdateId: MinCovered;
// Latest state of the filesystem as we know it, excluding
// unconfirmed creates but including pending deletes.
@ -441,7 +441,7 @@ export class SyncEventQueue {
newPath: RelativePath
): void {
const createEvent = this.findLatestCreateForPath(oldPath);
if (createEvent === undefined) return;
if (createEvent === undefined) {return;}
const { promise } = createEvent.resolvers;
createEvent.path = newPath;

View file

@ -217,8 +217,8 @@ export class Syncer {
}
private ensureDraining(): void {
if (this.drainPromise !== undefined) return;
if (this.isScanning) return;
if (this.drainPromise !== undefined) {return;}
if (this.isScanning) {return;}
this.drainPromise = this.drain().finally(() => {
this.drainPromise = undefined;
});
@ -329,7 +329,7 @@ export class Syncer {
relativePath = event.path;
break;
case SyncEventType.RemoteChange:
if (event.remoteVersion.isDeleted) return false;
if (event.remoteVersion.isDeleted) {return false;}
sizeInBytes = event.remoteVersion.contentSize;
({ relativePath } = event.remoteVersion);
break;
@ -339,7 +339,7 @@ export class Syncer {
sizeInBytes,
relativePath
);
if (oversizedEntry === undefined) return false;
if (oversizedEntry === undefined) {return false;}
this.history.addHistoryEntry(oversizedEntry);

View file

@ -43,7 +43,7 @@ export class EventListeners<TListener extends (...args: any[]) => any> {
const snapshot = this.listeners.slice();
for (const listener of snapshot) {
// allow removing listeners during the trigger loop
if (!this.listeners.includes(listener)) continue;
if (!this.listeners.includes(listener)) {continue;}
listener(...args);
}
}
@ -59,7 +59,7 @@ export class EventListeners<TListener extends (...args: any[]) => any> {
const snapshot = this.listeners.slice();
const promises: Promise<unknown>[] = [];
for (const listener of snapshot) {
if (!this.listeners.includes(listener)) continue;
if (!this.listeners.includes(listener)) {continue;}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const result = listener(...args);
if (result instanceof Promise) {

View file

@ -531,9 +531,9 @@ export class MockAgent extends MockClient {
private removeBinaryUuid(file: string): void {
const existing = this.files.get(file);
if (existing === undefined) return;
if (existing === undefined) {return;}
const content = new TextDecoder().decode(existing);
if (!content.startsWith("BINARY:")) return;
if (!content.startsWith("BINARY:")) {return;}
const uuid = content.slice("BINARY:".length);
utils.removeFromArray(this.writtenBinaryContents, uuid);
}