deictic 0.5.0 → 0.6.0
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/API.md +15 -8
- package/dist/shared/endpoints.js +34 -8
- package/dist/shared/endpoints.js.map +1 -1
- package/dist/shared/find.js +2 -1
- package/dist/shared/find.js.map +1 -1
- package/dist/shared/index.d.ts +8 -4
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index7.d.ts +2 -0
- package/dist/shared/index7.d.ts.map +1 -1
- package/dist/shared/init.js +12 -10
- package/dist/shared/init.js.map +1 -1
- package/dist/shared/packages.js +1 -1
- package/dist/shared/src.js.map +1 -1
- package/dist/shared/task.js +36 -0
- package/dist/shared/task.js.map +1 -1
- package/dist/shared/tasks.js +108 -114
- package/dist/shared/tasks.js.map +1 -1
- package/dist/tailwind/index.js +6 -2
- package/dist/tailwind/index.js.map +1 -1
- package/dist/tasks/client.d.ts.map +1 -1
- package/dist/tasks/client.js +4 -5
- package/dist/tasks/client.js.map +1 -1
- package/package.json +1 -1
- package/skills/deictic/references/tasks.md +6 -5
- package/src/cli/find.ts +3 -1
- package/src/cli/init.ts +13 -11
- package/src/cli/task.ts +43 -1
- package/src/index.ts +8 -4
- package/src/plugins/tailwind/index.ts +6 -2
- package/src/plugins/tasks/client.ts +4 -5
- package/src/plugins/tasks/index.ts +113 -124
- package/src/tools/endpoints.ts +18 -7
- package/src/tools/source.ts +25 -5
package/src/tools/endpoints.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
17
17
|
|
|
18
|
-
import { type Loc, Refusal, type ServerPlugin, type Target } from '#src/index.ts';
|
|
18
|
+
import { type Loc, Refusal, type ServerPlugin, type Source, type Target } from '#src/index.ts';
|
|
19
19
|
|
|
20
20
|
import { History, type Scope } from './history.ts';
|
|
21
21
|
import { missingMessage } from './packages.ts';
|
|
@@ -63,22 +63,33 @@ export function endpoints({ root, plugins, base = '/', open, history = new Histo
|
|
|
63
63
|
apply: async ({ plugin: name, target, op }) => {
|
|
64
64
|
const plugin = pluginOf(name);
|
|
65
65
|
if (plugin.apply === undefined) throw new Refusal(`${name} changes nothing from its panel: it has no \`apply\``);
|
|
66
|
-
const source =
|
|
67
|
-
const before = await readOf(plugin, target);
|
|
66
|
+
const source = sourceOf(target);
|
|
67
|
+
const before = await readOf(plugin, target, source);
|
|
68
68
|
const { file, line } = target.loc;
|
|
69
69
|
const label = `${name} ${file}:${line}: ${plugin.describe?.(op, before) ?? 'edit'}`;
|
|
70
70
|
const result = await plugin.apply(source, target, op);
|
|
71
71
|
const scope = scopeOf(name, target.loc);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
if (!Array.isArray(result)) return { change: history.record(label, name, result.done, scope), model: await readOf(plugin, target) };
|
|
73
|
+
// Edits to a file whose element isn't found would go who knows where: refused, as only they need it.
|
|
74
|
+
if (source instanceof Refusal) throw source;
|
|
75
|
+
const change = history.commit(label, applyEdits(source, result), scope);
|
|
75
76
|
return { model: await readOf(plugin, target), change };
|
|
76
77
|
},
|
|
77
78
|
undo: async (body) => ({ change: await history.undo(scopeIn(body)) }),
|
|
78
79
|
redo: async (body) => ({ change: await history.redo(scopeIn(body)) }),
|
|
79
80
|
};
|
|
81
|
+
// The source or why it can't be had, for the plugin to decide: only an edit to the file needs it, not a task.
|
|
82
|
+
const sourceOf = (target: Target): Source | Refusal => {
|
|
83
|
+
try {
|
|
84
|
+
return sourceAt(root, target);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
if (e instanceof Refusal) return e;
|
|
87
|
+
throw e;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
80
90
|
// A plugin without `read` has no model, and no need for its element to be where the page says.
|
|
81
|
-
const readOf = (plugin: ServerPlugin, target: Target
|
|
91
|
+
const readOf = (plugin: ServerPlugin, target: Target, source?: Source | Refusal) =>
|
|
92
|
+
plugin.read === undefined ? null : plugin.read(source ?? sourceOf(target), target);
|
|
82
93
|
// One write at a time: a plugin's change may wait on the network, and an undo sent meanwhile must
|
|
83
94
|
// take back that change, not the one before it.
|
|
84
95
|
let queue: Promise<unknown> = Promise.resolve();
|
package/src/tools/source.ts
CHANGED
|
@@ -29,18 +29,38 @@ export function readSource(root: string, file: string): string {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* The target's file and element, as they are on disk now. The element is the one the page's mark names, or else the
|
|
34
|
+
* only one of its tag on that line: the page may count columns in code a plugin before deictic's changed.
|
|
35
|
+
*/
|
|
33
36
|
export function sourceAt(root: string, target: Target): Source {
|
|
34
37
|
const { file, line, column } = target.loc;
|
|
35
38
|
const code = readSource(root, file);
|
|
36
|
-
const
|
|
39
|
+
const lines = lineStarts(code);
|
|
40
|
+
const offset = offsetOf(lines, line, column);
|
|
37
41
|
const { program, elements } = ASTRO.test(file) ? astro(root, file, code) : jsx(file, code);
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
const tagged = elements.filter((el) => isHost(el) && el.name.type === 'JSXIdentifier' && el.name.name === target.tag);
|
|
43
|
+
const start = lines[line - 1];
|
|
44
|
+
const onLine = start === undefined ? [] : tagged.filter((el) => el.start >= start && el.start < (lines[line] ?? Infinity));
|
|
45
|
+
const element = tagged.find((el) => el.start === offset) ?? (onLine.length === 1 ? onLine[0] : undefined);
|
|
46
|
+
if (element === undefined) throw new Refusal(notThere(target, code, lines, onLine.length));
|
|
41
47
|
return { file, code, program, element, read: (other) => readSource(root, other) };
|
|
42
48
|
}
|
|
43
49
|
|
|
50
|
+
/** Why the page's element isn't in the file, from what the file has there: it may not have changed at all. */
|
|
51
|
+
function notThere({ loc: { file, line, column }, tag }: Target, code: string, lines: number[], onLine: number): string {
|
|
52
|
+
const start = lines[line - 1];
|
|
53
|
+
const found =
|
|
54
|
+
start === undefined
|
|
55
|
+
? `${file} has no line ${line}`
|
|
56
|
+
: onLine === 0
|
|
57
|
+
? `line ${line} of ${file} has no <${tag}>: it reads \`${clip(code.slice(start, (lines[line] ?? code.length + 1) - 1).trim())}\``
|
|
58
|
+
: `line ${line} of ${file} has ${onLine} <${tag}>s, none at column ${column}`;
|
|
59
|
+
return `${found}. The page isn't running the file as it is: reload it, and if it says this again, a plugin before deictic's changes the file, so put deictic first`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const clip = (text: string) => (text.length > 80 ? `${text.slice(0, 79)}…` : text);
|
|
63
|
+
|
|
44
64
|
function jsx(file: string, code: string): Parsed {
|
|
45
65
|
const { program, errors } = parse(file, code);
|
|
46
66
|
if (errors.length > 0) throw new Refusal(`${file} doesn't parse: fix it first (${errors[0]!.message})`);
|