Make Git a native feature with an off switch
- Add the native feature runtime in src/lib/features/: the catalog, the switches, the first-start migration, the loader, and the feature sessions. - Add Settings → Features and the features settings section. - Add features_legacy. It reads the old plugin packages and changes nothing. - Move Git from the plugin into src/lib/features/git/, on host internals. - Remove api.git, the git contribution key, and the SDK Git types. - Add pnpm check:features. It fails when a feature module loads at start. - Update the tests, the menu inventory, the docs, and UI-055.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { t } from "$lib/i18n";
|
||||
import { commandShortcut } from "./workbenchKeys";
|
||||
import { pluginHost } from "$lib/plugins/registry";
|
||||
import { featureSwitches } from "$lib/features/state";
|
||||
import { gitApi } from "$lib/git/service";
|
||||
import type { GitLineInfo } from "$lib/git/contracts";
|
||||
import FindPanel from "$lib/editor/FindPanel.svelte";
|
||||
import { readingSearch } from "$lib/editor/readingSearch";
|
||||
@@ -49,7 +50,8 @@
|
||||
let { buffer, tabs, chrome, reading, split, focusLine, onChange, onRenameTitle, onInsertImage, onView, onSplit, onCursor, onOpenLink, onOpenWorkspace, onNewFile, onNewNote, onQuickOpen, onOpenBrowser, browserOpening = false, hasWorkspace, tableActions, linkActions, active = true, onCloseSplit }: Props = $props();
|
||||
let selectedLine = $state(1);
|
||||
let lineInfo = $state<GitLineInfo | null>(null);
|
||||
const git = $derived.by(() => { void $pluginHost; return pluginHost.get("git"); });
|
||||
// The blame line needs no feature code: it calls the host Git service while the Git feature is on.
|
||||
const git = $derived($featureSwitches.git ? gitApi : null);
|
||||
$effect(() => { void buffer?.id; selectedLine = 1; });
|
||||
$effect(() => {
|
||||
void buffer?.id;
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
import PluginSettings from "$lib/plugins/PluginSettings.svelte";
|
||||
import { installedPlugins, pluginTools } from "$lib/plugins/external";
|
||||
import { pluginHost } from "$lib/plugins/registry";
|
||||
import { FEATURES, type FeatureId } from "$lib/features/catalog";
|
||||
import { featureSwitches, setFeature } from "$lib/features/state";
|
||||
import { featureErrors } from "$lib/features/loader";
|
||||
import { onMount, untrack, type Snippet } from "svelte";
|
||||
import Icon from "$lib/ui/Icon.svelte";
|
||||
import IconButton, { type IconName } from "$lib/ui/IconButton.svelte";
|
||||
@@ -51,6 +54,7 @@
|
||||
{ id: "about", label: $t("Help and about"), icon: "help", keywords: "help about version shortcuts keyboard guide" },
|
||||
{ id: "general", label: $t("General"), icon: "settings", keywords: "auto-save autosave save interval seconds files language français 日本語 简体中文 tables table formulas calculate" },
|
||||
{ id: "appearance", label: $t("Appearance"), icon: "sun", keywords: "theme colors light dark Claude Sakura Harvest Moon Crimson Pilot Silver Serpent" },
|
||||
{ id: "features", label: $t("Features"), icon: "toggle", keywords: `features off switch memory ${FEATURES.map(feature => `${$t(feature.name)} ${feature.keywords}`).join(" ")}` },
|
||||
{ id: "plugins", label: $t("Plug-ins"), icon: "puzzle", keywords: "plugins extensions community" },
|
||||
]);
|
||||
let section = $state<Section>(untrack(() => help ? "about" : "general"));
|
||||
@@ -95,6 +99,12 @@
|
||||
apply({ ...settings, autosaveSeconds: seconds });
|
||||
}
|
||||
|
||||
function changeFeature(id: FeatureId, on: boolean) {
|
||||
error = "";
|
||||
setFeature(id, on).then(() => { message = $t("Changes saved."); })
|
||||
.catch(() => { error = $t("Could not save these settings. Your previous settings still apply. Try again."); message = ""; });
|
||||
}
|
||||
|
||||
function select(next: Section) { section = next; error = ""; message = ""; seconds = settings.autosaveSeconds; }
|
||||
|
||||
function trapFocus(event: KeyboardEvent) {
|
||||
@@ -180,6 +190,23 @@
|
||||
<p class="saved" role="status">{message}</p>
|
||||
{:else if selected.id === "appearance"}
|
||||
<AppearanceSettings />
|
||||
{:else if selected.id === "features"}
|
||||
<h2>{$t("Features")}</h2>
|
||||
<p class="intro">{$t("Turn off the features that you do not use. A feature that is off does not load, and its controls do not show.")}</p>
|
||||
<div class="card">
|
||||
{#each FEATURES as feature (feature.id)}
|
||||
<div class="setting-row">
|
||||
<div>
|
||||
<label for={`feature-${feature.id}`}>{$t(feature.name)}</label>
|
||||
<p id={`feature-${feature.id}-description`}>{$t(feature.description)}</p>
|
||||
{#if $featureErrors[feature.id]}<p class="error" role="alert">{$t("{name} could not load: {error}", { name: $t(feature.name), error: $featureErrors[feature.id] ?? "" })}</p>{/if}
|
||||
</div>
|
||||
<input id={`feature-${feature.id}`} class="rs-switch" type="checkbox" role="switch" aria-describedby={`feature-${feature.id}-description`} checked={$featureSwitches[feature.id]} onchange={event => changeFeature(feature.id, event.currentTarget.checked)} />
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{#if error}<p class="error" role="alert">{error}</p>{/if}
|
||||
<p class="saved" role="status">{message}</p>
|
||||
{:else if selected.id === "plugins"}
|
||||
<PluginManager />
|
||||
{:else if selected.id === "browser"}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { t } from "$lib/i18n";
|
||||
import TerminalSlot from "$lib/plugins/TerminalSlot.svelte";
|
||||
import type PluginEditor from "$lib/plugins/PluginEditor.svelte";
|
||||
import { featureOfOwner } from "$lib/features/catalog";
|
||||
import { pluginSplits, pinPluginEditor, pluginTabActions, pluginTabState, restorePluginTab, pluginTabDragData, dropPluginTab, waitForPluginStartup, pluginTools, installedPlugins, runPluginCommand } from "$lib/plugins/external";
|
||||
import { containsPane, paneBounds } from "$lib/workspace/splitLayout";
|
||||
import { pluginSidebar, closePluginSidebar, pluginNavigation, openPluginView, pluginView, pluginEditors, pluginEditorActive, selectPluginEditor, closePluginEditor, openPluginDocument, renamePluginDocuments, removePluginDocuments, notifyPluginWorkspace, guardPluginWrites, handlePluginFileOpen, handlePluginDocumentRename, cancelPluginDocumentOpen, type OpenPluginView } from "$lib/plugins/external";
|
||||
@@ -152,14 +153,19 @@
|
||||
const reading = $derived(activeDocumentPane?.reading ?? false);
|
||||
let quickOpen = $state(false);
|
||||
let palette = $state(false);
|
||||
/** The commands of the palette: the app commands that apply here, then the plugin commands. */
|
||||
/** The name of a native feature, or of an installed plugin. */
|
||||
function ownerName(owner: string) {
|
||||
const feature = featureOfOwner(owner);
|
||||
return feature ? $t(feature.name) : $installedPlugins.plugins.find(row => row.manifest.id === owner)?.manifest.name ?? owner;
|
||||
}
|
||||
/** The commands of the palette: the app commands that apply here, then the feature and plugin commands. */
|
||||
function paletteCommands(): PaletteCommand[] {
|
||||
const hidden = new Set<WorkbenchCommand>(["command-palette", ...(terminalEnabled ? [] : ["toggle-terminal" as const]), ...(workspace ? [] : ["quick-open" as const])]);
|
||||
const app = (Object.keys(COMMAND_LABELS) as WorkbenchCommand[]).filter(command => !hidden.has(command)).map(command => ({
|
||||
id: command, label: $t(COMMAND_LABELS[command]), shortcut: commandShortcut(command) || undefined, run: () => { runCommand(command); },
|
||||
}));
|
||||
const plugins = $pluginTools.filter(tool => tool.kind === "command" && tool.surface === "commands").map(tool => ({
|
||||
id: `plugin:${tool.owner}:${tool.id}`, label: tool.title, detail: $installedPlugins.plugins.find(row => row.manifest.id === tool.owner)?.manifest.name ?? tool.owner,
|
||||
id: `plugin:${tool.owner}:${tool.id}`, label: tool.title, detail: ownerName(tool.owner),
|
||||
run: () => { void runPluginCommand(tool.owner, tool.id).catch(reason => error = String(reason)); },
|
||||
}));
|
||||
return [...app, ...plugins];
|
||||
|
||||
Reference in New Issue
Block a user