diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ce2f44fa..d989c3993 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ Changes to Calva. ## [Unreleased] +## [2.0.477] - 2024-09-29 + +- Fix: [Global custom repl command keys override workspace dittos, should be the other way around](https://github.com/BetterThanTomorrow/calva/issues/2640) + ## [2.0.476] - 2024-09-28 - Fix: [Formatting and some pretty printing croaks on new Clojure 1.12.0 syntax](https://github.com/BetterThanTomorrow/calva/issues/2637) diff --git a/docs/site/custom-commands.md b/docs/site/custom-commands.md index 3406d110b..9692ef238 100644 --- a/docs/site/custom-commands.md +++ b/docs/site/custom-commands.md @@ -44,7 +44,7 @@ There are also substitutions available, which will take elements from the curren ## User and Workspace Settings -Settings from your User (global) level and the workspace are merged. +Settings from your User (global) level and the workspace are concatenated. Except for the `key` field, are merged. With these **User** settings: @@ -89,9 +89,7 @@ And these **Workspace** settings: ``` -Issuing **Run Custom REPL Command** will then render this VS Code menu: - -![](images/custom-command-menu.png) +Issuing **Run Custom REPL Command** will then render a VS Code menu with all the commands, where the Workspace configured commands will be listed first. The default keyboard shortcut for the command is `ctrl+alt+space space`. (Beware: on MacOS it may conflict with the default shortuct for Input Sources - Select next source in Input menu.) @@ -103,7 +101,7 @@ There are four ways to bind shortcuts to custom commands: * The digits `0` through `9` * The English letters `a` through `z` * Arrow keys `right`, `left`, `up`, or `down` - * One of `tab`, `backspace`, `,`, `.`, or `-` + * One of `tab`, `backspace`, `,`, `.`, or `-` 2. Bind `calva.runCustomREPLCommand` to a shortcut with whatever code you want to evaluate in the `args` slot. You have access to the substitution variables here as well. 3. Bind `calva.runCustomREPLCommand` to a keyboard shortcut referencing the `key` of one of your `calva.customREPLCommandSnippets`. (If not using any of the `key`s mentioned in **1.**) 4. Bind `calva.runCustomREPLCommand` to a shortcut with a `customREPLCommandSnippets` in the `args` slot. You have access to the substitution variables here as well. diff --git a/package-lock.json b/package-lock.json index d8a821fda..a2893fa24 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "calva", - "version": "2.0.476", + "version": "2.0.477", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "calva", - "version": "2.0.476", + "version": "2.0.477", "license": "MIT", "dependencies": { "@vscode/debugadapter": "^1.64.0", diff --git a/package.json b/package.json index 722f3d70c..8879fd397 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Calva: Clojure & ClojureScript Interactive Programming", "description": "Integrated REPL, formatter, Paredit, and more. Powered by cider-nrepl and clojure-lsp.", "icon": "assets/calva.png", - "version": "2.0.476", + "version": "2.0.477", "publisher": "betterthantomorrow", "author": { "name": "Better Than Tomorrow", diff --git a/src/custom-snippets.ts b/src/custom-snippets.ts index 130764eaf..e7b6308bf 100644 --- a/src/custom-snippets.ts +++ b/src/custom-snippets.ts @@ -87,16 +87,15 @@ async function getSnippetDefinition(codeOrKey: string, editorNS: string, editorR const workspaceSnippets = getConfig().customREPLCommandSnippetsWorkspace; const workspaceFolderSnippets = getConfig().customREPLCommandSnippetsWorkspaceFolder; let snippets = [ - ...(globalSnippets ? globalSnippets : []), - ...(workspaceSnippets ? workspaceSnippets : []), ...(workspaceFolderSnippets ? workspaceFolderSnippets : []), + ...(workspaceSnippets ? workspaceSnippets : []), + ...(globalSnippets ? globalSnippets : []), ]; if (snippets.length < 1) { snippets = getConfig().customREPLCommandSnippets; } const snippetsDict = {}; - const snippetsKeyDict = {}; - const snippetsMenuItems: string[] = []; + const snippetsMenuItems: vscode.QuickPickItem[] = []; snippets.forEach((c: CustomREPLCommandSnippet) => { const undefs = ['name', 'snippet'].filter((k) => { return !c[k]; @@ -107,11 +106,16 @@ async function getSnippetDefinition(codeOrKey: string, editorNS: string, editorR const entry = { ...c }; entry.ns = entry.ns ? entry.ns : editorNS; entry.repl = entry.repl ? entry.repl : editorRepl; - const prefix = entry.key !== undefined ? `${entry.key}: ` : ''; - const item = `${prefix}${entry.name} (${entry.repl})`; + const item = { + label: `${entry.key ? entry.key + ': ' : ''}${entry.name}`, + detail: `${entry.snippet}`, + description: `${entry.repl}`, + snippet: entry.snippet, + }; snippetsMenuItems.push(item); - snippetsDict[item] = entry; - snippetsKeyDict[entry.key] = item; + if (!snippetsDict[entry.key]) { + snippetsDict[entry.key] = entry; + } }); if (configErrors.length > 0) { @@ -123,20 +127,20 @@ async function getSnippetDefinition(codeOrKey: string, editorNS: string, editorR return; } - let pick: string; + let pick: any; if (codeOrKey === undefined) { // Called without args, show snippets menu if (snippetsMenuItems.length > 0) { try { const pickResult = await util.quickPickSingle({ - values: snippetsMenuItems.map((a) => ({ label: a })), + values: snippetsMenuItems, placeHolder: 'Choose a command to run at the REPL', saveAs: 'runCustomREPLCommand', }); if (pickResult === undefined || pickResult.label.length < 1) { return; } - pick = pickResult.label; // Assign the label property to pick + pick = pickResult; } catch (e) { console.error(e); } @@ -151,10 +155,10 @@ async function getSnippetDefinition(codeOrKey: string, editorNS: string, editorR if (pick === undefined) { // still no pick, but codeOrKey might be one - pick = snippetsKeyDict[codeOrKey]; + pick = snippetsDict[codeOrKey]; } - return pick !== undefined ? snippetsDict[pick] : { snippet: codeOrKey }; + return pick ?? { snippet: codeOrKey }; } export function makeContext(editor: vscode.TextEditor, ns: string, editorNS: string, repl: string) {