From 40aab1f45fe70a14a6d038155243a174cd171378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Geis?= Date: Mon, 1 Sep 2025 18:01:06 +0900 Subject: [PATCH] wip: split Dance into Core & Kakoune --- assets/dance.svg | 39 ----------- extensions/kakoune/LICENSE | 5 ++ extensions/kakoune/README.md | 3 + .../kakoune/assets}/dance.png | Bin extensions/kakoune/package.build.ts | 0 src/state/extension.ts | 4 ++ src/utils/keymaps.ts | 64 ++++++++++++++++++ 7 files changed, 76 insertions(+), 39 deletions(-) delete mode 100644 assets/dance.svg create mode 100644 extensions/kakoune/LICENSE create mode 100644 extensions/kakoune/README.md rename {assets => extensions/kakoune/assets}/dance.png (100%) create mode 100644 extensions/kakoune/package.build.ts create mode 100644 src/utils/keymaps.ts diff --git a/assets/dance.svg b/assets/dance.svg deleted file mode 100644 index 7319efa0..00000000 --- a/assets/dance.svg +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/extensions/kakoune/LICENSE b/extensions/kakoune/LICENSE new file mode 100644 index 00000000..827ae984 --- /dev/null +++ b/extensions/kakoune/LICENSE @@ -0,0 +1,5 @@ +Copyright 2020-2025 Grégoire Geis + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/extensions/kakoune/README.md b/extensions/kakoune/README.md new file mode 100644 index 00000000..0bb95d62 --- /dev/null +++ b/extensions/kakoune/README.md @@ -0,0 +1,3 @@ +# Dance - Kakoune keybindings + +Kakoune keybindings for VS Code based on [Dance](https://github.com/71/dance). diff --git a/assets/dance.png b/extensions/kakoune/assets/dance.png similarity index 100% rename from assets/dance.png rename to extensions/kakoune/assets/dance.png diff --git a/extensions/kakoune/package.build.ts b/extensions/kakoune/package.build.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/state/extension.ts b/src/state/extension.ts index 6085d262..00606289 100644 --- a/src/state/extension.ts +++ b/src/state/extension.ts @@ -11,6 +11,7 @@ import type { Commands } from "../commands"; import { extensionName } from "../utils/constants"; import { AutoDisposable } from "../utils/disposables"; import { assert, CancellationError } from "../utils/errors"; +import { watchKeymaps } from "../utils/keymaps"; import { SettingsValidator } from "../utils/settings-validator"; import { onDidLoadTreeSitter, type TreeSitter } from "../utils/tree-sitter"; @@ -189,6 +190,9 @@ export class Extension implements vscode.Disposable { // Tree Sitter support. this._subscriptions.push(onDidLoadTreeSitter((treeSitter) => this._treeSitter = treeSitter)); + + // Sanity checks + this._subscriptions.push(watchKeymaps()); } /** diff --git a/src/utils/keymaps.ts b/src/utils/keymaps.ts new file mode 100644 index 00000000..9f61cb80 --- /dev/null +++ b/src/utils/keymaps.ts @@ -0,0 +1,64 @@ +import * as vscode from "vscode"; + +/** + * Watches extensions, displaying warnings if potential conflicts are detected. + */ +export function watchKeymaps(): vscode.Disposable { + return vscode.extensions.onDidChange(checkKeymaps); +} + +function checkKeymaps(): void { + /** Map from mode name to contributing extensions. */ + const contributedModes = new Map(); + let hasConflict = false; + + // Find extensions that contribute Dance modes. + for (const extension of vscode.extensions.all) { + const packageJSON = extension.packageJSON; + const modes = packageJSON?.contributes?.configurationDefaults + ?.["dance.modes"]; + + if (typeof modes !== "object") { + continue; + } + + const extensionName = extension.packageJSON?.displayName ?? + extension.packageJSON?.name; + const extensionDisplayName = extensionName === undefined + ? extension.id + : `${extensionName} (${extension.id})`; + + for (const mode in modes) { + const existing = contributedModes.get(mode); + + if (existing === undefined) { + contributedModes.set(mode, [extensionDisplayName]); + } else { + existing.push(extensionDisplayName); + hasConflict = true; + } + } + } + + if (!hasConflict) { + return; + } + + // Aggregate conflicting extensions. + const conflictingExtensions = new Set(); + + for (const extensionNames of contributedModes.values()) { + if (extensionNames.length > 1) { + for (const extensionName of extensionNames) { + conflictingExtensions.add(extensionName); + } + } + } + + // Display error message. + vscode.window.showWarningMessage( + `Multiple extensions contribute conflicting Dance modes: ${ + Array.from(conflictingExtensions).sort().join(", ") + }`, + ); +}