Linting
This commit is contained in:
parent
8eae770621
commit
8b7be48522
13 changed files with 37 additions and 28 deletions
|
|
@ -192,6 +192,10 @@ export class DeterministicAgent extends debugging.InMemoryFileSystem {
|
||||||
const isNew = !this.files.has(path);
|
const isNew = !this.files.has(path);
|
||||||
await super.write(path, content);
|
await super.write(path, content);
|
||||||
|
|
||||||
|
if (!this.isSyncEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
this.enqueueSync(async () => {
|
this.enqueueSync(async () => {
|
||||||
this.client.syncLocallyCreatedFile(path);
|
this.client.syncLocallyCreatedFile(path);
|
||||||
|
|
@ -208,9 +212,11 @@ export class DeterministicAgent extends debugging.InMemoryFileSystem {
|
||||||
updater: (current: TextWithCursors) => TextWithCursors
|
updater: (current: TextWithCursors) => TextWithCursors
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const result = await super.atomicUpdateText(path, updater);
|
const result = await super.atomicUpdateText(path, updater);
|
||||||
|
if (this.isSyncEnabled) {
|
||||||
this.enqueueSync(async () => {
|
this.enqueueSync(async () => {
|
||||||
this.client.syncLocallyUpdatedFile({ relativePath: path });
|
this.client.syncLocallyUpdatedFile({ relativePath: path });
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -228,6 +234,7 @@ export class DeterministicAgent extends debugging.InMemoryFileSystem {
|
||||||
newPath: RelativePath
|
newPath: RelativePath
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await super.rename(oldPath, newPath);
|
await super.rename(oldPath, newPath);
|
||||||
|
if (this.isSyncEnabled) {
|
||||||
this.enqueueSync(async () => {
|
this.enqueueSync(async () => {
|
||||||
this.client.syncLocallyUpdatedFile({
|
this.client.syncLocallyUpdatedFile({
|
||||||
oldPath,
|
oldPath,
|
||||||
|
|
@ -235,6 +242,7 @@ export class DeterministicAgent extends debugging.InMemoryFileSystem {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async waitForWebSocket(): Promise<void> {
|
private async waitForWebSocket(): Promise<void> {
|
||||||
const deadline = Date.now() + WEBSOCKET_CONNECT_TIMEOUT_MS;
|
const deadline = Date.now() + WEBSOCKET_CONNECT_TIMEOUT_MS;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ export function parseConcurrency(): number {
|
||||||
i + 1 < args.length
|
i + 1 < args.length
|
||||||
) {
|
) {
|
||||||
const n = parseInt(args[i + 1], 10);
|
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;
|
return os.cpus().length;
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ export class ServerManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async stopAll(): Promise<void> {
|
public async stopAll(): Promise<void> {
|
||||||
if (this.isShuttingDown) return;
|
if (this.isShuttingDown) {return;}
|
||||||
this.isShuttingDown = true;
|
this.isShuttingDown = true;
|
||||||
|
|
||||||
const servers = Array.from(this.activeServers);
|
const servers = Array.from(this.activeServers);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ export default [
|
||||||
rules: {
|
rules: {
|
||||||
"no-console": "error",
|
"no-console": "error",
|
||||||
"no-unused-vars": "off",
|
"no-unused-vars": "off",
|
||||||
|
"curly": ["error", "all"],
|
||||||
"@typescript-eslint/restrict-template-expressions": "off",
|
"@typescript-eslint/restrict-template-expressions": "off",
|
||||||
"@typescript-eslint/no-unused-vars": "off",
|
"@typescript-eslint/no-unused-vars": "off",
|
||||||
"@typescript-eslint/no-floating-promises": [
|
"@typescript-eslint/no-floating-promises": [
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ export function renderCursorsInFileExplorer(
|
||||||
app: App
|
app: App
|
||||||
): void {
|
): void {
|
||||||
const fileExplorers = app.workspace.getLeavesOfType("file-explorer");
|
const fileExplorers = app.workspace.getLeavesOfType("file-explorer");
|
||||||
if (fileExplorers.length == 0) return;
|
if (fileExplorers.length == 0) {return;}
|
||||||
|
|
||||||
const [fileExplorer] = fileExplorers;
|
const [fileExplorer] = fileExplorers;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ export class SyncService {
|
||||||
response: Response,
|
response: Response,
|
||||||
operation: string
|
operation: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (response.ok) return;
|
if (response.ok) {return;}
|
||||||
const message = `Failed to ${operation}: ${await SyncService.errorFromResponse(response)}`;
|
const message = `Failed to ${operation}: ${await SyncService.errorFromResponse(response)}`;
|
||||||
// 429 is the only 4xx the server uses for *transient* contention
|
// 429 is the only 4xx the server uses for *transient* contention
|
||||||
// (`WriteBusyError` → HTTP 429). Every other 4xx means the request
|
// (`WriteBusyError` → HTTP 429). Every other 4xx means the request
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ function truncateFileNameToByteLimit(
|
||||||
maxBytes: number
|
maxBytes: number
|
||||||
): string {
|
): string {
|
||||||
const encoder = new TextEncoder();
|
const encoder = new TextEncoder();
|
||||||
if (encoder.encode(fileName).byteLength <= maxBytes) return fileName;
|
if (encoder.encode(fileName).byteLength <= maxBytes) {return fileName;}
|
||||||
|
|
||||||
const dotIndex = fileName.lastIndexOf(".");
|
const dotIndex = fileName.lastIndexOf(".");
|
||||||
// Dotfile (starts with "." and nothing else) → no extension to preserve.
|
// Dotfile (starts with "." and nothing else) → no extension to preserve.
|
||||||
|
|
@ -35,7 +35,7 @@ function truncateFileNameToByteLimit(
|
||||||
let usedBytes = 0;
|
let usedBytes = 0;
|
||||||
for (const { segment } of segmenter.segment(stem)) {
|
for (const { segment } of segmenter.segment(stem)) {
|
||||||
const segmentBytes = encoder.encode(segment).byteLength;
|
const segmentBytes = encoder.encode(segment).byteLength;
|
||||||
if (usedBytes + segmentBytes > stemBudget) break;
|
if (usedBytes + segmentBytes > stemBudget) {break;}
|
||||||
truncatedStem += segment;
|
truncatedStem += segment;
|
||||||
usedBytes += segmentBytes;
|
usedBytes += segmentBytes;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,9 +90,9 @@ export class ExpectedFsEvents {
|
||||||
key: RelativePath
|
key: RelativePath
|
||||||
): boolean {
|
): boolean {
|
||||||
const count = map.get(key) ?? 0;
|
const count = map.get(key) ?? 0;
|
||||||
if (count === 0) return false;
|
if (count === 0) {return false;}
|
||||||
if (count === 1) map.delete(key);
|
if (count === 1) {map.delete(key);}
|
||||||
else map.set(key, count - 1);
|
else {map.set(key, count - 1);}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ export async function scheduleOfflineChanges(
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const path of locallyPossibleCreatedFiles) {
|
for (const path of locallyPossibleCreatedFiles) {
|
||||||
if (renamedPaths.has(path)) continue;
|
if (renamedPaths.has(path)) {continue;}
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
`File ${path} was created while offline, scheduling sync to create it`
|
`File ${path} was created while offline, scheduling sync to create it`
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import {
|
||||||
import { MinCovered } from "../utils/data-structures/min-covered";
|
import { MinCovered } from "../utils/data-structures/min-covered";
|
||||||
|
|
||||||
export class SyncEventQueue {
|
export class SyncEventQueue {
|
||||||
private _lastSeenUpdateId: MinCovered;
|
private readonly _lastSeenUpdateId: MinCovered;
|
||||||
|
|
||||||
// Latest state of the filesystem as we know it, excluding
|
// Latest state of the filesystem as we know it, excluding
|
||||||
// unconfirmed creates but including pending deletes.
|
// unconfirmed creates but including pending deletes.
|
||||||
|
|
@ -441,7 +441,7 @@ export class SyncEventQueue {
|
||||||
newPath: RelativePath
|
newPath: RelativePath
|
||||||
): void {
|
): void {
|
||||||
const createEvent = this.findLatestCreateForPath(oldPath);
|
const createEvent = this.findLatestCreateForPath(oldPath);
|
||||||
if (createEvent === undefined) return;
|
if (createEvent === undefined) {return;}
|
||||||
|
|
||||||
const { promise } = createEvent.resolvers;
|
const { promise } = createEvent.resolvers;
|
||||||
createEvent.path = newPath;
|
createEvent.path = newPath;
|
||||||
|
|
|
||||||
|
|
@ -217,8 +217,8 @@ export class Syncer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ensureDraining(): void {
|
private ensureDraining(): void {
|
||||||
if (this.drainPromise !== undefined) return;
|
if (this.drainPromise !== undefined) {return;}
|
||||||
if (this.isScanning) return;
|
if (this.isScanning) {return;}
|
||||||
this.drainPromise = this.drain().finally(() => {
|
this.drainPromise = this.drain().finally(() => {
|
||||||
this.drainPromise = undefined;
|
this.drainPromise = undefined;
|
||||||
});
|
});
|
||||||
|
|
@ -329,7 +329,7 @@ export class Syncer {
|
||||||
relativePath = event.path;
|
relativePath = event.path;
|
||||||
break;
|
break;
|
||||||
case SyncEventType.RemoteChange:
|
case SyncEventType.RemoteChange:
|
||||||
if (event.remoteVersion.isDeleted) return false;
|
if (event.remoteVersion.isDeleted) {return false;}
|
||||||
sizeInBytes = event.remoteVersion.contentSize;
|
sizeInBytes = event.remoteVersion.contentSize;
|
||||||
({ relativePath } = event.remoteVersion);
|
({ relativePath } = event.remoteVersion);
|
||||||
break;
|
break;
|
||||||
|
|
@ -339,7 +339,7 @@ export class Syncer {
|
||||||
sizeInBytes,
|
sizeInBytes,
|
||||||
relativePath
|
relativePath
|
||||||
);
|
);
|
||||||
if (oversizedEntry === undefined) return false;
|
if (oversizedEntry === undefined) {return false;}
|
||||||
|
|
||||||
this.history.addHistoryEntry(oversizedEntry);
|
this.history.addHistoryEntry(oversizedEntry);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ export class EventListeners<TListener extends (...args: any[]) => any> {
|
||||||
const snapshot = this.listeners.slice();
|
const snapshot = this.listeners.slice();
|
||||||
for (const listener of snapshot) {
|
for (const listener of snapshot) {
|
||||||
// allow removing listeners during the trigger loop
|
// allow removing listeners during the trigger loop
|
||||||
if (!this.listeners.includes(listener)) continue;
|
if (!this.listeners.includes(listener)) {continue;}
|
||||||
listener(...args);
|
listener(...args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -59,7 +59,7 @@ export class EventListeners<TListener extends (...args: any[]) => any> {
|
||||||
const snapshot = this.listeners.slice();
|
const snapshot = this.listeners.slice();
|
||||||
const promises: Promise<unknown>[] = [];
|
const promises: Promise<unknown>[] = [];
|
||||||
for (const listener of snapshot) {
|
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
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
const result = listener(...args);
|
const result = listener(...args);
|
||||||
if (result instanceof Promise) {
|
if (result instanceof Promise) {
|
||||||
|
|
|
||||||
|
|
@ -531,9 +531,9 @@ export class MockAgent extends MockClient {
|
||||||
|
|
||||||
private removeBinaryUuid(file: string): void {
|
private removeBinaryUuid(file: string): void {
|
||||||
const existing = this.files.get(file);
|
const existing = this.files.get(file);
|
||||||
if (existing === undefined) return;
|
if (existing === undefined) {return;}
|
||||||
const content = new TextDecoder().decode(existing);
|
const content = new TextDecoder().decode(existing);
|
||||||
if (!content.startsWith("BINARY:")) return;
|
if (!content.startsWith("BINARY:")) {return;}
|
||||||
const uuid = content.slice("BINARY:".length);
|
const uuid = content.slice("BINARY:".length);
|
||||||
utils.removeFromArray(this.writtenBinaryContents, uuid);
|
utils.removeFromArray(this.writtenBinaryContents, uuid);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue