Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion configs/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,52 @@ const semi = {
}
};

const blockLayout = {
meta: {
type: "layout",
fixable: "whitespace",
schema: [],
messages: { line: "Put each CSS rule, declaration and closing brace on its own indented line." }
},
create(context) {
return cssVisitor(context, (source, offset) => {
const text = source.text;
const document = context.sourceCode.text;
const newline = document.includes("\r\n") ? "\r\n" : "\n";
function startLine(index, depth) {
const end = offset + index;
const line = document.lastIndexOf("\n", end - 1) + 1;
const prefix = document.slice(line, end);
const indent = " ".repeat(depth);
if (prefix === indent) return;
const start = end - /[ \t]*$/u.exec(prefix)[0].length;
const replacement = prefix.trim() ? newline + indent : indent;
context.report({
loc: context.sourceCode.getLocFromIndex(end),
messageId: "line",
fix: fixer => fixer.replaceTextRange([start, end], replacement)
});
}
function visit(container, depth) {
for (const child of container.children) {
startLine(child.loc.start.offset, depth);
if (child.block?.children.length) {
visit(child.block, depth + 1);
const close = child.block.loc.end.offset - 1;
if (text[close] === "}") startLine(close, depth);
}
}
}
visit(source.ast, offset ? 1 : 0);
if (offset && source.ast.children.length) startLine(text.length, 0);
});
}
};

