reactive-vscode
Version:
Develop VSCode extension with Vue Reactivity API
862 lines (861 loc) • 21.6 kB
JavaScript
import { getCurrentScope as U, onScopeDispose as L, effectScope as Y, shallowRef as g, computed as h, shallowReactive as $, toValue as a, watchEffect as w, watch as C, unref as I, ref as S, toRaw as oe, isRef as ie } from "@reactive-vscode/reactivity";
export * from "@reactive-vscode/reactivity";
import { workspace as T, commands as V, window as v, debug as q, extensions as W, chat as ae, comments as se, env as E, EventEmitter as G, tasks as y, Uri as re, languages as ce, ColorThemeKind as z, l10n as Q, lm as F } from "vscode";
function ue(e) {
return U() ? (L(e), !0) : !1;
}
function N(e, t) {
const n = /* @__PURE__ */ new Map();
return (...o) => {
const i = t(...o);
let r = n.get(i);
return r ? r.refCount++ : (r = {
data: e(...o),
refCount: 1
}, n.set(i, r)), ue(() => {
--r.refCount === 0 && n.delete(i);
}), r.data;
};
}
const J = [];
function le(e) {
J.push(e);
}
function p(e) {
let t = !1, n = !1, o;
return () => {
if (!n) {
if (t)
throw new Error("Cannot call a singleton composable recursively.");
try {
t = !0;
const i = Y(!0);
le(() => i.stop()), o = i.run(e), n = !0;
} finally {
t = !1;
}
}
return o;
};
}
const k = g(null), M = Y();
function Ee(e) {
return {
activate: (t) => (k.value = t, M.run(() => (X.forEach((n) => n(t)), e(t)))),
deactivate: async () => {
await Promise.allSettled(J.map((t) => t())), M.stop();
}
};
}
const X = [];
function Z(e) {
k.value ? e(k.value) : X.push(e);
}
function de(e, t, n) {
const o = !e, i = T.getConfiguration(o ? void 0 : e, n);
function r(u, d) {
const l = g(d), m = h({
get: () => l.value,
set: (f) => {
l.value = f, i.update(u, f);
}
});
return m.update = async (f, b, D) => {
await i.update(u, f, b, D), l.value = f;
}, m.set = (f) => {
l.value = f;
}, m;
}
const s = Object.fromEntries(
Object.keys(t).map((u) => [u, r(u, i.get(u))])
);
return Z(() => {
c(T.onDidChangeConfiguration(
o ? (u) => {
const d = T.getConfiguration();
for (const l in t)
u.affectsConfiguration(l) && s[l].set(d.get(l));
} : (u) => {
if (!u.affectsConfiguration(e))
return;
const d = T.getConfiguration(e);
for (const l in t)
u.affectsConfiguration(`${e}.${l}`) && s[l].set(d.get(l));
}
));
}), s;
}
function ye(e, t, n) {
const o = de(e, t, n), i = {}, r = $({
$update(s, u, d, l) {
return o[s].update(u, d, l);
},
$set(s, u) {
return o[s].set(u);
}
});
for (const s in t) {
const u = s.split(".");
let d = "", l = i, m = r;
for (const b of u.slice(0, -1)) {
d = d ? `${d}.${b}` : b;
const D = l = l[b] ||= {};
if (m[b])
m = m[b];
else {
const H = $({});
Object.defineProperty(m, b, {
enumerable: !0,
get() {
return H;
},
set(ne) {
function B(A, O, K) {
if (A)
for (const R in A)
B(A[R], O ? `${O}.${R}` : R, K?.[R]);
else
o[O].value = K;
}
B(D, d, ne);
}
}), m = H;
}
}
const f = u[u.length - 1];
l[f] = null, Object.defineProperty(m, f, {
enumerable: !0,
get() {
return o[s].value;
},
set(b) {
o[s].value = b;
}
});
}
return r;
}
function ke(e, t) {
const n = g(null), o = [], i = (r) => (...s) => n.value ? n.value[r](...s) : (o.push([r, s]), null);
return Z(() => {
n.value = we(e, t);
for (const [r, s] of o)
n.value[r](...s);
}), {
logger: n,
outputChannel: h(() => n.value?.outputChannel),
info: i("info"),
warn: i("warn"),
error: i("error"),
append: i("append"),
appendLine: i("appendLine"),
replace: i("replace"),
clear: i("clear"),
show: i("show"),
hide: i("hide")
};
}
const Re = p;
function Pe(e, ...t) {
return V.executeCommand(e, ...t);
}
function fe(e, t = !1) {
const n = k.value;
if (!n && !t)
throw new Error("Cannot get absolute path because the extension is not activated yet");
return n?.asAbsolutePath(e);
}
function Ve(e, t = !1) {
return h(() => fe(a(e), t));
}
function c(e) {
return (U() ?? M).cleanups.push(e.dispose.bind(e)), e;
}
const ve = p(() => {
const e = g(v.activeColorTheme);
return c(v.onDidChangeActiveColorTheme((t) => {
e.value = t;
})), e;
}), Ae = p(() => {
const e = g(q.activeDebugSession);
return c(q.onDidChangeActiveDebugSession((t) => {
e.value = t;
})), h(() => e.value);
}), ge = p(() => {
const e = g(v.activeTextEditor);
return c(v.onDidChangeActiveTextEditor((t) => {
e.value = t;
})), e;
});
function he(e) {
const t = g(a(e)?.getText());
return w(() => {
t.value = a(e)?.getText();
}), c(T.onDidChangeTextDocument((n) => {
n.document === a(e) && (t.value = n.document.getText());
})), t;
}
function me(e, t, n, o = {}) {
const {
updateOn: i = ["effect", "documentChanged"]
} = o;
let r;
const s = h(
() => {
r?.dispose(), r = void 0;
const l = a(t);
if ("key" in l)
return l;
const m = v.createTextEditorDecorationType(l);
return r = c(m), m;
}
), u = async () => {
const l = a(e);
l && l.setDecorations(
s.value,
typeof n == "function" ? await n(l) : a(n)
);
}, d = i.includes("documentChanged") ? he(() => a(e)?.document) : null;
return i.includes("effect") ? w(async () => {
d?.value, await u();
}) : d && C(d, u), {
/**
* Manually trigger the decoration update.
*/
update: u
};
}
function Oe(e, t, n = {}) {
const o = ge();
return me(o, e, t, n);
}
const Ie = p(() => {
const e = g(v.activeNotebookEditor);
return c(v.onDidChangeActiveNotebookEditor((t) => {
e.value = t;
})), e;
}), We = p(() => {
const e = g(v.activeTerminal);
return c(v.onDidChangeActiveTerminal((t) => {
e.value = t;
})), e;
}), Fe = p(() => {
const e = g(W.all);
return c(W.onDidChange(() => {
e.value = W.all;
})), h(() => e.value);
});
function x(e, t) {
const n = (o, i, r) => {
c(e(o, i, r));
};
return t?.forEach((o) => n(o)), n;
}
function _(e, t, n) {
for (const o of n) {
const i = t[o];
i !== void 0 && w(() => {
e[o] = a(i);
});
}
}
const $e = N((e, t, n = {}) => {
const o = c(ae.createChatParticipant(e, I(t)));
return _(o, n, [
"iconPath"
]), n.followupProvider !== void 0 && w(() => {
o.followupProvider = I(n.followupProvider);
}), w(() => {
o.requestHandler = I(t);
}), {
onDidReceiveFeedback: x(o.onDidReceiveFeedback)
};
}, (e) => e);
function be(e, t) {
c(V.registerCommand(e, t));
}
function Me(e) {
for (const [t, n] of Object.entries(e))
n && be(t, n);
}
function Le(e, t) {
return c(se.createCommentController(e, t));
}
function ee(e) {
const t = g(a(e)?.state);
return C(e, () => {
t.value = a(e)?.state;
}), c(v.onDidChangeTerminalState((n) => {
n === a(e) && (t.value = n.state);
})), h(() => t.value);
}
function Ne(...e) {
const t = S(null);
function n() {
return !!t.value && t.value.exitStatus == null;
}
function o() {
return n() ? t.value : t.value = v.createTerminal(...e);
}
function i(u) {
o().sendText(u);
}
function r() {
o().show();
}
function s() {
n() && (t.value.sendText(""), t.value.dispose(), t.value = null);
}
return L(s), {
terminal: t,
getIsActive: n,
show: r,
sendText: i,
close: s,
state: ee(t)
};
}
const je = p(() => {
const e = g(E.shell);
return c(E.onDidChangeShell((t) => {
e.value = t;
})), h(() => e.value);
});
function P(e, t = []) {
const n = Array.isArray(e) ? e : t ?? [], o = c(Array.isArray(e) || e == null ? new G() : e), i = x(o.event, n);
for (const r of n)
i(r);
return {
event: o.event,
fire: o.fire.bind(o),
addListener: i
};
}
async function He(e) {
const t = k.value.secrets, n = S(await t.get(e));
return n.set = async (o) => {
n.value = o, await t.store(e, o);
}, n.remove = async () => {
n.value = void 0, await t.delete(e);
}, c(t.onDidChange(async (o) => {
o.key === e && (n.value = await t.get(e));
})), C(n, (o) => {
o === void 0 ? t.delete(e) : t.store(e, o);
}), n;
}
function Be(e) {
return h(() => y.fetchTasks(a(e)));
}
function Ke(e) {
return h(() => re.file(a(e)));
}
function qe(e, t) {
const n = new G(), o = g();
w(() => {
o.value && n.fire(), o.value = a(t);
}), c(ce.registerFoldingRangeProvider(
e,
{
onDidChangeFoldingRanges: n.event,
provideFoldingRanges(i, r, s) {
return o.value?.(i, r, s);
}
}
));
}
function ze(e, t, n, o) {
const i = $(/* @__PURE__ */ new Map()), r = P(), s = P(), u = P(), d = h(() => {
const f = a(e);
return Array.isArray(f) ? f : f instanceof Set ? Array.from(f) : [f];
});
function l() {
const f = d.value;
for (const [b, D] of i)
f.includes(b) || (D.dispose(), i.delete(b));
for (const b of f)
if (!i.has(b)) {
const D = T.createFileSystemWatcher(
b,
a(t) || !1,
a(n) || !1,
a(o) || !1
);
D.onDidCreate(r.fire), D.onDidChange(s.fire), D.onDidDelete(u.fire), i.set(b, D);
}
}
function m() {
for (const f of i.values())
f.dispose();
i.clear();
}
return l(), C(d, l), C(
() => [
a(t),
a(n),
a(o)
],
() => {
m(), l();
}
), L(m), {
watchers: i,
onDidCreate: r.event,
onDidChange: s.event,
onDidDelete: u.event
};
}
const Qe = p(() => {
const e = ve();
return h(() => e.value.kind === z.Dark || e.value.kind === z.HighContrast);
}), Ue = p(() => {
const e = g(E.isTelemetryEnabled);
return c(E.onDidChangeTelemetryEnabled((t) => {
e.value = t;
})), h(() => e.value);
});
function Ye(e, ...t) {
return h(() => typeof t[0] == "object" ? Q.t(a(e), oe(t[0])) : Q.t(a(e), ...t.map(a)));
}
const Ge = p(() => {
const e = g(F.tools);
return c(F.onDidChangeChatModels(() => {
e.value = F.tools;
})), h(() => e.value);
});
function pe(e, t) {
return c(v.createOutputChannel(e, t));
}
function Je(e) {
const t = /* @__PURE__ */ new Date(), n = String(t.getFullYear()).padStart(4, "0"), o = String(t.getMonth() + 1).padStart(2, "0"), i = String(t.getDate()).padStart(2, "0"), r = String(t.getHours()).padStart(2, "0"), s = String(t.getMinutes()).padStart(2, "0"), u = String(t.getSeconds()).padStart(2, "0"), d = String(t.getMilliseconds()).padStart(3, "0");
return `${n}-${o}-${i} ${r}:${s}:${u}.${d} [${e}] `;
}
function we(e, t = {}) {
const n = t.outputChannel ?? pe(e, { log: !0 }), o = t.toConsole ?? ["error", "warn"], i = (r) => (...s) => {
n.appendLine((t.getPrefix?.(r) ?? "") + s.join(" ")), o.includes(r) && console[r](...s);
};
return {
outputChannel: n,
createLoggerFunc: i,
info: i("info"),
warn: i("warn"),
error: i("error"),
append: n.append.bind(n),
appendLine: n.appendLine.bind(n),
replace: n.replace.bind(n),
clear: n.clear.bind(n),
show: n.show.bind(n),
hide: n.hide.bind(n)
};
}
const Xe = p(() => {
const e = g(E.logLevel);
return c(E.onDidChangeLogLevel((t) => {
e.value = t;
})), h(() => e.value);
});
function Ce(e) {
const t = g(a(e)?.selections ?? []);
return C(e, () => {
t.value = a(e)?.selections ?? [];
}), c(v.onDidChangeNotebookEditorSelection((n) => {
n.notebookEditor === a(e) && (t.value = n.selections);
})), h({
get() {
return t.value;
},
set(n) {
t.value = n;
const o = a(e);
o && (o.selections = n);
}
});
}
function Ze(e) {
const t = Ce(e);
return h({
get() {
return t.value[0];
},
set(n) {
t.value = t.value.toSpliced(0, 1, n);
}
});
}
function _e(e) {
const t = g(a(e)?.visibleRanges ?? []);
return C(e, () => {
t.value = a(e)?.visibleRanges ?? [];
}), c(v.onDidChangeNotebookEditorVisibleRanges((n) => {
n.notebookEditor === a(e) && (t.value = n.visibleRanges);
})), h(() => t.value);
}
const et = p(() => {
const e = g(v.terminals);
function t() {
e.value = v.terminals;
}
return c(v.onDidOpenTerminal(t)), c(v.onDidCloseTerminal(t)), e;
});
function tt(e = {}) {
const t = c(v.createQuickPick()), n = x(t.onDidChangeActive), o = x(t.onDidChangeSelection), i = x(t.onDidAccept), r = x(t.onDidHide), s = x(t.onDidTriggerButton), u = x(t.onDidChangeValue);
[
"items",
"buttons",
"title",
"step",
"totalSteps",
"enabled",
"busy",
"ignoreFocusOut",
"placeholder",
"canSelectMany",
"matchOnDescription",
"matchOnDetail",
"keepScrollPosition"
].forEach((f) => {
e[f] && w(() => t[f] = a(e[f]));
}), e.value && (t.value = e.value);
const d = g(t.value);
u((f) => d.value = f), e.activeItems && (t.activeItems = e.activeItems);
const l = g(t.activeItems);
n((f) => l.value = f), e.selectedItems && (t.selectedItems = e.selectedItems);
const m = g(t.selectedItems);
return o((f) => m.value = f), {
...t,
onDidChangeActive: n,
onDidChangeSelection: o,
onDidAccept: i,
onDidHide: r,
onDidTriggerButton: s,
onDidChangeValue: u,
value: d,
activeItems: l,
selectedItems: m
};
}
function nt(e) {
const t = c(e.id ? v.createStatusBarItem(e.id, e.alignment, e.priority) : v.createStatusBarItem(e.alignment, e.priority));
return _(t, e, [
"name",
"text",
"tooltip",
"color",
"backgroundColor",
"command",
"accessibilityInformation"
]), e.visible != null ? w(() => {
a(e.visible) ? t.show() : t.hide();
}) : t.show(), t;
}
const ot = p(() => {
const e = g(y.taskExecutions);
function t() {
e.value = y.taskExecutions;
}
return c(y.onDidStartTask(t)), c(y.onDidEndTask(t)), h(() => e.value);
});
function it(...e) {
const t = c(v.createTerminal(...e));
return {
terminal: t,
get name() {
return t.name;
},
get processId() {
return t.processId;
},
get creationOptions() {
return t.creationOptions;
},
get exitStatus() {
return t.exitStatus;
},
get shellIntegration() {
return t.shellIntegration;
},
sendText: t.sendText.bind(t),
show: t.show.bind(t),
hide: t.hide.bind(t),
state: ee(t)
};
}
function De(e, t) {
c(V.registerTextEditorCommand(e, t));
}
function at(e) {
for (const [t, n] of Object.entries(e))
De(t, n);
}
function Te(e, t) {
const n = g(a(e)?.selections ?? []);
return C(e, () => {
n.value = a(e)?.selections ?? [];
}), c(v.onDidChangeTextEditorSelection((o) => {
const i = a(e), r = a(t);
o.textEditor === i && (!r || r.includes(o.kind)) && (n.value = o.selections);
})), h({
get() {
return n.value;
},
set(o) {
n.value = o;
const i = a(e);
i && (i.selections = o);
}
});
}
function st(e, t) {
const n = Te(e, t);
return h({
get() {
return n.value[0];
},
set(o) {
n.value = n.value.toSpliced(0, 1, o);
}
});
}
function rt(e) {
const t = g(a(e)?.viewColumn);
return C(e, () => {
t.value = a(e)?.viewColumn;
}), c(v.onDidChangeTextEditorViewColumn((n) => {
n.textEditor === a(e) && (t.value = n.viewColumn);
})), h(() => t.value);
}
function ct(e) {
const t = g(a(e)?.visibleRanges ?? []);
return C(e, () => {
t.value = a(e)?.visibleRanges ?? [];
}), c(v.onDidChangeTextEditorVisibleRanges((n) => {
n.textEditor === a(e) && (t.value = n.visibleRanges);
})), h(() => t.value);
}
function te(e, t) {
w(() => {
const n = a(e);
n && (n.badge = a(t));
});
}
function j(e, t) {
w(() => {
const n = a(e);
n && (n.title = a(t));
});
}
const ut = N(
(e, t, n) => {
const o = P();
C(t, () => o.fire()), n?.watchSource && C(n.watchSource, () => o.fire());
const i = /* @__PURE__ */ new WeakMap(), r = c(v.createTreeView(e, {
...n,
treeDataProvider: {
...n,
onDidChangeTreeData: o.event,
getTreeItem(s) {
return s.treeItem;
},
async getChildren(s) {
if (s) {
const u = await s.children;
return u?.forEach((d) => i.set(d, s)), u;
}
return a(t);
},
getParent(s) {
return i.get(s);
}
}
}));
return n?.title && j(r, n.title), n?.badge && te(r, n.badge), r;
},
(e) => e
);
function lt(e) {
const t = S(a(e)?.visible);
function n() {
t.value = a(e)?.visible;
}
return w((o) => {
const i = a(e);
if (i) {
const r = i.onDidChangeVisibility(n);
o(() => r.dispose());
}
}), w(n), h(() => !!t.value);
}
const dt = p(() => {
const e = g(v.visibleNotebookEditors);
return c(v.onDidChangeVisibleNotebookEditors((t) => {
e.value = t;
})), e;
}), ft = p(() => {
const e = g(v.visibleTextEditors);
return c(v.onDidChangeVisibleTextEditors((t) => {
e.value = t;
})), e;
});
function vt(e, t, n = !0) {
const o = ie(t) ? t : typeof t == "function" ? h(t) : S(t);
return w(() => {
a(n) && V.executeCommand("setContext", e, o.value);
}), o;
}
function gt(e, t, n, o, i) {
const r = g(), s = c(v.createWebviewPanel(
e,
a(t),
o,
{
enableFindWidget: i?.enableFindWidget,
retainContextWhenHidden: i?.retainContextWhenHidden,
...a(i?.webviewOptions)
}
));
i?.onDidReceiveMessage && s.webview.onDidReceiveMessage(i.onDidReceiveMessage);
const u = S(0);
function d() {
u.value++;
}
if (w(() => {
s.webview.html = `${a(n)}<!--${u.value}-->`;
}), i?.webviewOptions) {
const b = i.webviewOptions;
w(() => {
s.webview.options = a(b);
});
}
j(s, t);
function l(b) {
return s.webview.postMessage(b);
}
const m = S(s.active), f = S(s.visible);
return c(s.onDidChangeViewState(() => {
m.value = s.active, f.value = s.visible;
})), { panel: s, context: r, active: m, visible: f, postMessage: l, forceRefresh: d };
}
const ht = N(
(e, t, n) => {
const o = g(), i = g();
c(v.registerWebviewViewProvider(
e,
{
resolveWebviewView(d, l) {
o.value = d, i.value = l, n?.onDidReceiveMessage && d.webview.onDidReceiveMessage(n.onDidReceiveMessage);
}
},
{
webviewOptions: {
retainContextWhenHidden: n?.retainContextWhenHidden
}
}
));
const r = S(0);
function s() {
r.value++;
}
if (w(() => {
o.value && (o.value.webview.html = `${a(t)}<!--${r.value}-->`);
}), n?.webviewOptions) {
const d = n.webviewOptions;
w(() => {
o.value && (o.value.webview.options = a(d));
});
}
n?.title && j(o, n.title), n?.badge && te(o, n.badge);
function u(d) {
return o.value?.webview.postMessage(d);
}
return { view: o, context: i, postMessage: u, forceRefresh: s };
},
(e) => e
), mt = p(() => {
const e = g(v.state);
return c(v.onDidChangeWindowState((t) => {
e.value = t;
})), {
focused: h(() => e.value.focused),
active: h(() => e.value.active)
};
}), bt = p(() => {
const e = g(T.workspaceFolders);
return c(T.onDidChangeWorkspaceFolders(() => {
e.value = T.workspaceFolders;
})), h(() => e.value);
});
export {
X as activateCbs,
N as createKeyedComposable,
p as createSingletonComposable,
J as deactivateCbs,
ye as defineConfigObject,
de as defineConfigs,
Ee as defineExtension,
ke as defineLogger,
Re as defineService,
Pe as executeCommand,
k as extensionContext,
M as extensionScope,
Je as getDefaultLoggerPrefix,
Z as onActivate,
le as onDeactivate,
ue as tryOnScopeDispose,
Ve as useAbsolutePath,
ve as useActiveColorTheme,
Ae as useActiveDebugSession,
Oe as useActiveEditorDecorations,
Ie as useActiveNotebookEditor,
We as useActiveTerminal,
ge as useActiveTextEditor,
Fe as useAllExtensions,
$e as useChatParticipant,
be as useCommand,
Me as useCommands,
Le as useCommentController,
Ne as useControlledTerminal,
je as useDefaultShell,
c as useDisposable,
he as useDocumentText,
me as useEditorDecorations,
x as useEvent,
P as useEventEmitter,
He as useExtensionSecret,
Be as useFetchTasks,
Ke as useFileUri,
qe as useFoldingRangeProvider,
ze as useFsWatcher,
Qe as useIsDarkTheme,
Ue as useIsTelemetryEnabled,
Ye as useL10nText,
Ge as useLmTools,
Xe as useLogLevel,
we as useLogger,
Ze as useNotebookEditorSelection,
Ce as useNotebookEditorSelections,
_e as useNotebookEditorVisibleRanges,
et as useOpenedTerminals,
pe as useOutputChannel,
tt as useQuickPick,
_ as useReactiveOptions,
nt as useStatusBarItem,
ot as useTaskExecutions,
it as useTerminal,
ee as useTerminalState,
De as useTextEditorCommand,
at as useTextEditorCommands,
st as useTextEditorSelection,
Te as useTextEditorSelections,
rt as useTextEditorViewColumn,
ct as useTextEditorVisibleRanges,
ut as useTreeView,
te as useViewBadge,
j as useViewTitle,
lt as useViewVisibility,
dt as useVisibleNotebookEditors,
ft as useVisibleTextEditors,
vt as useVscodeContext,
gt as useWebviewPanel,
ht as useWebviewView,
mt as useWindowState,
bt as useWorkspaceFolders
};