export default {
rules: {
"css-quotes": quotes,
"css-semi": semi
"css-semi": semi,
"css-block-layout": blockLayout
}
};
10 changes: 10 additions & 0 deletions configs/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@ export default defineConfig(
}, {
selector: "Property[kind=/^(get|set)$/], MethodDefinition[kind=/^(get|set)$/], AccessorProperty",
message: "Use ordinary functions for reads and writes."
}, {
selector: "VariableDeclaration[declarations.length>1] > VariableDeclarator > CallExpression.init:matches([callee.name=/^\\$(state|derived)$/], [callee.object.name='$state'][callee.property.name='raw'], [callee.object.name='$derived'][callee.property.name='by'])",
message: "Declare each reactive binding separately."
}, {
selector: "VariableDeclarator[init.callee.name='$props'] > ObjectPattern[properties.length>=4] > TSTypeAnnotation > :matches(TSTypeLiteral, TSIntersectionType, TSUnionType)",
message: "Give complex component props a named type."
}],
"@stylistic/quotes": ["warn", "double", { avoidEscape: false, allowTemplateLiterals: "always" }],
"@stylistic/semi": ["warn", "always"],
"@stylistic/comma-dangle": ["warn", "never"],
"@stylistic/max-statements-per-line": "warn",
"@stylistic/arrow-spacing": ["warn", { before: true, after: true }],
"@stylistic/brace-style": ["warn", "stroustrup"]
}
Expand Down Expand Up @@ -59,6 +66,8 @@ export default defineConfig(
rules: {
"svelte/indent": ["warn", { indent: 4 }],
"style/component-order": "warn",
"style/attribute-lines": "warn",
"style/binding-indent": "warn",
"svelte/no-restricted-html-elements": ["error", {
elements: ["p"],
message: "Use a div for UI text or a semantic element for a page region."
Expand Down Expand Up @@ -88,6 +97,7 @@ export default defineConfig(
plugins: { local },
rules: {
"local/css-quotes": "warn",
"local/css-block-layout": "warn",
"local/css-semi": "warn"
}
},
Expand Down
71 changes: 53 additions & 18 deletions configs/feed.preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export default defineConfig({
if (event.type === "feed") version++;
});
server.httpServer?.once("close", () => {
unsubscribe(); session.close();
unsubscribe();
session.close();
});

server.middlewares.use(async (req, res, next) => {
Expand All @@ -58,23 +59,57 @@ export default defineConfig({
if (!Array.isArray(args)) throw new LabloomError({ kind: "invalid-argument" });
let result: unknown;
switch (method) {
case "version": result = version; break;
case "getState": result = feed.getState(args[0] as FeedQuery, (args[1] ?? undefined) as string | undefined); break;
case "getRows": result = feed.getRows(args[0] as string[]); break;
case "getItem": result = feed.getItem(args[0] as string); break;
case "resolveSource": result = await feed.resolveSource(args[0] as FeedSourceInput); break;
case "discardSource": result = feed.discardSource(args[0] as string); break;
case "saveSource": result = feed.saveSource(args[0] as string); break;
case "attachPDF": result = papers.attachFile(args[0] as string, "paper_files", args[1] as string, workspaceHistory); break;
case "setSourceStatus": result = feed.setSourceStatus(args[0] as string, args[1] as FeedSourceAction); break;
case "refresh": result = await feed.refresh((args[0] ?? undefined) as string | undefined); break;
case "setRead": result = feed.setRead(args[0] as string, args[1] as boolean); break;
case "markAllRead": result = feed.markAllRead((args[0] ?? undefined) as string | undefined); break;
case "setPosition": result = feed.setPosition(args[0] as string, args[1] as number); break;
case "setKeywords": result = feed.setKeywords(args[0] as string[]); break;
case "importItem": result = feed.importItem(args[0] as string, args[1] === true); break;
case "fetchPDF": result = await feed.fetchPDF(args[0] as string); break;
case "openItem": result = feed.itemURL(args[0] as string); break;
case "version":
result = version;
break;
case "getState":
result = feed.getState(args[0] as FeedQuery, (args[1] ?? undefined) as string | undefined);
break;
case "getRows":
result = feed.getRows(args[0] as string[]);
break;
case "getItem":
result = feed.getItem(args[0] as string);
break;
case "resolveSource":
result = await feed.resolveSource(args[0] as FeedSourceInput);
break;
case "discardSource":
result = feed.discardSource(args[0] as string);
break;
case "saveSource":
result = feed.saveSource(args[0] as string);
break;
case "attachPDF":
result = papers.attachFile(args[0] as string, "paper_files", args[1] as string, workspaceHistory);
break;
case "setSourceStatus":
result = feed.setSourceStatus(args[0] as string, args[1] as FeedSourceAction);
break;
case "refresh":
result = await feed.refresh((args[0] ?? undefined) as string | undefined);
break;
case "setRead":
result = feed.setRead(args[0] as string, args[1] as boolean);
break;
case "markAllRead":
result = feed.markAllRead((args[0] ?? undefined) as string | undefined);
break;
case "setPosition":
result = feed.setPosition(args[0] as string, args[1] as number);
break;
case "setKeywords":
result = feed.setKeywords(args[0] as string[]);
break;
case "importItem":
result = feed.importItem(args[0] as string, args[1] === true);
break;
case "fetchPDF":
result = await feed.fetchPDF(args[0] as string);
break;
case "openItem":
result = feed.itemURL(args[0] as string);
break;
default: throw new LabloomError({ kind: "invalid-argument" });
}
res.end(JSON.stringify(result ?? null));
Expand Down
7 changes: 5 additions & 2 deletions configs/ipcValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ type ModuleKey = { source: string; key: string; watch: string[] };
type Snapshot = { version: string; reads: [string, string][]; modules: Record<string, ModuleKey> };
type Output = { code: string; map: { version: 3; sources: string[]; names: string[]; mappings: string } };
type Compilation = {
builder: ts.SemanticDiagnosticsBuilderProgram; program: ts.Program;
versions: Map<string, string>; common: Hash; watch: Set<string>;
builder: ts.SemanticDiagnosticsBuilderProgram;
program: ts.Program;
versions: Map<string, string>;
common: Hash;
watch: Set<string>;
};

function hash(text: string): string {
Expand Down
90 changes: 88 additions & 2 deletions configs/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,108 @@ export default {
"component-order": {
meta: {
type: "layout",
fixable: "whitespace",
schema: [],
messages: { order: "Place markup first, followed by style and script blocks." }
messages: {
order: "Place markup first, followed by style and script blocks.",
gap: "Leave two blank lines between component sections."
}
},
create(context) {
return {
Program(node) {
let previous = 0;
let end;
const source = context.sourceCode;
const newline = source.text.includes("\r\n") ? "\r\n" : "\n";
for (const part of node.body) {
if (part.type === "SvelteHTMLComment" || (part.type === "SvelteText" && !part.value.trim())) continue;
if (part.type === "SvelteText" && !part.value.trim()) continue;
if (part.type === "SvelteHTMLComment") {
end = part.range[1];
continue;
}
const order = part.type === "SvelteScriptElement" ? 2 : part.type === "SvelteStyleElement" ? 1 : 0;
if (order < previous) context.report({ node: part, messageId: "order" });
if (order && end !== undefined) {
const range = [end, part.range[0]];
const gap = source.text.slice(...range);
if (!gap.trim() && gap !== newline.repeat(3)) {
context.report({
node: part,
messageId: "gap",
fix: fixer => fixer.replaceTextRange(range, newline.repeat(3))
});
}
}
previous = Math.max(previous, order);
end = part.type === "SvelteText" ? part.range[0] + source.getText(part).trimEnd().length : part.range[1];
}
}
};
}
},
"attribute-lines": {
meta: {
type: "layout",
fixable: "whitespace",
schema: [],
messages: { layout: "Put the attributes of a long or multiline tag on separate lines." }
},
create(context) {
const source = context.sourceCode;
const newline = source.text.includes("\r\n") ? "\r\n" : "\n";
return {
SvelteStartTag(node) {
if (node.parent.type !== "SvelteElement" || !node.attributes.length) return;
if (node.loc.start.line === node.loc.end.line && node.range[1] - node.range[0] <= 120) return;
const indent = source.lines[node.loc.start.line - 1].match(/^[ \t]*/u)[0];
const gaps = [];
let end = node.parent.name.range[1];
for (const attribute of node.attributes) {
gaps.push([end, attribute.range[0], indent + " "]);
end = attribute.range[1];
}
gaps.push([end, node.range[1] - (node.selfClosing ? 2 : 1), indent]);
const packed = gaps.filter(([start, stop]) => /^[ \t]*$/u.test(source.text.slice(start, stop)));
if (packed.length) {
context.report({
node,
messageId: "layout",
fix: fixer => packed.map(([start, stop, spaces]) => fixer.replaceTextRange([start, stop], newline + spaces))
});
}
}
};
}
},
"binding-indent": {
meta: {
type: "layout",
fixable: "whitespace",
schema: [],
messages: { indent: "Indent the body of a function binding by four spaces." }
},
create(context) {
const source = context.sourceCode;
function check(position, indent) {
const prefix = source.lines[position.line - 1].slice(0, position.column);
if (prefix === indent || prefix.trim()) return;
const end = source.getIndexFromLoc(position);
context.report({
loc: position,
messageId: "indent",
fix: fixer => fixer.replaceTextRange([end - prefix.length, end], indent)
});
}
return {
"SvelteFunctionBindingsExpression BlockStatement"(node) {
const line = node.parent.type === "BlockStatement" ? node.loc.start.line : node.parent.loc.start.line;
const indent = source.lines[line - 1].match(/^[ \t]*/u)[0];
for (const statement of node.body) check(statement.loc.start, indent + " ");
check(source.getLastToken(node).loc.start, indent);
}
};
}
}
}
};
7 changes: 6 additions & 1 deletion main/attachments/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { LabloomError, diagnostic } from "../../shared/failure";
import { httpURL } from "../../shared/utils/url";
import * as metadata from "./metadata";

export type DownloadOptions = { expectedType?: string; timeoutMs?: number; signal?: AbortSignal; progress?: (bytes: number, total?: number) => void };
export type DownloadOptions = {
expectedType?: string;
timeoutMs?: number;
signal?: AbortSignal;
progress?: (bytes: number, total?: number) => void;
};
type Request = DownloadOptions & { directory: string; fetcher: typeof fetch; signal: AbortSignal };

export const pdfHeader = Buffer.from("%PDF-");
Expand Down
7 changes: 6 additions & 1 deletion main/attachments/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ async function checkPDF(path: string): Promise<void> {
}
}

type PathOptions = { signal?: AbortSignal; progress?: Progress; source?: SourceFile; pdfOnly?: boolean };
type PathOptions = {
signal?: AbortSignal;
progress?: Progress;
source?: SourceFile;
pdfOnly?: boolean;
};
export async function importPath(path: string, options: PathOptions = {}): Promise<MediaFile> {
const session = workspace.requireWorkspace();
const signal = options.signal ? AbortSignal.any([session.controller.signal, options.signal]) : session.controller.signal;
Expand Down
16 changes: 14 additions & 2 deletions main/feed/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,20 @@ import * as workspaceSettings from "../workspaceSettings";
import { type WorkspaceState } from "../workspaceState";
import { FeedError, type FeedResult } from "./parser";

type SourceRow = Omit<FeedSource, "unreadCount" | "refreshing"> & { failures: number; etag: string | null; lastModified: string | null; deleted: boolean };
type Shared = { resolutions: Map<string, { input: FeedSourceInput; feed: FeedResult | null }>; pending: Map<string, Promise<void>>; pdfDownloads: Map<string, Promise<FeedDownload | null>>; pdfFailures: Map<string, FailureInfo>; active: number; waiting: (() => void)[] };
type SourceRow = Omit<FeedSource, "unreadCount" | "refreshing"> & {
failures: number;
etag: string | null;
lastModified: string | null;
deleted: boolean;
};
type Shared = {
resolutions: Map<string, { input: FeedSourceInput; feed: FeedResult | null }>;
pending: Map<string, Promise<void>>;
pdfDownloads: Map<string, Promise<FeedDownload | null>>;
pdfFailures: Map<string, FailureInfo>;
active: number;
waiting: (() => void)[];
};
let state: Shared = newState();
function newState(): Shared {
return { resolutions: new Map(), pending: new Map(), pdfDownloads: new Map(), pdfFailures: new Map(), active: 0, waiting: [] };
Expand Down
6 changes: 5 additions & 1 deletion main/knowledge/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ class ConfirmationRollback extends Error {
}
let effects: (() => void)[] = [];
type Scope = {
options: Options; context: Context; captures: history.Capture[]; invalid: history.Invalidation[]; feed: boolean;
options: Options;
context: Context;
captures: history.Capture[];
invalid: history.Invalidation[];
feed: boolean;
};
const contexts: Scope[] = [];
export function release(): void {
Expand Down
Loading
Loading